Search in sources :

Example 6 with IdentityOathEventListener

use of org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPostSetUserClaimValues.

@Test
public void testDoPostSetUserClaimValues() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    assertTrue(identityOathEventListener.doPostSetUserClaimValues(username, mockedMapClaims, profileName, userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostSetUserClaimValues(username, mockedMapClaims, profileName, userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 7 with IdentityOathEventListener

use of org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPostUpdateCredential.

@Test
public void testDoPostUpdateCredential() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    OAuthServerConfiguration mockedServerConfig = mock(OAuthServerConfiguration.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    IdentityOathEventListener ioeListener = new IdentityOathEventListener();
    assertTrue(ioeListener.doPostUpdateCredential(username, new Object(), userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostUpdateCredential(username, new Object(), userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 8 with IdentityOathEventListener

use of org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testForExceptionInTokenRevocationPath4.

@Test
public void testForExceptionInTokenRevocationPath4() throws Exception {
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    Set<String> clientIds = new HashSet<String>();
    clientIds.add("CLIENT_ID_ONE");
    AccessTokenDO accessTokenDO = new AccessTokenDO();
    accessTokenDO.setConsumerKey("CONSUMER_KEY");
    accessTokenDO.setAuthzUser(authenticatedUser);
    accessTokenDO.setScope(new String[] { "OPEN_ID", "PROFILE" });
    accessTokenDO.setAccessToken("ACCESS_TOKEN  ");
    when(IdentityUtil.isUserStoreInUsernameCaseSensitive(anyString())).thenReturn(true);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostUpdateCredentialByAdmin(username, new Object(), userStoreManager));
}
Also used : AccessTokenDO(org.wso2.carbon.identity.oauth2.model.AccessTokenDO) IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 9 with IdentityOathEventListener

use of org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPreDeleteUser.

@Test
public void testDoPreDeleteUser() throws Exception {
    IdentityEventListenerConfig listenerConfig = mock(IdentityEventListenerConfig.class);
    IdentityCacheConfig identityCacheConfig = mock(IdentityCacheConfig.class);
    ClaimCache claimCache = mock(ClaimCache.class);
    OAuthServerConfiguration mockedServerConfig = mock(OAuthServerConfiguration.class);
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(listenerConfig);
    when(StringUtils.isNotBlank(anyString())).thenReturn(true);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPreDeleteUser(username, userStoreManager));
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityUtil.getIdentityCacheConfig(anyString(), anyString())).thenReturn(identityCacheConfig);
    when(claimCache.isEnabled()).thenReturn(false);
    when(ClaimMetaDataCache.getInstance()).thenReturn(claimMetaDataCache);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    IdentityOathEventListener listener2 = new IdentityOathEventListener();
    assertTrue(listener2.doPreDeleteUser(username, userStoreManager));
}
Also used : IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) ClaimCache(org.wso2.carbon.identity.oauth.util.ClaimCache) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 10 with IdentityOathEventListener

use of org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOathEventListenerTest method testDoPreSetUserClaimValueWithAuthorizationCode.

@Test
public void testDoPreSetUserClaimValueWithAuthorizationCode() throws Exception {
    Set<String> accessToken = new HashSet<>();
    accessToken.add("kljdslfjljdsfjldsflkdsjkfjdsjlkj");
    Set<String> authorizationCodes = new HashSet<String>();
    authorizationCodes.add("AUTHORIZATION_CODE");
    AuthorizationGrantCache authorizationGrantCache = mock(AuthorizationGrantCache.class);
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    when(IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn("TENANT_DOMAIN_NAME");
    whenNew(AuthenticatedUser.class).withNoArguments().thenReturn(authenticatedUser);
    when(AuthorizationGrantCache.getInstance()).thenReturn(authorizationGrantCache);
    IdentityOathEventListener identityOathEventListener = new IdentityOathEventListener();
    assertTrue(identityOathEventListener.doPreSetUserClaimValue(username, claimUri, claimValue, profileName, userStoreManager));
}
Also used : AuthorizationGrantCache(org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)12 IdentityCacheConfig (org.wso2.carbon.identity.core.model.IdentityCacheConfig)8 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)7 ClaimCache (org.wso2.carbon.identity.oauth.util.ClaimCache)7 HashSet (java.util.HashSet)5 Matchers.anyString (org.mockito.Matchers.anyString)5 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)5 AuthorizationGrantCache (org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache)3 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 OAuthAdminServiceImpl (org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl)1 IdentityOathEventListener (org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener)1 IdentityOauthEventHandler (org.wso2.carbon.identity.oauth.listener.IdentityOauthEventHandler)1 OAuthTokenSessionMappingEventHandler (org.wso2.carbon.identity.oauth.listener.OAuthTokenSessionMappingEventHandler)1 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)1 OAuth2Service (org.wso2.carbon.identity.oauth2.OAuth2Service)1