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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations