Java Code Examples for org.wso2.carbon.user.core.util.UserCoreUtil#removeDomainFromName()

The following examples show how to use org.wso2.carbon.user.core.util.UserCoreUtil#removeDomainFromName() . 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 File: User.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a User object constructed from fully qualified username
 *
 * @param username Fully qualified username
 * @return User object
 * @throws IllegalArgumentException
 */
public static User getUserFromUserName(String username) {

    User user = new User();
    if (StringUtils.isNotBlank(username)) {
        String tenantDomain = MultitenantUtils.getTenantDomain(username);
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        String tenantAwareUsernameWithNoUserDomain = UserCoreUtil.removeDomainFromName(tenantAwareUsername);
        String userStoreDomain = IdentityUtil.extractDomainFromName(username).toUpperCase(Locale.ENGLISH);
        user.setUserName(tenantAwareUsernameWithNoUserDomain);
        if (StringUtils.isNotEmpty(tenantDomain)) {
            user.setTenantDomain(tenantDomain);
        } else {
            user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        }
        if (StringUtils.isNotEmpty(userStoreDomain)) {
            user.setUserStoreDomain(userStoreDomain);
        } else {
            user.setTenantDomain(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
        }
    }
    return user;
}
 
Example 2
Source File: UserIdentityManagementAdminService.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * User change the password of the user.
 *
 * @param newPassword
 * @throws IdentityMgtServiceException
 */
public void changeUserPassword(String newPassword, String oldPassword) throws IdentityMgtServiceException {

    String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();

    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        userName = UserCoreUtil.removeDomainFromName(userName);
        userStoreManager.updateCredential(userName, newPassword, oldPassword);
        log.info("Password changed for: " + userName);
    } catch (UserStoreException e) {
        String message = "Error while resetting the password for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 3
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * User change the password of the user.
 *
 * @param newPassword
 * @throws IdentityMgtServiceException
 */
public void changeUserPassword(String newPassword, String oldPassword) throws IdentityMgtServiceException {

    String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();

    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        userName = UserCoreUtil.removeDomainFromName(userName);
        userStoreManager.updateCredential(userName, newPassword, oldPassword);
        log.info("Password changed for: " + userName);
    } catch (UserStoreException e) {
        String message = "Error while resetting the password for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 4
Source File: OAuth2Util.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static AuthenticatedUser getUserFromUserName(String username) throws IllegalArgumentException {
    if (StringUtils.isNotBlank(username)) {
        String tenantDomain = MultitenantUtils.getTenantDomain(username);
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        String tenantAwareUsernameWithNoUserDomain = UserCoreUtil.removeDomainFromName(tenantAwareUsername);
        String userStoreDomain = IdentityUtil.extractDomainFromName(username).toUpperCase();
        AuthenticatedUser user = new AuthenticatedUser();
        user.setUserName(tenantAwareUsernameWithNoUserDomain);
        user.setTenantDomain(tenantDomain);
        user.setUserStoreDomain(userStoreDomain);

        return user;
    }
    throw new IllegalArgumentException("Cannot create user from empty user name");
}
 
Example 5
Source File: Utils.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * get email address from user store
 *
 * @param userName user name
 * @param tenantId tenant id
 * @return email address
 */
public static String getEmailAddressForUser(String userName, int tenantId) {

    String email = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("Retrieving email address from user profile.");
        }

        Tenant tenant = IdentityMgtServiceComponent.getRealmService().
                getTenantManager().getTenant(tenantId);
        if (tenant != null && tenant.getAdminName().equals(userName)) {
            email = tenant.getEmail();
        }

        if (email == null || email.trim().length() < 1) {
            email = getClaimFromUserStoreManager(userName, tenantId,
                    UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS);
        }

        if ((email == null || email.trim().length() < 1) && MultitenantUtils.isEmailUserName()) {
            email = UserCoreUtil.removeDomainFromName(userName);
        }
    } catch (Exception e) {
        String msg = "Unable to retrieve an email address associated with the given user : " + userName;
        log.warn(msg, e);   // It is common to have users with no email address defined.
    }

    return email;
}
 
Example 6
Source File: UserIdentityManagementAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Admin resets the password of the user.
 *
 * @param userName
 * @param newPassword
 * @throws IdentityMgtServiceException
 */
public void resetUserPassword(String userName, String newPassword)
        throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        userStoreManager.updateCredentialByAdmin(userNameWithoutDomain, newPassword);
        log.info("User password reset for: " + userName);
    } catch (UserStoreException e) {
        String message = "Error occurred while resetting password for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 7
Source File: UserIdentityManagementAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Admin unlocks the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_UNLOCK);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
        }
        log.info("Account unlocked for: " + userName);
    } catch (UserStoreException|IdentityException e) {
        String message = "Error occurred while unlocking account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 8
Source File: UserIdentityManagementAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Admin locks the user account. Only the admin can unlock the account using
 * the {@literal unlockUserAccount} method.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void lockUserAccount(String userName) throws IdentityMgtServiceException {

    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.lockUserAccount(userNameWithoutDomain, userStoreManager);
        log.info("User account locked: " + userName);
    } catch (UserStoreException|IdentityException e) {
        log.error("Error occurred while trying to lock the account " + userName, e);
        throw new IdentityMgtServiceException("Error occurred while trying to lock the account " + userName, e);
    }
}
 
