Search in sources :

Example 1 with OAuthEventInterceptor

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

the class OAuth2Service method invokePostRevocationListeners.

private void invokePostRevocationListeners(OAuthRevocationRequestDTO revokeRequestDTO, OAuthRevocationResponseDTO revokeResponseDTO, AccessTokenDO accessTokenDO, RefreshTokenValidationDataDO refreshTokenDO) {
    OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance().getOAuthEventInterceptorProxy();
    if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) {
        try {
            Map<String, Object> paramMap = new HashMap<>();
            oAuthEventInterceptorProxy.onPostTokenRevocationByClient(revokeRequestDTO, revokeResponseDTO, accessTokenDO, refreshTokenDO, paramMap);
        } catch (IdentityOAuth2Exception e) {
            log.error("Error occurred when invoking post token revoke listener ", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)

Example 2 with OAuthEventInterceptor

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

the class OAuthAdminServiceImpl method triggerPostRevokeListeners.

void triggerPostRevokeListeners(OAuthRevocationRequestDTO revokeRequestDTO, OAuthRevocationResponseDTO revokeRespDTO, AccessTokenDO[] accessTokenDOs) {
    OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance().getOAuthEventInterceptorProxy();
    for (AccessTokenDO accessTokenDO : accessTokenDOs) {
        if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) {
            try {
                Map<String, Object> paramMap = new HashMap<String, Object>();
                oAuthEventInterceptorProxy.onPostTokenRevocationByResourceOwner(revokeRequestDTO, revokeRespDTO, accessTokenDO, paramMap);
            } catch (IdentityOAuth2Exception e) {
                LOG.error("Error occurred with post revocation listener.", e);
            }
        }
    }
}
Also used : AccessTokenDO(org.wso2.carbon.identity.oauth2.model.AccessTokenDO) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) HashMap(java.util.HashMap) OAuth2Util.buildScopeString(org.wso2.carbon.identity.oauth2.util.OAuth2Util.buildScopeString) OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)

Example 3 with OAuthEventInterceptor

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

the class AccessTokenIssuer method triggerPostListeners.

private void triggerPostListeners(OAuth2AccessTokenReqDTO tokenReqDTO, OAuth2AccessTokenRespDTO tokenRespDTO, OAuthTokenReqMessageContext tokReqMsgCtx, boolean isRefresh) {
    OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance().getOAuthEventInterceptorProxy();
    if (isRefresh) {
        if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) {
            try {
                if (log.isDebugEnabled()) {
                    log.debug("Triggering refresh token post renewal listeners for client: " + tokenReqDTO.getClientId());
                }
                Map<String, Object> paramMap = new HashMap<>();
                oAuthEventInterceptorProxy.onPostTokenRenewal(tokenReqDTO, tokenRespDTO, tokReqMsgCtx, paramMap);
            } catch (IdentityOAuth2Exception e) {
                log.error("Oauth post renewal listener failed", e);
            }
        }
    } else {
        if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) {
            try {
                if (log.isDebugEnabled()) {
                    log.debug("Triggering access token post issuer listeners for client: " + tokenReqDTO.getClientId());
                }
                Map<String, Object> paramMap = new HashMap<>();
                oAuthEventInterceptorProxy.onPostTokenIssue(tokenReqDTO, tokenRespDTO, tokReqMsgCtx, paramMap);
            } catch (IdentityOAuth2Exception e) {
                log.error("Oauth post issuer listener failed.", e);
            }
        }
    }
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) HashMap(java.util.HashMap) OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)

Example 4 with OAuthEventInterceptor

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

the class OAuth2Util method triggerOnIntrospectionExceptionListeners.

/**
 * Extract information related to the token introspection and publish the event on introspection error.
 *
 * @param
 */
public static void triggerOnIntrospectionExceptionListeners(OAuth2TokenValidationRequestDTO introspectionRequest, OAuth2IntrospectionResponseDTO introspectionResponse) {
    Map<String, Object> params = new HashMap<>();
    params.put("error", introspectionResponse.getError());
    try {
        OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance().getOAuthEventInterceptorProxy();
        if (oAuthEventInterceptorProxy != null) {
            try {
                oAuthEventInterceptorProxy.onTokenValidationException(introspectionRequest, params);
            } catch (IdentityOAuth2Exception e) {
                log.error("Error while invoking OAuthEventInterceptor for onTokenValidationException", e);
            }
        }
    } catch (Throwable e) {
        // Catching a throwable as we do no need to interrupt the code flow since these are logging purposes.
        if (log.isDebugEnabled()) {
            log.debug("Error occurred while executing oAuthEventInterceptorProxy for onTokenValidationException.", e);
        }
    }
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JWEObject(com.nimbusds.jose.JWEObject) JSONObject(org.json.JSONObject) OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)

Example 5 with OAuthEventInterceptor

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

the class TokenResponseTypeHandlerTest method setUp.

@BeforeTest
public void setUp() throws Exception {
    OAuthEventInterceptor interceptor = Mockito.mock(OAuthEventInterceptor.class);
    OAuthComponentServiceHolder.getInstance().addOauthEventInterceptorProxy(interceptor);
}
Also used : OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

OAuthEventInterceptor (org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)12 HashMap (java.util.HashMap)11 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)7 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)3 IdentityException (org.wso2.carbon.identity.base.IdentityException)2 InvalidOAuthClientException (org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)2 OAuth2Util.buildScopeString (org.wso2.carbon.identity.oauth2.util.OAuth2Util.buildScopeString)2 JWEObject (com.nimbusds.jose.JWEObject)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 JSONObject (org.json.JSONObject)1 BeforeTest (org.testng.annotations.BeforeTest)1 UserIdNotFoundException (org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException)1 OAuthCacheKey (org.wso2.carbon.identity.oauth.cache.OAuthCacheKey)1 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)1 OAuthClientAuthnContext (org.wso2.carbon.identity.oauth2.bean.OAuthClientAuthnContext)1 OAuth2AuthorizeReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO)1