Java Code Examples for org.wso2.carbon.user.core.UserRealm

The following examples show how to use org.wso2.carbon.user.core.UserRealm. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: carbon-identity   Source File: UserProfileAdmin.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isAddProfileEnabledForDomain(String domain) throws UserProfileException {

        org.wso2.carbon.user.core.UserStoreManager userStoreManager = null;
        org.wso2.carbon.user.core.UserRealm realm = getUserRealm();
        boolean isAddProfileEnabled = false;

        try {
            if (StringUtils.isBlank(domain) || StringUtils.equals(domain, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
                userStoreManager = realm.getUserStoreManager();
            } else {
                userStoreManager = realm.getUserStoreManager().getSecondaryUserStoreManager(domain);
            }

        } catch (UserStoreException e) {
            String errorMessage = "Error in obtaining SecondaryUserStoreManager.";
            log.error(errorMessage, e);
            throw new UserProfileException(errorMessage, e);
        }

        if (userStoreManager != null) {
            isAddProfileEnabled = userStoreManager.isMultipleProfilesAllowed();
        }

        return isAddProfileEnabled;
    }
 
Example 2
Source Project: carbon-identity   Source File: UserProfileAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return
 * @throws UserStoreException
 */
private Claim[] getAllSupportedClaims(UserRealm realm, String dialectUri)
        throws org.wso2.carbon.user.api.UserStoreException {
    ClaimMapping[] claims = null;
    List<Claim> reqClaims = null;

    claims = realm.getClaimManager().getAllSupportClaimMappingsByDefault();
    reqClaims = new ArrayList<Claim>();
    for (int i = 0; i < claims.length; i++) {
        if (dialectUri.equals(claims[i].getClaim().getDialectURI()) && (claims[i] != null && claims[i].getClaim().getDisplayTag() != null
                && !claims[i].getClaim().getClaimUri().equals(IdentityConstants.CLAIM_PPID))) {

            reqClaims.add((Claim) claims[i].getClaim());
        }
    }

    return reqClaims.toArray(new Claim[reqClaims.size()]);
}
 
Example 3
Source Project: carbon-apimgt   Source File: SelfSignUpUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check whether user can signup to the tenant domain
 * 
 * @param userName - The user name
 * @param realm - The realm
 * @return - A boolean value
 * @throws APIManagementException
 */
public static boolean isUserNameWithAllowedDomainName(String userName, UserRealm realm)
		throws APIManagementException {
	int index;
	index = userName.indexOf('/');

	// Check whether we have a secondary UserStoreManager setup.
	if (index > 0) {
		// Using the short-circuit. User name comes with the domain name.
		try {
			return !realm.getRealmConfiguration()
					.isRestrictedDomainForSlefSignUp(userName.substring(0, index));
		} catch (UserStoreException e) {
			throw new APIManagementException(e.getMessage(), e);				
		}
	}

	return true;
}
 
Example 4
public void addUser(UserDTO user) throws Exception {
    UserFieldDTO[] userFieldDTOs = null;
    Map<String, String> userClaims = null;

    userFieldDTOs = user.getUserFields();
    userClaims = new HashMap<String, String>();

    if (userFieldDTOs != null) {
        for (UserFieldDTO userFieldDTO : userFieldDTOs) {
            userClaims.put(userFieldDTO.getClaimUri(), userFieldDTO.getFieldValue());
        }
    }

    UserRealm realm = null;
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user.getUserName());
    String tenantName = MultitenantUtils.getTenantDomain(user.getUserName());
    realm = IdentityTenantUtil.getRealm(tenantName, null);
    addUser(tenantAwareUserName, user.getPassword(), userClaims, null, realm);
}
 