Example 9
Source File: Utils.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * get email address from user store
 *
 * @param userName user name
 * @param tenantId tenant id
 * @return email address
 */
public static String getEmailAddressForUser(String userName, int tenantId) {

    String email = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("Retrieving email address from user profile.");
        }

        Tenant tenant = IdentityMgtServiceComponent.getRealmService().
                getTenantManager().getTenant(tenantId);
        if (tenant != null && tenant.getAdminName().equals(userName)) {
            email = tenant.getEmail();
        }

        if (email == null || email.trim().length() < 1) {
            email = getClaimFromUserStoreManager(userName, tenantId,
                    UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS);
        }

        if ((email == null || email.trim().length() < 1) && MultitenantUtils.isEmailUserName()) {
            email = UserCoreUtil.removeDomainFromName(userName);
        }
    } catch (Exception e) {
        String msg = "Unable to retrieve an email address associated with the given user : " + userName;
        log.warn(msg, e);   // It is common to have users with no email address defined.
    }

    return email;
}
 
Example 10
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin resets the password of the user.
 *
 * @param userName
 * @param newPassword
 * @throws IdentityMgtServiceException
 */
public void resetUserPassword(String userName, String newPassword)
        throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        userStoreManager.updateCredentialByAdmin(userNameWithoutDomain, newPassword);
        log.info("User password reset for: " + userName);
    } catch (UserStoreException e) {
        String message = "Error occurred while resetting password for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 11
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin enables the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void enableUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.enableUserAccount(userNameWithoutDomain, userStoreManager);

        audit.info(String.format(AUDIT_MESSAGE, getUser(), "Enable user account", userName,
                "Notification type :" + notificationType, SUCCESS));

        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isAccountEnableNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_ENABLE);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);

            if(log.isDebugEnabled()){
                log.debug("Account enabled notification is sent in " + notificationType);
            }
        }

    } catch (UserStoreException | IdentityException e) {
        String message = "Error occurred while enabling account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 12
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin disables the user account. Only the admin can enable the account using
 * the {@literal enableUserAccount} method.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void disableUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {

    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.disableUserAccount(userNameWithoutDomain, userStoreManager);

        audit.info(String.format(AUDIT_MESSAGE, getUser(), "Disable user account", userName,
                "Notification type :" + notificationType, SUCCESS));

        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isAccountDisableNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_DISABLE);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);

            if(log.isDebugEnabled()){
                log.debug("Account enabled notification is sent in " + notificationType);
            }
        }
    } catch (UserStoreException | IdentityException e) {
        log.error("Error occurred while trying to disable the account " + userName, e);
        throw new IdentityMgtServiceException("Error occurred while trying to disable the account " + userName, e);
    }
}
 
Example 13
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin unlocks the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_UNLOCK);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
        }
        log.info("Account unlocked for: " + userName);
    } catch (UserStoreException|IdentityException e) {
        String message = "Error occurred while unlocking account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 14
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin locks the user account. Only the admin can unlock the account using
 * the {@literal unlockUserAccount} method.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void lockUserAccount(String userName) throws IdentityMgtServiceException {

    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.lockUserAccount(userNameWithoutDomain, userStoreManager);
        log.info("User account locked: " + userName);
    } catch (UserStoreException|IdentityException e) {
        log.error("Error occurred while trying to lock the account " + userName, e);
        throw new IdentityMgtServiceException("Error occurred while trying to lock the account " + userName, e);
    }
}
 
