Search in sources :

Example 11 with UserOperationEventListener

use of org.wso2.carbon.user.core.listener.UserOperationEventListener in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPreGetUserListWithID.

@Override
public boolean doPreGetUserListWithID(String claimUri, String claimValue, List<User> returnUsersList, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    List<String> returnUserNamesList = returnUsersList.stream().map(User::getUsername).collect(Collectors.toList());
    Set<String> returnInitialUserNamesList = new HashSet<>(returnUserNamesList);
    Set<String> tempUserNamesList = new HashSet<>();
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPreGetUserList(claimUri, claimValue, returnUserNamesList, userStoreManager)) {
                return false;
            }
        }
    }
    // Reflect newly removed users by listeners in returnUsersList
    if (CollectionUtils.isNotEmpty(returnUserNamesList)) {
        tempUserNamesList.addAll(returnInitialUserNamesList);
        tempUserNamesList.removeAll(returnUserNamesList);
        for (User user : returnUsersList) {
            if (tempUserNamesList.contains(user.getUsername())) {
                returnUsersList.remove(user);
            }
        }
        tempUserNamesList.clear();
    }
    // Reflect newly add users by listeners in returnUsersList
    if (CollectionUtils.isNotEmpty(returnUserNamesList)) {
        tempUserNamesList.addAll(returnUserNamesList);
        tempUserNamesList.removeAll(returnInitialUserNamesList);
        for (String username : tempUserNamesList) {
            User newUser = new User();
            newUser.setUsername(username);
            try {
                newUser.setUserID(FrameworkUtils.resolveUserIdFromUsername(userStoreManager, username));
            } catch (UserSessionException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Error occurred while resolving Id for the user: " + username, e);
                }
            }
            returnUsersList.add(newUser);
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener) User(org.wso2.carbon.user.core.common.User) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException) HashSet(java.util.HashSet)

Example 12 with UserOperationEventListener

use of org.wso2.carbon.user.core.listener.UserOperationEventListener in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPostAuthenticateWithID.

@Override
public boolean doPostAuthenticateWithID(String userID, 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 {
        userName = getUserNameFromUserID(userID, (AbstractUserStoreManager) userStoreManager);
    }
    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) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager)

Example 13 with UserOperationEventListener

use of org.wso2.carbon.user.core.listener.UserOperationEventListener in project carbon-identity-framework by wso2.

the class IdentityUserNameResolverListener method doPostUpdateUserListOfRoleWithID.

