Search in sources :

Example 1 with RevocationRequestPublisher

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());
}
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 2 with RevocationRequestPublisher

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);
}
Also used : RevocationRequestPublisher(org.wso2.carbon.apimgt.impl.publishers.RevocationRequestPublisher) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)2 RevocationRequestPublisher (org.wso2.carbon.apimgt.impl.publishers.RevocationRequestPublisher)2 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)1 TokenRevocationEvent (org.wso2.carbon.apimgt.notification.event.TokenRevocationEvent)1