Example 5
@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    userAdminStub = Mockito.mock(UserAdminStub.class);
    userRegistrationAdminServiceStub = Mockito.mock(UserRegistrationAdminServiceStub.class);
    serviceClient =  Mockito.mock(ServiceClient.class);;
    PowerMockito.whenNew(UserAdminStub.class).withAnyArguments().thenReturn(userAdminStub);
    PowerMockito.whenNew(UserRegistrationAdminServiceStub.class).withAnyArguments().thenReturn
            (userRegistrationAdminServiceStub);
    PowerMockito.when(userRegistrationAdminServiceStub._getServiceClient()).thenReturn(serviceClient);
    Mockito.when(serviceClient.getOptions()).thenReturn(new Options());
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getBootstrapRealm()).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(),
            Mockito.anyString(), Mockito.anyBoolean(), (ServiceClient) Mockito.anyObject());
    FlaggedName flaggedName = new FlaggedName();
    flaggedName.setSelected(true);
    flaggedName.setItemName(role);
    flaggedNames = new FlaggedName[]{flaggedName};
}
 
Example 6
Source Project: carbon-identity   Source File: UserAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param roleName
 * @param realm
 * @return
 * @throws UserAdminException
 */
private boolean isAllowedRoleName(String roleName, UserRealm realm) throws UserAdminException {

    int index;
    index = roleName.indexOf("/");

    if (index > 0) {
        roleName = roleName.substring(index + 1);
    }

    try {
        return !realm.getRealmConfiguration().isReservedRoleName(roleName);
    } catch (UserStoreException e) {
        throw new UserAdminException(e.getMessage(), e);
    }
}
 
Example 7
Source Project: attic-stratos   Source File: CommonUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void setAnonAuthorization(String path, UserRealm userRealm)
        throws RegistryException {

    if (userRealm == null) {
        return;
    }

    try {
        AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
        String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

        accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
        accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

    } catch (UserStoreException e) {
        String msg = "Could not set authorizations for the " + path + ".";
        log.error(msg, e);
        throw new RegistryException(msg);
    }
}
 
Example 8
Source Project: carbon-identity   Source File: DefaultClaimHandler.java    License: Apache License 2.0 6 votes vote down vote up
private UserStoreManager getUserStoreManager(String tenantDomain, UserRealm realm, String userDomain) throws
        FrameworkException {
    UserStoreManager userStore = null;
    try {
        userStore = realm.getUserStoreManager();
        if (StringUtils.isNotBlank(userDomain)) {
            userStore = realm.getUserStoreManager().getSecondaryUserStoreManager(userDomain);
        }

        if (userStore == null) {
            // To avoid NPEs
            throw new FrameworkException("Invalid user store domain name : " + userDomain + " in tenant : "
                    + tenantDomain);
        }
    } catch (UserStoreException e) {
        throw new FrameworkException("Error occurred while retrieving the UserStoreManager " +
                                     "from Realm for " + tenantDomain + " to handle local claims", e);
    }
    return userStore;
}
 
Example 9
Source Project: carbon-identity   Source File: UserAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get list of roles which have given permission
 *
 * @param filter     filter to check
 * @param permission permission to check
 * @param limit
 * @return
 * @throws UserAdminException
 */
