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