Search in sources :

Example 1 with TokenRevocationEvent

use of org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent in project carbon-apimgt by wso2.

the class AbstractKeyManagerEventHandler method handleTokenRevocationEvent.

public boolean handleTokenRevocationEvent(TokenRevocationEvent tokenRevocationEvent) throws APIManagementException {
    Properties properties = new Properties();
    properties.setProperty(APIConstants.NotificationEvent.EVENT_ID, tokenRevocationEvent.getEventId());
    properties.put(APIConstants.NotificationEvent.CONSUMER_KEY, tokenRevocationEvent.getConsumerKey());
    if (StringUtils.isBlank(tokenRevocationEvent.getTokenType())) {
        tokenRevocationEvent.setTokenType(APIConstants.NotificationEvent.APPLICATION_TOKEN_TYPE_OAUTH2);
    }
    properties.put(APIConstants.NotificationEvent.TOKEN_TYPE, tokenRevocationEvent.getTokenType());
    properties.put(APIConstants.NotificationEvent.TENANT_ID, tokenRevocationEvent.getTenantId());
    properties.put(APIConstants.NotificationEvent.TENANT_DOMAIN, tokenRevocationEvent.getTenantDomain());
    ApiMgtDAO.getInstance().addRevokedJWTSignature(tokenRevocationEvent.getEventId(), tokenRevocationEvent.getAccessToken(), tokenRevocationEvent.getTokenType(), tokenRevocationEvent.getExpiryTime(), tokenRevocationEvent.getTenantId());
    revocationRequestPublisher.publishRevocationEvents(tokenRevocationEvent.getAccessToken(), tokenRevocationEvent.getExpiryTime(), properties);
    // Cleanup expired revoked tokens from db.
    Runnable expiredJWTCleaner = new ExpiredJWTCleaner();
    Thread cleanupThread = new Thread(expiredJWTCleaner);
    cleanupThread.start();
    return true;
}
Also used : ExpiredJWTCleaner(org.wso2.carbon.apimgt.impl.keymgt.ExpiredJWTCleaner) Properties(java.util.Properties)

Example 2 with TokenRevocationEvent

use of org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent in project carbon-apimgt by wso2.

the class AbstractKeyManagerEventHandlerTest method handleTokenRevocationEventTest.

@Test
public void handleTokenRevocationEventTest() throws Exception {
    TokenRevocationEvent tokenRevocationEvent = new TokenRevocationEvent();
    Assert.assertTrue(StringUtils.isBlank(tokenRevocationEvent.getTokenType()));
    RevocationRequestPublisher revocationRequestPublisher = Mockito.mock(RevocationRequestPublisher.class);
    PowerMockito.mockStatic(RevocationRequestPublisher.class);
    PowerMockito.when(RevocationRequestPublisher.getInstance()).thenReturn(revocationRequestPublisher);
    doNothing().when(revocationRequestPublisher).publishRevocationEvents(Mockito.anyString(), Mockito.anyLong(), Mockito.anyObject());
    Properties properties = Mockito.mock(Properties.class);
    whenNew(Properties.class).withNoArguments().thenReturn(properties);
    ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    DefaultKeyManagerEventHandlerImpl defaultKeyManagerEventHandler = new DefaultKeyManagerEventHandlerImpl();
    Boolean result = defaultKeyManagerEventHandler.handleTokenRevocationEvent(tokenRevocationEvent);
    Assert.assertTrue(result);
    Assert.assertEquals("Default", tokenRevocationEvent.getTokenType());
}
Also used : RevocationRequestPublisher(org.wso2.carbon.apimgt.impl.publishers.RevocationRequestPublisher) TokenRevocationEvent(org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TokenRevocationEvent

use of org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent in project carbon-apimgt by wso2.

the class DefaultKeyManagerEventHandlerImpl method handleTokenRevocationEvent.

private boolean handleTokenRevocationEvent(String event) throws APIManagementException {
    TokenRevocationEvent tokenRevocationEvent = new Gson().fromJson(event, TokenRevocationEvent.class);
    handleTokenRevocationEvent(tokenRevocationEvent);
    return true;
}
Also used : Gson(com.google.gson.Gson) TokenRevocationEvent(org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent)

Example 4 with TokenRevocationEvent

use of org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent in project carbon-apimgt by wso2.

the class TokenRevocationNotifierImpl method sendMessageOnRealtime.

/**
 * Method to publish the revoked token on to the realtime message broker
 *
 * @param revokedToken requested revoked token
 * @param properties realtime notifier properties read from the config
 */
@Override
public void sendMessageOnRealtime(String revokedToken, Properties properties) {
    // Variables related to Realtime Notifier
    String realtimeNotifierTTL = realTimeNotifierProperties.getProperty("ttl", DEFAULT_TTL);
    long expiryTimeForJWT = Long.parseLong(properties.getProperty("expiryTime"));
    String eventId = properties.getProperty(APIConstants.NotificationEvent.EVENT_ID);
    String tokenType = properties.getProperty(APIConstants.NotificationEvent.TOKEN_TYPE);
    int tenantId = (int) properties.get(APIConstants.NotificationEvent.TENANT_ID);
    Object[] objects = new Object[] { eventId, revokedToken, realtimeNotifierTTL, expiryTimeForJWT, tokenType, tenantId };
    EventPublisherEvent tokenRevocationEvent = new EventPublisherEvent(APIConstants.TOKEN_REVOCATION_STREAM_ID, System.currentTimeMillis(), objects);
    APIUtil.publishEvent(EventPublisherType.TOKEN_REVOCATION, tokenRevocationEvent, tokenRevocationEvent.toString());
}
Also used : EventPublisherEvent(org.wso2.carbon.apimgt.eventing.EventPublisherEvent)

Aggregations

Properties (java.util.Properties)2 TokenRevocationEvent (org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent)2 Gson (com.google.gson.Gson)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 EventPublisherEvent (org.wso2.carbon.apimgt.eventing.EventPublisherEvent)1 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)1 ExpiredJWTCleaner (org.wso2.carbon.apimgt.impl.keymgt.ExpiredJWTCleaner)1 RevocationRequestPublisher (org.wso2.carbon.apimgt.impl.publishers.RevocationRequestPublisher)1