public FlaggedName[] getAllPermittedRoleNames(String filter, String permission, int limit) throws
        UserAdminException {

    FlaggedName[] roles = getUserAdminProxy().getAllRolesNames(filter, limit);
    List<FlaggedName> permittedRoles = new ArrayList<>();
    try {
        org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm
                (PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
        AuthorizationManager authorizationManager = realm.getAuthorizationManager();
        for (int i = 0; i < roles.length - 1; i++) {
            if (authorizationManager.isRoleAuthorized(roles[i].getItemName(), permission, UserMgtConstants
                    .EXECUTE_ACTION)) {
                permittedRoles.add(roles[i]);
            }
        }
        permittedRoles.add(roles[roles.length - 1]);
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        throw new UserAdminException("Error while filtering authorized roles.", e);
    }
    FlaggedName[] permittedRolesArray = new FlaggedName[permittedRoles.size()];
    return permittedRoles.toArray(permittedRolesArray);
}
 
Example 10
Source Project: carbon-identity   Source File: UserRegistrationService.java    License: Apache License 2.0 5 votes vote down vote up
public UserFieldDTO[] readUserFieldsForUserRegistration(String dialect)
        throws IdentityException {

    IdentityClaimManager claimManager = null;
    Claim[] claims = null;
    List<UserFieldDTO> claimList = null;
    UserRealm realm = null;

    claimManager = IdentityClaimManager.getInstance();
    realm = IdentityTenantUtil.getRealm(null, null);
    claims = claimManager.getAllSupportedClaims(dialect, realm);

    if (claims == null || claims.length == 0) {
        return new UserFieldDTO[0];
    }

    claimList = new ArrayList<UserFieldDTO>();

    for (Claim claim : claims) {
        if (claim.getDisplayTag() != null
                && !IdentityConstants.PPID_DISPLAY_VALUE.equals(claim.getDisplayTag())) {
            if (UserCoreConstants.ClaimTypeURIs.ACCOUNT_STATUS.equals(claim.getClaimUri())) {
                continue;
            }
            if (!claim.isReadOnly()) {
                claimList.add(getUserFieldDTO(claim.getClaimUri(), claim.getDisplayTag(), claim.isRequired(),
                        claim.getDisplayOrder(), claim.getRegEx(), claim.isSupportedByDefault()));
            }
        }
    }
    return claimList.toArray(new UserFieldDTO[claimList.size()]);
}
 
Example 11
private LDAPServerStoreManager getServerStoreManager() throws DirectoryServerManagerException {
    UserRealm realm = this.getUserRealm();
    RealmConfiguration configuration;
    try {
        configuration = realm.getRealmConfiguration();
    } catch (UserStoreException e) {
        throw new DirectoryServerManagerException("Unable to retrieve realm configuration.", e);
    }

    return new LDAPServerStoreManager(configuration);
}
 
Example 12
private UserRealm getUserRealm(String tenantDomain) throws PostAuthenticationFailedException {

        UserRealm realm;
        try {
            realm = AnonymousSessionUtil.getRealmByTenantDomain(
                    FrameworkServiceComponent.getRegistryService(),
                    FrameworkServiceComponent.getRealmService(), tenantDomain);
        } catch (CarbonException e) {
            throw new PostAuthenticationFailedException("Error while handling missing mandatory claims",
                    "Error occurred while retrieving the Realm for " + tenantDomain + " to handle local claims", e);
        }
        return realm;
    }
 
Example 13
@Override
protected List<String> retrieveRolesToBeDeleted(UserRealm realm, List<String> currentRolesList,
                                                List<String> rolesToAdd) throws UserStoreException {

    List<String> deletingRoles = super.retrieveRolesToBeDeleted(realm, currentRolesList, rolesToAdd);

    // Remove all internal roles from deleting list
    deletingRoles.removeAll(extractInternalRoles(currentRolesList));

    return deletingRoles;
}
 
Example 14
Source Project: carbon-identity   Source File: UserRegistrationService.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isAddUserEnabled() throws Exception {

        UserRealm userRealm = IdentityTenantUtil.getRealm(null, null);
        if (userRealm != null) {
            UserStoreManager userStoreManager = userRealm.getUserStoreManager();
            if (userStoreManager != null) {
                return !userStoreManager.isReadOnly();
            }
        }
        return false;
    }
 
Example 15
/**
 * Retrieve the list of roles to be deleted.
 *
 * @param realm            user realm
 * @param currentRolesList current role list of the user
 * @param rolesToAdd       roles that are about to be added
 * @return roles to be deleted
 * @throws UserStoreException When failed to get realm configuration
 */
protected List<String> retrieveRolesToBeDeleted(UserRealm realm, List<String> currentRolesList,
                                                List<String> rolesToAdd) throws UserStoreException {

    List<String> deletingRoles = new ArrayList<String>();
    deletingRoles.addAll(currentRolesList);

    // deletingRoles = currentRolesList - rolesToAdd
    deletingRoles.removeAll(rolesToAdd);

    // Exclude Internal/everyonerole from deleting role since its cannot be deleted
    deletingRoles.remove(realm.getRealmConfiguration().getEveryOneRoleName());

    return deletingRoles;
}
 
Example 16
Source Project: carbon-identity   Source File: UserAdmin.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get list of users which have given permission
 *
 * @param filter     filter to check
 * @param permission permission to check
 * @param limit
 * @return
 * @throws UserAdminException
 */
public FlaggedName[] listAllUsersWithPermission(String filter, String permission, int limit) throws
        UserAdminException {

    List<FlaggedName> permittedUsers = new ArrayList<>();
    try {
        org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm
                (PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
        AuthorizationManager authorizationManager = realm.getAuthorizationManager();


        FlaggedName[] users = getUserAdminProxy().listAllUsers(filter, limit);

        for (int i = 0; i < users.length - 1; i++) {
            if (authorizationManager.isUserAuthorized(users[i].getItemName(),
                    permission, UserMgtConstants.EXECUTE_ACTION)) {
                permittedUsers.add(users[i]);
            }
        }
        permittedUsers.add(users[users.length - 1]);
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        throw new UserAdminException("Error while filtering authorized users.", e);
    }
    FlaggedName[] permittedUsersArray = new FlaggedName[permittedUsers.size()];
    return permittedUsers.toArray(permittedUsersArray);

}
 
Example 17
private ClaimManager getClaimManager(String tenantDomain, UserRealm realm) throws FrameworkException {
    ClaimManager claimManager = null;
    try {
        claimManager = realm.getClaimManager();
    } catch (UserStoreException e) {
        throw new FrameworkException("Error occurred while retrieving the ClaimManager " +
                                     "from Realm for " + tenantDomain + " to handle local claims", e);
    }
    return claimManager;
}
 
Example 18
private UserRealm getUserRealm(String tenantDomain) throws FrameworkException {
    UserRealm realm;
    try {
        realm = AnonymousSessionUtil.getRealmByTenantDomain(
                FrameworkServiceComponent.getRegistryService(),
                FrameworkServiceComponent.getRealmService(), tenantDomain);
    } catch (CarbonException e) {
        throw new FrameworkException("Error occurred while retrieving the Realm for " +
                                     tenantDomain + " to handle local claims", e);
    }
    return realm;
}
 
Example 19
Source Project: carbon-apimgt   Source File: SelfSignupUtilTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIsUserNameWithAllowedDomainNameWhenDomainNotGiven() throws Exception {
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    RealmConfiguration realmConfiguration = new RealmConfiguration();
    realmConfiguration.addRestrictedDomainForSelfSignUp("foo.com");
    Mockito.when(userRealm.getRealmConfiguration()).thenReturn(realmConfiguration);
    boolean result = SelfSignUpUtil.isUserNameWithAllowedDomainName("john", userRealm);
    Assert.assertTrue(result);
}
 
Example 20
/**
 * @param userName
 * @param tenantDomain
 * @return
 * @throws CarbonException
 * @throws UserStoreException
 */
private Map<String, String> getUserClaims(String userName, String tenantDomain) throws CarbonException,
                                                                                       UserStoreException {

    Map<String, String> inboundAttributes = new HashMap<>();

    RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService();
    RealmService realmService = IdentityProvisionServiceComponent.getRealmService();

    UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService,
                                                                  realmService, tenantDomain);

    UserStoreManager userstore = null;
    userstore = realm.getUserStoreManager();
    Claim[] claimArray = null;
    try {
        claimArray = userstore.getUserClaimValues(userName, null);
    } catch (UserStoreException e) {
        if (e.getMessage().contains("UserNotFound")) {
            if (log.isDebugEnabled()) {
                log.debug("User " + userName + " not found in user store");
            }
        } else {
            throw e;
        }
    }
    if (claimArray != null) {
        for (Claim claim : claimArray) {
            inboundAttributes.put(claim.getClaimUri(), claim.getValue());
        }
    }

    return inboundAttributes;
}
 
Example 21
/**
 * To check whether the application owner is valid by validating user existence and permissions.
 *
 * @param serviceProvider service provider
 * @return true if the application owner is valid.
 * @throws IdentityApplicationManagementException when an error occurs while validating the user.
 */
public static boolean isValidApplicationOwner(ServiceProvider serviceProvider)
        throws IdentityApplicationManagementException {

    try {
        String userName;
        String userNameWithDomain;
        if (serviceProvider.getOwner() != null) {
            userName = serviceProvider.getOwner().getUserName();
            if (StringUtils.isEmpty(userName) || CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(userName)) {
                return false;
            }
            String userStoreDomain = serviceProvider.getOwner().getUserStoreDomain();
            userNameWithDomain = IdentityUtil.addDomainToName(userName, userStoreDomain);

            org.wso2.carbon.user.api.UserRealm realm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
            if (realm == null || StringUtils.isEmpty(userNameWithDomain)) {
                return false;
            }
            boolean isUserExist = realm.getUserStoreManager().isExistingUser(userNameWithDomain);
            if (!isUserExist) {
                throw new IdentityApplicationManagementException("User validation failed for owner update in the " +
                        "application: " +
                        serviceProvider.getApplicationName() + " as user is not existing.");
            }
        } else {
            return false;
        }
    } catch (UserStoreException | IdentityApplicationManagementException e) {
        throw new IdentityApplicationManagementException("User validation failed for owner update in the " +
                "application: " +
                serviceProvider.getApplicationName(), e);
    }
    return true;
}
 
Example 22
private void removeAuthorization (UserRealm userRealm, String serviceGroupId,
                                  String serviceName) throws UserStoreException {

    AuthorizationManager manager = userRealm.getAuthorizationManager();
    String resourceName = serviceGroupId + "/" + serviceName;
    String[] roles = manager.
            getAllowedRolesForResource(resourceName,
                    UserCoreConstants.INVOKE_SERVICE_PERMISSION);
    if (roles != null) {
        for (String role : roles) {
            manager.clearRoleAuthorization(role, resourceName,
                    UserCoreConstants.INVOKE_SERVICE_PERMISSION);
        }
    }
}
 
Example 23
Source Project: carbon-apimgt   Source File: UserSignUpWorkflowExecutor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Method updates Roles users with subscriber role
 * @param serverURL
 * @param adminUsername
 * @param adminPassword
 * @param userName
 * @param role
 * @throws Exception
 */
protected static void updateRolesOfUser(String serverURL, String adminUsername,
                                        String adminPassword, String userName, String role)
                                                                                           throws Exception {
	if (log.isDebugEnabled()) {
		log.debug("Adding Subscriber role to " + userName);
	}

	String url = serverURL + "UserAdmin";
	RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
	UserRealm realm = realmService.getBootstrapRealm();
	UserStoreManager manager = realm.getUserStoreManager();
	if (!manager.isExistingRole(role)){
		log.error("Could not find role " + role + " in the user store");
		throw new Exception("Could not find role " + role + " in the user store");
	}

	UserAdminStub userAdminStub = new UserAdminStub(url);
	CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient());
	FlaggedName[] flaggedNames = userAdminStub.getRolesOfUser(userName, "*", -1);
	List<String> roles = new ArrayList<String>();
	if (flaggedNames != null) {
		for (FlaggedName flaggedName : flaggedNames) {
			if (flaggedName.getSelected()) {
				roles.add(flaggedName.getItemName());
			}
		}
	}
	roles.add(role);
	userAdminStub.updateRolesOfUser(userName, roles.toArray(new String[roles.size()]));
}
 
