Search in sources :

Example 1 with IdentityStoreEventListener

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);
    }
}
Also used : DefaultNotificationChannelManager(org.wso2.carbon.identity.governance.internal.service.impl.notification.DefaultNotificationChannelManager) NotificationChannelManager(org.wso2.carbon.identity.governance.service.notification.NotificationChannelManager) IdentityMgtEventListener(org.wso2.carbon.identity.governance.listener.IdentityMgtEventListener) IdentityStoreEventListener(org.wso2.carbon.identity.governance.listener.IdentityStoreEventListener) IdentityGovernanceServiceImpl(org.wso2.carbon.identity.governance.IdentityGovernanceServiceImpl) DefaultNotificationChannelManager(org.wso2.carbon.identity.governance.internal.service.impl.notification.DefaultNotificationChannelManager) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with IdentityStoreEventListener

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));
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) Field(java.lang.reflect.Field) UserIdentityDataStore(org.wso2.carbon.identity.governance.store.UserIdentityDataStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with IdentityStoreEventListener

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));
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) Field(java.lang.reflect.Field) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UserIdentityDataStore(org.wso2.carbon.identity.governance.store.UserIdentityDataStore) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with IdentityStoreEventListener

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));
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) Field(java.lang.reflect.Field) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UserIdentityDataStore(org.wso2.carbon.identity.governance.store.UserIdentityDataStore) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with IdentityStoreEventListener

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);
}
Also used : IdentityErrorMsgContext(org.wso2.carbon.identity.core.model.IdentityErrorMsgContext)

Aggregations

UserIdentityClaim (org.wso2.carbon.identity.governance.model.UserIdentityClaim)5 Field (java.lang.reflect.Field)4 BeforeTest (org.testng.annotations.BeforeTest)4 Test (org.testng.annotations.Test)4 UserIdentityDataStore (org.wso2.carbon.identity.governance.store.UserIdentityDataStore)4 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)4 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 UserStoreBasedIdentityDataStore (org.wso2.carbon.identity.governance.store.UserStoreBasedIdentityDataStore)3 UserClaimSearchEntry (org.wso2.carbon.user.core.model.UserClaimSearchEntry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Activate (org.osgi.service.component.annotations.Activate)1 IdentityException (org.wso2.carbon.identity.base.IdentityException)1 IdentityErrorMsgContext (org.wso2.carbon.identity.core.model.IdentityErrorMsgContext)1 IdentityGovernanceServiceImpl (org.wso2.carbon.identity.governance.IdentityGovernanceServiceImpl)1 DefaultNotificationChannelManager (org.wso2.carbon.identity.governance.internal.service.impl.notification.DefaultNotificationChannelManager)1