use of org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener in project identity-governance by wso2-extensions.
the class IdentityMgtServiceComponent method activate.
@Activate
protected void activate(ComponentContext context) {
try {
IdentityMgtEventListener listener = new IdentityMgtEventListener();
context.getBundleContext().registerService(UserOperationEventListener.class, listener, null);
context.getBundleContext().registerService(UserOperationEventListener.class, new IdentityStoreEventListener(), null);
IdentityGovernanceServiceImpl identityGovernanceService = new IdentityGovernanceServiceImpl();
context.getBundleContext().registerService(IdentityGovernanceService.class, identityGovernanceService, null);
IdentityMgtServiceDataHolder.getInstance().setIdentityGovernanceService(identityGovernanceService);
DefaultNotificationChannelManager defaultNotificationChannelManager = new DefaultNotificationChannelManager();
context.getBundleContext().registerService(NotificationChannelManager.class.getName(), defaultNotificationChannelManager, null);
if (log.isDebugEnabled()) {
log.debug("Identity Management Listener is enabled");
}
} catch (Exception e) {
log.error("Error while activating identity governance component.", e);
}
}
use of org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener in project identity-governance by wso2-extensions.
the class IdentityStoreEventListenerTest method testDoPostGetUserClaimValues.
@Test(dataProvider = "getUserClaimHandler")
public void testDoPostGetUserClaimValues(String userName, Object pwd, String[] claimList, Map<String, String> claims, String prof) throws Exception {
realmConfiguration = mock(RealmConfiguration.class);
userIdentityDataStore = mock(UserIdentityDataStore.class);
Field fieldIdentityStore = IdentityStoreEventListener.class.getDeclaredField("identityDataStore");
fieldIdentityStore.setAccessible(true);
fieldIdentityStore.set(identityStoreEventListener, userIdentityDataStore);
Assert.assertTrue(identityStoreEventListener.doPostGetUserClaimValues(userName, claimList, prof, claims, userStoreManager));
}
use of org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener in project identity-governance by wso2-extensions.
the class IdentityStoreEventListenerTest method testDoPostDeleteUser.
@Test
public void testDoPostDeleteUser() throws Exception {
userStoreManager = mock(UserStoreManager.class);
realmConfiguration = mock(RealmConfiguration.class);
userIdentityDataStore = mock(UserIdentityDataStore.class);
String username = "user1";
Field fieldIdentityStore = IdentityStoreEventListener.class.getDeclaredField("identityDataStore");
fieldIdentityStore.setAccessible(true);
fieldIdentityStore.set(identityStoreEventListener, userIdentityDataStore);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(userIdentityDataStore).remove(username, userStoreManager);
Assert.assertTrue(identityStoreEventListener.doPostDeleteUser(username, userStoreManager));
}
use of org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener in project identity-governance by wso2-extensions.
the class IdentityStoreEventListenerTest method testDoPreGetUserList.
@Test(dataProvider = "getuserlistHandler")
public void testDoPreGetUserList(String claimUri, String claimValue, final List<String> userList, String userStore) throws Exception {
userStoreManager = mock(UserStoreManager.class);
realmConfiguration = mock(RealmConfiguration.class);
userIdentityDataStore = mock(UserIdentityDataStore.class);
Field fieldIdentityStore = IdentityStoreEventListener.class.getDeclaredField("identityDataStore");
fieldIdentityStore.setAccessible(true);
fieldIdentityStore.set(identityStoreEventListener, userIdentityDataStore);
final List<String> userIds = new ArrayList<>();
userIds.add("PRIMARY/user1@carbon.super");
userIds.add("PRIMARY/user2@abc.com");
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return userIds;
}
}).when(userIdentityDataStore).list(claimUri, claimValue, userStoreManager);
Mockito.when(userStoreManager.getRealmConfiguration()).thenReturn(realmConfiguration);
Mockito.when(UserCoreUtil.getDomainName(realmConfiguration)).thenReturn(userStore);
assertTrue(identityStoreEventListener.doPreGetUserList(claimUri, claimValue, userList, userStoreManager));
}
use of org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener in project identity-governance by wso2-extensions.
the class IdentityStoreEventListener method doPreSetUserClaimValues.
/**
* As in the above method the user account lock claim, primary challenges
* claim will be separately handled. Identity claims will be removed from
* the claim set before adding claims to the user store.
*/
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> claims, String profileName, UserStoreManager userStoreManager) throws UserStoreException {
if (!isEnable()) {
return true;
}
if (log.isDebugEnabled()) {
log.debug("doPreSetUserClaimValues executed in the IdentityStoreEventListener for user: " + userName);
}
boolean accountLocked = Boolean.parseBoolean(claims.get(UserIdentityDataStore.ACCOUNT_LOCK));
if (accountLocked) {
IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(UserCoreConstants.ErrorCode.USER_IS_LOCKED);
IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
}
return storeInIdentityDataStore(userName, userStoreManager, PRE_SET_USER_CLAIM_VALUES, claims);
}
Aggregations