@Override
public boolean doPostUpdateUserListOfRoleWithID(String roleName, String[] deletedUserIDs, String[] newUserIDs, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String[] deletedUserNames = getUserNamesFromUserIDs(deletedUserIDs, (AbstractUserStoreManager) userStoreManager);
    String[] newUserNames = getUserNamesFromUserIDs(newUserIDs, (AbstractUserStoreManager) userStoreManager);
    for (UserOperationEventListener listener : getUserStoreManagerListeners()) {
        if (isNotAResolverListener(listener)) {
            if (!listener.doPostUpdateUserListOfRole(roleName, deletedUserNames, newUserNames, userStoreManager)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) AbstractIdentityUserOperationEventListener(org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)

Example 14 with UserOperationEventListener

use of org.wso2.carbon.user.core.listener.UserOperationEventListener in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMCommonComponent method activate.

@Activate
protected void activate(ComponentContext ctx) {
    try {
        String filePath = IdentityUtil.getIdentityConfigDirPath() + File.separator + SCIMCommonConstants.CHARON_CONFIG_NAME;
        SCIMConfigProcessor scimConfigProcessor = SCIMConfigProcessor.getInstance();
        scimConfigProcessor.buildConfigFromFile(filePath);
        // reading user schema extension
        if (Boolean.parseBoolean(scimConfigProcessor.getProperty("user-schema-extension-enabled"))) {
            String schemaFilePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG;
            SCIMUserSchemaExtensionBuilder.getInstance().buildUserSchemaExtension(schemaFilePath);
        }
        // If custom schema is enabled, read it root attribute URI from the file config if it is configured.
        if (SCIMCommonUtils.isCustomSchemaEnabled()) {
            SCIMCustomSchemaExtensionBuilder.getInstance().setURI(SCIMCommonUtils.getCustomSchemaURI());
        }
        // register UserOperationEventListener implementation
        SCIMUserOperationListener scimUserOperationListener = new SCIMUserOperationListener();
        userOperationEventListenerServiceReg = ctx.getBundleContext().registerService(UserOperationEventListener.class, scimUserOperationListener, null);
        // register scimTenantMgtListener implementation
        SCIMTenantMgtListener scimTenantMgtListener = new SCIMTenantMgtListener();
        tenantMgtListenerServiceReg = ctx.getBundleContext().registerService(TenantMgtListener.class, scimTenantMgtListener, null);
        // Register claim operation event handler implementation.
        ctx.getBundleContext().registerService(AbstractEventHandler.class.getName(), new SCIMClaimOperationEventHandler(), null);
        if (logger.isDebugEnabled()) {
            logger.debug("SCIMClaimOperationEventHandler is successfully registered.");
        }
        // Register default implementation of SCIMUserStoreErrorResolver
        ctx.getBundleContext().registerService(SCIMUserStoreErrorResolver.class.getName(), new DefaultSCIMUserStoreErrorResolver(), null);
        // Register default implementation of SCIMGroupResolver.
        ctx.getBundleContext().registerService(GroupResolver.class.getName(), new SCIMGroupResolver(), null);
        // Update super tenant user/group attributes.
        AdminAttributeUtil.updateAdminUser(MultitenantConstants.SUPER_TENANT_ID, true);
        AdminAttributeUtil.updateAdminGroup(MultitenantConstants.SUPER_TENANT_ID);
        if (logger.isDebugEnabled()) {
            logger.debug("SCIM Common component activated successfully.");
        }
    } catch (CharonException e) {
        logger.error("Error in reading information from identity tables at SCIMCommonComponentStartup.", e);
    } catch (InternalErrorException e) {
        logger.error("Error in reading information from identity tables at SCIMCommonComponentStartup.", e);
    }
}
Also used : UserOperationEventListener(org.wso2.carbon.user.core.listener.UserOperationEventListener) SCIMUserOperationListener(org.wso2.carbon.identity.scim2.common.listener.SCIMUserOperationListener) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMConfigProcessor(org.wso2.carbon.identity.scim2.common.utils.SCIMConfigProcessor) SCIMTenantMgtListener(org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener) TenantMgtListener(org.wso2.carbon.stratos.common.listeners.TenantMgtListener) SCIMTenantMgtListener(org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener) DefaultSCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver) SCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) SCIMClaimOperationEventHandler(org.wso2.carbon.identity.scim2.common.handlers.SCIMClaimOperationEventHandler) SCIMGroupResolver(org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver) SCIMGroupResolver(org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver) GroupResolver(org.wso2.carbon.user.core.listener.GroupResolver) CharonException(org.wso2.charon3.core.exceptions.CharonException) DefaultSCIMUserStoreErrorResolver(org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver) Activate(org.osgi.service.component.annotations.Activate)

Example 15 with UserOperationEventListener

use of org.wso2.carbon.user.core.listener.UserOperationEventListener in project carbon-identity-framework by wso2.

the class IdentityUserIdResolverListener method doPostUpdateUserListOfRole.

@Override
public boolean doPostUpdateUserListOfRole(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).doPostUpdateUserListOfRoleWithID(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)

Aggregations

UserOperationEventListener (org.wso2.carbon.user.core.listener.UserOperationEventListener)22 AbstractIdentityUserOperationEventListener (org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)19 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)9 UniqueIDUserOperationEventListener (org.wso2.carbon.user.core.listener.UniqueIDUserOperationEventListener)7 UserStoreException (org.wso2.carbon.user.core.UserStoreException)4 Activate (org.osgi.service.component.annotations.Activate)3 TenantMgtListener (org.wso2.carbon.stratos.common.listeners.TenantMgtListener)3 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 User (org.wso2.carbon.user.core.common.User)2 UniqueIDUserClaimSearchEntry (org.wso2.carbon.user.core.model.UniqueIDUserClaimSearchEntry)2 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 AxisObserver (org.apache.axis2.engine.AxisObserver)1 BundleContext (org.osgi.framework.BundleContext)1 UserSessionException (org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)1 ClaimMetadataMgtListener (org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataMgtListener)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 IdentityMgtEventListener (org.wso2.carbon.identity.mgt.IdentityMgtEventListener)1 IdentityUserIdResolverListener (org.wso2.carbon.identity.mgt.listener.IdentityUserIdResolverListener)1 IdentityUserNameResolverListener (org.wso2.carbon.identity.mgt.listener.IdentityUserNameResolverListener)1