Example 24
/**
 * Set user realm for IdentityProfileManager.
 *
 * @param realm user realm to be set
 */
public void setRealm(UserRealm realm) {
    this.realm = realm;
    if (log.isDebugEnabled()) {
        if (realm != null) {
            log.debug("IdentityProfileManager UserRealm set successfully: "
                    + realm.getClass().getName());
        }
    }
}
 
Example 25
Source Project: carbon-identity   Source File: UserRegistrationService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This service method will return back all available password validation regular expressions
 * against the corresponding domain names.
 *
 * @return
 * @throws IdentityException
 */
public PasswordRegExDTO[] getPasswordRegularExpressions() throws IdentityException {
    UserRealm realm = null;
    realm = IdentityTenantUtil.getRealm(null, null);
    List<PasswordRegExDTO> passwordRegExList = new ArrayList<PasswordRegExDTO>();
    PasswordRegExDTO passwordRegEx;

    try {
        UserStoreManager manager = realm.getUserStoreManager();
        String domainName;
        String regEx;

        while (manager != null) {
            domainName = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
            regEx = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_JS_REG_EX);
            if (regEx != null && regEx.length() > 0) {
                passwordRegEx = new PasswordRegExDTO();
                passwordRegEx.setDomainName(domainName);
                passwordRegEx.setRegEx(regEx);
                passwordRegExList.add(passwordRegEx);
            }
            manager = manager.getSecondaryUserStoreManager();
        }
    } catch (UserStoreException e) {
        log.error(e);
        throw IdentityException.error(
                "Error occured while loading password validation regular expressions.");
    }
    return passwordRegExList.toArray(new PasswordRegExDTO[passwordRegExList.size()]);
}
 
