Search in sources :

Example 1 with IdentityOathEventListener

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

the class OAuthServiceComponent method activate.

protected void activate(ComponentContext context) {
    try {
        // initialize the OAuth Server configuration
        OAuthServerConfiguration oauthServerConfig = OAuthServerConfiguration.getInstance();
        if (OAuthCache.getInstance().isEnabled()) {
            log.debug("OAuth Caching is enabled. Initializing the cache.");
        }
        IdentityOathEventListener listener = new IdentityOathEventListener();
        serviceRegistration = context.getBundleContext().registerService(UserOperationEventListener.class.getName(), listener, null);
        log.debug("Identity Oath Event Listener is enabled");
        context.getBundleContext().registerService(AbstractEventHandler.class.getName(), new IdentityOauthEventHandler(), null);
        if (log.isDebugEnabled()) {
            log.debug("Identity Oauth Event handler is enabled");
        }
        OAuth2Service oauth2Service = new OAuth2Service();
        context.getBundleContext().registerService(OAuth2Service.class.getName(), oauth2Service, null);
        OAuthComponentServiceHolder.getInstance().setOauth2Service(oauth2Service);
        // We need to explicitly populate the OAuthTokenIssuerMap since it's used for token validation.
        oauthServerConfig.populateOAuthTokenIssuerMap();
        OAuthAdminServiceImpl oauthAdminService = new OAuthAdminServiceImpl();
        OAuthComponentServiceHolder.getInstance().setOAuthAdminService(oauthAdminService);
        OAuth2ServiceComponentHolder.getInstance().setOAuthAdminService(oauthAdminService);
        context.getBundleContext().registerService(OAuthEventInterceptor.class, new OAuthTokenSessionMappingEventHandler(), null);
        if (log.isDebugEnabled()) {
            log.debug("OAuthTokenSessionMapping Event Handler is enabled");
        }
        context.getBundleContext().registerService(OAuthAdminServiceImpl.class.getName(), oauthAdminService, null);
        if (log.isDebugEnabled()) {
            log.debug("Identity OAuth bundle is activated");
        }
    } catch (Throwable e) {
        String errMsg = "Error occurred while activating OAuth Service Component";
        log.error(errMsg, e);
        throw new RuntimeException(errMsg, e);
    }
}
Also used : OAuth2Service(org.wso2.carbon.identity.oauth2.OAuth2Service) IdentityOauthEventHandler(org.wso2.carbon.identity.oauth.listener.IdentityOauthEventHandler) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) IdentityOathEventListener(org.wso2.carbon.identity.oauth.listener.IdentityOathEventListener) OAuthAdminServiceImpl(org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) OAuthTokenSessionMappingEventHandler(org.wso2.carbon.identity.oauth.listener.OAuthTokenSessionMappingEventHandler)

Example 2 with IdentityOathEventListener

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

the class IdentityOathEventListenerTest method testDoPostUpdateCredentialByAdmin.

@Test
public void testDoPostUpdateCredentialByAdmin() 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.doPostUpdateCredentialByAdmin(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.doPostUpdateCredentialByAdmin(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 3 with IdentityOathEventListener

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

the class IdentityOathEventListenerTest method testForExceptionsInTokenRevocationPath1.

@Test
public void testForExceptionsInTokenRevocationPath1() throws Exception {
    when(OAuth2Util.checkAccessTokenPartitioningEnabled()).thenReturn(true);
    when(OAuth2Util.checkUserNameAssertionEnabled()).thenReturn(true);
    when(OAuth2Util.getUserStoreForFederatedUser(any(AuthenticatedUser.class))).thenThrow(new IdentityOAuth2Exception("message"));
    when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostUpdateCredentialByAdmin(username, new Object(), userStoreManager));
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 4 with IdentityOathEventListener

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

the class IdentityOathEventListenerTest method testDoPostSetUserClaimValue.

@Test
public void testDoPostSetUserClaimValue() 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.doPostSetUserClaimValue(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);
    IdentityOathEventListener listener = new IdentityOathEventListener();
    assertTrue(listener.doPostSetUserClaimValue(username, 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 5 with IdentityOathEventListener

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

the class IdentityOathEventListenerTest method testDoPostAuthenticate.

@Test
public void testDoPostAuthenticate() 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.doPostAuthenticate(username, true, 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.doPostAuthenticate(username, true, 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)

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