Example 15
Source File: DefaultProvisioningHandler.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(List<String> roles, String subject, Map<String, String> attributes,
                   String provisioningUserStoreId, String tenantDomain) throws FrameworkException {

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

    try {
        int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
        UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService,
                                                                      realmService, tenantDomain);

        String userStoreDomain = getUserStoreDomain(provisioningUserStoreId, realm);

        String username = MultitenantUtils.getTenantAwareUsername(subject);

        UserStoreManager userStoreManager = getUserStoreManager(realm, userStoreDomain);

        // Remove userStoreManager domain from username if the userStoreDomain is not primary
        if (realm.getUserStoreManager().getRealmConfiguration().isPrimary()) {
            username = UserCoreUtil.removeDomainFromName(username);
        }

        String[] newRoles = new String[]{};

        if (roles != null) {
            roles = removeDomainFromNamesExcludeInternal(roles, userStoreManager.getTenantId());
            newRoles = roles.toArray(new String[roles.size()]);
        }

        if (log.isDebugEnabled()) {
            log.debug("User " + username + " contains roles : " + Arrays.toString(newRoles)
                      + " going to be provisioned");
        }

        // addingRoles = newRoles AND allExistingRoles
        Collection<String> addingRoles = getRolesToAdd(userStoreManager, newRoles);

        Map<String, String> userClaims = prepareClaimMappings(attributes);

        if (userStoreManager.isExistingUser(username)) {

            if (roles != null && !roles.isEmpty()) {
                // Update user
                Collection<String> currentRolesList = Arrays.asList(userStoreManager
                                                                            .getRoleListOfUser(username));
                // addingRoles = (newRoles AND existingRoles) - currentRolesList)
                addingRoles.removeAll(currentRolesList);

                Collection<String> deletingRoles = new ArrayList<String>();
                deletingRoles.addAll(currentRolesList);
                // deletingRoles = currentRolesList - newRoles
                deletingRoles.removeAll(Arrays.asList(newRoles));

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

                // TODO : Does it need to check this?
                // Check for case whether superadmin login
                handleFederatedUserNameEqualsToSuperAdminUserName(realm, username, userStoreManager, deletingRoles);

                updateUserWithNewRoleSet(username, userStoreManager, newRoles, addingRoles, deletingRoles);
            }

            if (!userClaims.isEmpty()) {
                userStoreManager.setUserClaimValues(username, userClaims, null);
            }

        } else {

            userStoreManager.addUser(username, generatePassword(), addingRoles.toArray(
                    new String[addingRoles.size()]), userClaims, null);

            if (log.isDebugEnabled()) {
                log.debug("Federated user: " + username
                          + " is provisioned by authentication framework with roles : "
                          + Arrays.toString(addingRoles.toArray(new String[addingRoles.size()])));
            }
        }

        PermissionUpdateUtil.updatePermissionTree(tenantId);

    } catch (org.wso2.carbon.user.api.UserStoreException | CarbonException e) {
        throw new FrameworkException("Error while provisioning user : " + subject, e);
    }
}
 
Example 16
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Stores basic application information and meta-data such as the application name, creator and
 * tenant.
 *
 * @param serviceProvider
 * @throws IdentityApplicationManagementException
 */
