Search in sources :

Example 61 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-identity-framework by wso2.

the class IdentityUserIdResolverListener method doPreUpdateUserListOfRole.

@Override
public boolean doPreUpdateUserListOfRole(String roleName, String[] deletedUsers, String[] newUsers, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String[] deletedUserIDs;
    try {
        deletedUserIDs = getUserIdsFromUserNames(deletedUsers, (AbstractUserStoreManager) userStoreManager);
    } catch (UserStoreException e) {
        // supported user store.
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
        return true;
    }
    String[] newUserIDs;
    try {
        newUserIDs = getUserIdsFromUserNames(newUsers, (AbstractUserStoreManager) userStoreManager);
    } catch (UserStoreException e) {
        // supported user store.
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
        return true;
    }
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!((UniqueIDUserOperationEventListener) listener).doPreUpdateUserListOfRoleWithID(roleName, deletedUserIDs, newUserIDs, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) UniqueIDUserOperationEventListener(org.wso2.carbon.user.core.listener.UniqueIDUserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener) UserStoreException(org.wso2.carbon.user.core.UserStoreException) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager)

Example 62 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPostGetUserListOfRoleWithID.

@Override
public boolean doPostGetUserListOfRoleWithID(String roleName, List<User> userList, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    List<String> returnUserNamesList = userList.stream().map(User::getUsername).collect(Collectors.toList());
    String[] returnUserNames = returnUserNamesList.toArray(new String[0]);
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPostGetUserListOfRole(roleName, returnUserNames, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)

Example 63 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPreDeleteUserWithID.

@Override
public boolean doPreDeleteUserWithID(String userID, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String userName = getUserNameFromUserID(userID, (AbstractUserStoreManager) userStoreManager);
    if (userName == null) {
        return handleUserNameResolveFailure(userID, userStoreManager);
    }
    // Setting the thread-local to keep userName for doPostDeleteUserWithID listener.
    IdentityUtil.threadLocalProperties.get().put(DO_PRE_DELETE_USER_USER_NAME, userName);
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPreDeleteUser(userName, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)

Example 64 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPreAuthenticateWithID.

@Override
public boolean doPreAuthenticateWithID(String preferredUserNameClaim, String preferredUserNameValue, Object credential, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String userName;
    String[] users = userStoreManager.getUserList(preferredUserNameClaim, preferredUserNameValue, null);
    if (users.length == 1) {
        userName = UserCoreUtil.removeDomainFromName(users[0]);
    } else {
        return true;
    }
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPreAuthenticate(userName, credential, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)

Example 65 with UserStoreManager

use of org.wso2.carbon.user.api.UserStoreManager in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPostAuthenticateWithID.

@Override
public boolean doPostAuthenticateWithID(List<LoginIdentifier> loginIdentifiers, AuthenticationResult authenticationResult, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String userName;
    boolean authenticated = authenticationResult.getAuthenticationStatus() == AuthenticationResult.AuthenticationStatus.SUCCESS;
    if (authenticated) {
        userName = authenticationResult.getAuthenticatedUser().get().getUsername();
    } else {
        return true;
    }
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPostAuthenticate(userName, authenticated, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)157 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)112 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)94 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)93 RealmService (org.wso2.carbon.user.core.service.RealmService)87 UserStoreException (org.wso2.carbon.user.core.UserStoreException)83 HashMap (java.util.HashMap)76 UserRealm (org.wso2.carbon.user.core.UserRealm)66 Test (org.testng.annotations.Test)57 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)55 IdentityException (org.wso2.carbon.identity.base.IdentityException)38 ArrayList (java.util.ArrayList)33 Map (java.util.Map)28 UserRealm (org.wso2.carbon.user.api.UserRealm)25 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)22 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 UserOperationEventListener (org.wso2.carbon.user.core.listener.UserOperationEventListener)20 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)20 AbstractIdentityUserOperationEventListener (org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)19 JDBCUserStoreManager (org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager)19