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