@Override
public int createApplication(ServiceProvider serviceProvider, String tenantDomain)
        throws IdentityApplicationManagementException {

    // get logged-in users tenant identifier.
    int tenantID = MultitenantConstants.INVALID_TENANT_ID;

    if (tenantDomain != null) {
        tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
    }

    String qualifiedUsername = CarbonContext.getThreadLocalCarbonContext().getUsername();
    if (ApplicationConstants.LOCAL_SP.equals(serviceProvider.getApplicationName())) {
        qualifiedUsername = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }
    String username = UserCoreUtil.removeDomainFromName(qualifiedUsername);
    String userStoreDomain = IdentityUtil.extractDomainFromName(qualifiedUsername);
    String applicationName = serviceProvider.getApplicationName();
    String description = serviceProvider.getDescription();

    if (log.isDebugEnabled()) {
        log.debug("Creating Application " + applicationName + " for user " + qualifiedUsername);
    }

    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement storeAppPrepStmt = null;
    ResultSet results = null;

    try {
        String dbProductName = connection.getMetaData().getDatabaseProductName();
        storeAppPrepStmt = connection.prepareStatement(
                ApplicationMgtDBQueries.STORE_BASIC_APPINFO, new String[]{
                        DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "ID")});

        // TENANT_ID, APP_NAME, USER_STORE, USERNAME, DESCRIPTION, AUTH_TYPE
        storeAppPrepStmt.setInt(1, tenantID);
        storeAppPrepStmt.setString(2, applicationName);
        storeAppPrepStmt.setString(3, userStoreDomain);
        storeAppPrepStmt.setString(4, username);
        storeAppPrepStmt.setString(5, description);
        // by default authentication type would be default.
        // default authenticator is defined system-wide - in the configuration file.
        storeAppPrepStmt.setString(6, ApplicationConstants.AUTH_TYPE_DEFAULT);
        storeAppPrepStmt.execute();

        results = storeAppPrepStmt.getGeneratedKeys();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

        int applicationId = 0;
        if (results.next()) {
            applicationId = results.getInt(1);
        }
        // some JDBC Drivers returns this in the result, some don't
        if (applicationId == 0) {
            if (log.isDebugEnabled()) {
                log.debug("JDBC Driver did not return the application id, executing Select operation");
            }
            applicationId = getApplicationIDByName(applicationName, tenantID, connection);
        }

        if (serviceProvider.getSpProperties() != null) {
            addServiceProviderProperties(connection, applicationId,
                    Arrays.asList(serviceProvider.getSpProperties()), tenantID);
        }

        if (log.isDebugEnabled()) {
            log.debug("Application Stored successfully with application id " + applicationId);
        }

        return applicationId;

    } catch (SQLException e) {
        try {
            if (connection != null) {
                connection.rollback();
            }
        } catch (SQLException sql) {
            throw new IdentityApplicationManagementException(
                    "Error while Creating Application", sql);
        }
        throw new IdentityApplicationManagementException("Error while Creating Application", e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(results);
        IdentityApplicationManagementUtil.closeStatement(storeAppPrepStmt);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
}
 
Example 17
Source File: LocalRole.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public LocalRole(String combinedRoleName) {
    this.userStoreId = IdentityUtil.extractDomainFromName(combinedRoleName);
    this.localRoleName = UserCoreUtil.removeDomainFromName(combinedRoleName);
}
 
Example 18
Source File: IdentityUserNameResolverListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private String getUserNameFromUserID(String userID, AbstractUserStoreManager userStoreManager) throws
        UserStoreException {

    return UserCoreUtil.removeDomainFromName(userStoreManager.getUserNameFromUserID(userID));
}
 
Example 19
Source File: UserStoreBasedIdentityDataStore.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * This method stores data in the read write user stores.
 */
@Override
public void store(UserIdentityClaimsDO userIdentityDTO, UserStoreManager userStoreManager) throws IdentityException {

    UserIdentityClaimsDO newIdentityClaimDO = new UserIdentityClaimsDO(userIdentityDTO.getUserName(),
            userIdentityDTO.getUserDataMap());
    super.store(newIdentityClaimDO, userStoreManager);

    if (userIdentityDTO.getUserName() == null) {
        log.error("Error while persisting user data.  Null user name is provided.");
        return;
    }
    String username = UserCoreUtil.removeDomainFromName(userIdentityDTO.getUserName());

        try {
            // Check if the user store is read only. If it is read only and still uses user store based data
            // store then log a warn.
            if(!userStoreManager.isReadOnly()) {
                // Need to clone the map. If not iterative calls will refer the same map
                userStoreManager.setUserClaimValues(username, new HashMap<String,String>
                        (userIdentityDTO.getUserDataMap()), null);
            } else {
                // If the user store is read only and still uses UserStoreBasedIdentityDataStore, then log a warn
                log.warn("User store is read only. Changes to identities are only stored in memory, " +
                        "and not updated in user store.");
                return;
            }
        } catch (UserStoreException e) {
            if(!e.getMessage().startsWith(IdentityCoreConstants.USER_NOT_FOUND)){
                throw IdentityException.error("Error while persisting identity user data in to user store", e);
            } else if (log.isDebugEnabled()){
                String message = null;
                if(userStoreManager instanceof AbstractUserStoreManager){
                    String domain = ((AbstractUserStoreManager)userStoreManager).getRealmConfiguration()
                            .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
                    if(domain != null){
                        message = "User: " + username + " does not exist in " + domain;
                    }
                }
                if(message == null) {
                    message = "User: " + username + " does not exist";
                }
                log.debug(message);
                return;
            }
        }
}
 
Example 20
Source File: LocalRole.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public LocalRole(String combinedRoleName) {

        this.userStoreId = IdentityUtil.extractDomainFromName(combinedRoleName);
        this.localRoleName = UserCoreUtil.removeDomainFromName(combinedRoleName);
    }