Example 26
private void addRealmToSecondaryUserStoreManager(UserStorePersistanceDTO userStorePersistanceDTO) throws
        UserStoreException, XMLStreamException {

    UserRealm userRealm = (UserRealm) CarbonContext.getThreadLocalCarbonContext().getUserRealm();
    AbstractUserStoreManager primaryUSM = (AbstractUserStoreManager) userRealm.getUserStoreManager();
    InputStream targetStream = new ByteArrayInputStream(userStorePersistanceDTO.getUserStoreProperties()
                                                                               .getBytes());
    RealmConfiguration realmConfiguration = getRealmConfiguration(userStorePersistanceDTO.getUserStoreDTO().
            getDomainId(), targetStream);
    primaryUSM.addSecondaryUserStoreManager(realmConfiguration, userRealm);
}
 
Example 27
public UserFieldDTO[] readUserFieldsForUserRegistration(String dialect)
        throws IdentityException {

    IdentityClaimManager claimManager = null;
    Claim[] claims = null;
    List<UserFieldDTO> claimList = null;
    UserRealm realm = null;

    claimManager = IdentityClaimManager.getInstance();
    realm = IdentityTenantUtil.getRealm(null, null);
    claims = claimManager.getAllSupportedClaims(dialect, realm);

    if (claims == null || claims.length == 0) {
        return new UserFieldDTO[0];
    }

    claimList = new ArrayList<UserFieldDTO>();

    for (Claim claim : claims) {
        if (claim.getDisplayTag() != null
                && !IdentityConstants.PPID_DISPLAY_VALUE.equals(claim.getDisplayTag())) {
            if (UserCoreConstants.ClaimTypeURIs.ACCOUNT_STATUS.equals(claim.getClaimUri())) {
                continue;
            }
            if (!claim.isReadOnly()) {
                claimList.add(getUserFieldDTO(claim.getClaimUri(), claim.getDisplayTag(), claim.isRequired(),
                        claim.getDisplayOrder(), claim.getRegEx(), claim.isSupportedByDefault()));
            }
        }
    }
    return claimList.toArray(new UserFieldDTO[claimList.size()]);
}
 
