Search in sources :

Example 21 with IdentityEventService

use of org.wso2.carbon.identity.event.services.IdentityEventService in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2TokenUtil method triggerEvent.

private static void triggerEvent(String eventName, HashMap<String, Object> properties) throws IdentityOAuth2Exception {
    try {
        if (StringUtils.isNotBlank(eventName)) {
            Event requestObjectPersistanceEvent = new Event(eventName, properties);
            IdentityEventService identityEventService = OpenIDConnectServiceComponentHolder.getIdentityEventService();
            if (identityEventService != null) {
                if (log.isDebugEnabled()) {
                    log.debug("The event: " + eventName + " triggered.");
                }
                identityEventService.handleEvent(requestObjectPersistanceEvent);
            }
        }
    } catch (IdentityEventException e) {
        String message = "Error while triggering the event: " + eventName;
        log.error(message, e);
        throw new IdentityOAuth2Exception(message, e);
    }
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) IdentityEventService(org.wso2.carbon.identity.event.services.IdentityEventService)

Example 22 with IdentityEventService

use of org.wso2.carbon.identity.event.services.IdentityEventService in project identity-governance by wso2-extensions.

the class IdentityMgtEventListenerTest method mockHandleEvent.

private void mockHandleEvent() throws Exception {
    identityMgtEventListener = spy(IdentityMgtEventListener.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    realmConfiguration = Mockito.mock(RealmConfiguration.class);
    tenantManager = Mockito.mock(TenantManager.class);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    when(tenantManager.getDomain(SAMPLE_TENANT_ID)).thenReturn(SAMPLE_TENANT_DOMAIN);
    TestUtils.startTenantFlow(SAMPLE_TENANT_DOMAIN);
    when(userStoreManager.getTenantId()).thenReturn(SAMPLE_TENANT_ID);
    when(userStoreManager.getRealmConfiguration()).thenReturn(realmConfiguration);
    when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME)).thenReturn("PRIMARY");
    Map<String, Object> properties = new HashMap<>();
    Event identityMgtEvent = new Event("sampleEvent", properties);
    doNothing().when(identityEventService).handleEvent(any(Event.class));
    identityEventService.handleEvent(identityMgtEvent);
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) HashMap(java.util.HashMap) Event(org.wso2.carbon.identity.event.event.Event) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager)

Aggregations

IdentityEventService (org.wso2.carbon.identity.event.services.IdentityEventService)18 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)10 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)10 Event (org.wso2.carbon.identity.event.event.Event)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 AfterTest (org.testng.annotations.AfterTest)4 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)3 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)3 OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)3 Method (java.lang.reflect.Method)2 Instant (java.time.Instant)2 Hashtable (java.util.Hashtable)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpMethod (javax.ws.rs.HttpMethod)2