use of org.wso2.carbon.apimgt.impl.publishers.RevocationRequestPublisher 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.impl.publishers.RevocationRequestPublisher in project carbon-apimgt by wso2.
the class APIConsumerImpl method revokeAPIKey.
public void revokeAPIKey(String apiKey, long expiryTime, String tenantDomain) throws APIManagementException {
RevocationRequestPublisher revocationRequestPublisher = RevocationRequestPublisher.getInstance();
Properties properties = new Properties();
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
String eventID = UUID.randomUUID().toString();
properties.put(APIConstants.NotificationEvent.EVENT_ID, eventID);
properties.put(APIConstants.NotificationEvent.TOKEN_TYPE, APIConstants.API_KEY_AUTH_TYPE);
properties.put(APIConstants.NotificationEvent.TENANT_ID, tenantId);
properties.put(APIConstants.NotificationEvent.TENANT_DOMAIN, tenantDomain);
ApiMgtDAO.getInstance().addRevokedJWTSignature(eventID, apiKey, APIConstants.API_KEY_AUTH_TYPE, expiryTime, tenantId);
revocationRequestPublisher.publishRevocationEvents(apiKey, expiryTime, properties);
}
Aggregations