Example 28
private ProfileConfigurationManager getProfileConfigurationManager() throws UserStoreException {
    try {
        UserRealm realm = super.getUserRealm();
        if (realm == null) {
            throw new UserStoreException(NULL_REALM_MESSAGE);
        }
        return realm.getProfileConfigurationManager();
    } catch (Exception e) {
        throw new UserStoreException(e);
    }
}
 
Example 29
Source Project: carbon-identity   Source File: UserProfileAdmin.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isReadOnlyUserStore() throws UserProfileException {
    try {
        UserRealm realm = getUserRealm();
        if ("true".equals(realm.getRealmConfiguration().getUserStoreProperty(
                UserCoreConstants.RealmConfig.PROPERTY_READ_ONLY))) {
            return true;
        }
        return false;
    } catch (UserStoreException e) {
        log.error(e.getMessage(), e);
        throw new UserProfileException(e.getMessage(), e);
    }
}
 
Example 30
Source Project: carbon-apimgt   Source File: SelfSignupUtilTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = APIManagementException.class)
public void testIsUserNameWithAllowedDomainNameException() throws Exception {
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    RealmConfiguration realmConfiguration = new RealmConfiguration();
    realmConfiguration.addRestrictedDomainForSelfSignUp("bar.com");
    Mockito.when(userRealm.getRealmConfiguration()).thenThrow(new UserStoreException());
    SelfSignUpUtil.isUserNameWithAllowedDomainName("bar.com/john", userRealm);
}