Java Code Examples for org.wso2.carbon.user.core.UserStoreManager#getTenantId()

The following examples show how to use org.wso2.carbon.user.core.UserStoreManager#getTenantId() . 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: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Delete federated user account associations a user has upon deleting the local user account.
 *
 * @param userName
 * @param userStoreManager
 * @return
 * @throws UserStoreException
 */
@Override
public boolean doPreDeleteUser(String userName,
        UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        return true;
    }

    String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (StringUtils.isBlank(userStoreDomain)) {
        userStoreDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    int tenantId = userStoreManager.getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("doPreDeleteUser method executed in ProfileMgtEventListener for user:" +
                getFullQualifiedUsername(userName, userStoreDomain, IdentityTenantUtil.getTenantDomain(tenantId)));
    }

    deleteFederatedIdpAccountAssociations(userName, userStoreDomain, tenantId);
    return true;
}
 
Example 2
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims,
                            String profile, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        AddUserWFRequestHandler addUserWFRequestHandler = new AddUserWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);
        return addUserWFRequestHandler.startAddUserFlow(domain, userName, credential, roleList, claims, profile);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 3
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreDeleteUser(String userName, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        DeleteUserWFRequestHandler deleteUserWFRequestHandler = new DeleteUserWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);
        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return deleteUserWFRequestHandler.startDeleteUserFlow(domain, userName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 4
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> claims, String profileName,
                                       UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        SetMultipleClaimsWFRequestHandler setMultipleClaimsWFRequestHandler = new SetMultipleClaimsWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);
        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return setMultipleClaimsWFRequestHandler.startSetMultipleClaimsWorkflow(domain, userName, claims, profileName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 5
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreDeleteUserClaimValues(String userName, String[] claims, String profileName, UserStoreManager
        userStoreManager) throws UserStoreException {

    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        DeleteMultipleClaimsWFRequestHandler deleteMultipleClaimsWFRequestHandler = new DeleteMultipleClaimsWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);
        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return deleteMultipleClaimsWFRequestHandler.startDeleteMultipleClaimsWorkflow(domain, userName, claims,
                profileName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 6
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreAddRole(String roleName, String[] userList, Permission[] permissions, UserStoreManager
        userStoreManager) throws UserStoreException {

    try {
        if (!isEnable() || isCalledViaIdentityMgtListners()) {
            return true;
        }
        AddRoleWFRequestHandler addRoleWFRequestHandler = new AddRoleWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return addRoleWFRequestHandler.startAddRoleFlow(domain, roleName, userList, permissions);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 7
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreDeleteRole(String roleName, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        DeleteRoleWFRequestHandler deleteRoleWFRequestHandler = new DeleteRoleWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return deleteRoleWFRequestHandler.startDeleteRoleFlow(domain, roleName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 8
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreUpdateRoleName(String roleName, String newRoleName, UserStoreManager userStoreManager) throws
        UserStoreException {
    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        UpdateRoleNameWFRequestHandler updateRoleNameWFRequestHandler = new UpdateRoleNameWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return updateRoleNameWFRequestHandler.startUpdateRoleNameFlow(domain, roleName, newRoleName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 9
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreUpdateUserListOfRole(String roleName, String[] deletedUsers, String[] newUsers, UserStoreManager
        userStoreManager) throws UserStoreException {
    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        UpdateRoleUsersWFRequestHandler updateRoleUsersWFRequestHandler = new UpdateRoleUsersWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return updateRoleUsersWFRequestHandler.startUpdateRoleUsersFlow(domain, roleName, deletedUsers, newUsers);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 10
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreUpdateRoleListOfUser(String userName, String[] deletedRoles, String[] newRoles, UserStoreManager
        userStoreManager) throws UserStoreException {
    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }
    try {
        UpdateUserRolesWFRequestHandler updateUserRolesWFRequestHandler = new UpdateUserRolesWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return updateUserRolesWFRequestHandler.startUpdateUserRolesFlow(domain, userName, deletedRoles, newRoles);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 11
Source File: UserDeletionEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public boolean doPostDeleteUser(String userName, UserStoreManager userStoreManager) throws UserStoreException {

    // Check whether the listener is enabled.
    if (!isEnable()) {
        return true;
    }

    IdentityConfigParser identityConfigParser = IdentityConfigParser.getInstance();
    Map<UserDeletionEventRecorder, Map<String, String>> userDeleteEventRecorders =
            readDeletionEventRecorders(identityConfigParser);

    try {
        String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
        int tenantId = userStoreManager.getTenantId();
        String tenantDomain = UserMgtDSComponent.getRealmService().getTenantManager()
                .getDomain(userStoreManager.getTenantId());

        // We are calling all the event recorders with the values we have. (Including properties we read.)
        for (Map.Entry<UserDeletionEventRecorder, Map<String, String>> entry : userDeleteEventRecorders.entrySet
                ()) {
            UserDeletionEventRecorder userDeletionEventRecorder = entry.getKey();
            Map<String, String> stringMap = entry.getValue();

            userDeletionEventRecorder.recordUserDeleteEvent(userName, userStoreDomain, tenantDomain, tenantId,
                    new Date(System.currentTimeMillis()), stringMap);
            if (log.isDebugEnabled()) {
                log.debug("Event recorder with name: " + userDeletionEventRecorder.getClass().getName() +
                        " invoked with values. " + userName + ", " + userStoreDomain + ", " + tenantId);
            }
        }
    } catch (RecorderException | org.wso2.carbon.user.api.UserStoreException e) {
        throw new UserStoreException(e);
    }

    return true;
}
 
Example 12
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public boolean doPreSetUserClaimValue(String userName, String claimURI, String claimValue, String profileName,
                                      UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }

    Map<String, String> claims = new HashMap<>();
    claims.put(claimURI, claimValue);

    try {
        SetMultipleClaimsWFRequestHandler setMultipleClaimsWFRequestHandler = new SetMultipleClaimsWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return setMultipleClaimsWFRequestHandler.startSetMultipleClaimsWorkflow(domain, userName, claims,
                                                                                profileName);

    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 13
Source File: UserStoreActionListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public boolean doPreDeleteUserClaimValue(String userName, String claimURI, String profileName,
                                         UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable() || isCalledViaIdentityMgtListners()) {
        return true;
    }

    String[] claims = new String[1];
    claims[0] = claimURI;

    try {
        DeleteMultipleClaimsWFRequestHandler deleteMultipleClaimsWFRequestHandler = new DeleteMultipleClaimsWFRequestHandler();
        String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                                                                                              .PROPERTY_DOMAIN_NAME);

        int tenantId = userStoreManager.getTenantId() ;
        String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser);

        return deleteMultipleClaimsWFRequestHandler.startDeleteMultipleClaimsWorkflow(domain, userName, claims,
                                                                                      profileName);
    } catch (WorkflowException e) {
        // Sending e.getMessage() since it is required to give error message to end user.
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}