Search in sources :

Example 6 with ClaimsRetriever

use of org.wso2.carbon.apimgt.impl.token.ClaimsRetriever in project carbon-apimgt by wso2.

the class NewAPIVersionEmailNotifier method getNotifierSet.

/**
 * @param notificationDTO
 * @return a set of email ids
 * @throws NotificationException
 */
public Set<String> getNotifierSet(NotificationDTO notificationDTO) throws NotificationException {
    Set<Subscriber> subscriberList = (Set<Subscriber>) notificationDTO.getProperty(NotifierConstants.SUBSCRIBERS_PER_API);
    String claimsRetrieverImplClass = (String) notificationDTO.getProperty(NotifierConstants.CLAIMS_RETRIEVER_IMPL_CLASS);
    ClaimsRetriever claimsRetriever = null;
    Set<String> emailset = new HashSet<String>();
    try {
        for (Subscriber subscriber : subscriberList) {
            String tenantUserName = subscriber.getName();
            claimsRetriever = getClaimsRetriever(claimsRetrieverImplClass);
            claimsRetriever.init();
            String email = claimsRetriever.getClaims(tenantUserName).get(NotifierConstants.EMAIL_CLAIM);
            if (email != null && !email.isEmpty()) {
                emailset.add(email);
            }
        }
    } catch (IllegalAccessException e) {
        throw new NotificationException("Error while retrieving Email Claims ", e);
    } catch (InstantiationException e) {
        throw new NotificationException("Error while retrieving Email Claims ", e);
    } catch (ClassNotFoundException e) {
        throw new NotificationException("Cannot find claimsRetrieverImplClass ", e);
    } catch (APIManagementException e) {
        throw new NotificationException("Error while retrieving Email Claims ", e);
    }
    return emailset;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) ClaimsRetriever(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever) HashSet(java.util.HashSet)

Example 7 with ClaimsRetriever

use of org.wso2.carbon.apimgt.impl.token.ClaimsRetriever in project carbon-apimgt by wso2.

the class NewAPIVersionEmailNotifierTest method testShouldReturnNotifiersWhenPropertiesValid.

@Test
public void testShouldReturnNotifiersWhenPropertiesValid() throws APIManagementException {
    final ClaimsRetriever claimsRetriever = Mockito.mock(ClaimsRetriever.class);
    final SortedMap<String, String> claims = new TreeMap<String, String>();
    claims.put(NotifierConstants.EMAIL_CLAIM, "admin@wso2.com");
    NewAPIVersionEmailNotifier emailNotifier = new NewAPIVersionEmailNotifier() {

        @Override
        protected ClaimsRetriever getClaimsRetriever(String claimsRetrieverImplClass) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
            return claimsRetriever;
        }
    };
    Mockito.doNothing().when(claimsRetriever).init();
    Mockito.when(claimsRetriever.getClaims(Mockito.anyString())).thenReturn(claims);
    try {
        Assert.assertTrue(emailNotifier.getNotifierSet(notificationDTO).size() > 0);
    } catch (NotificationException e) {
        Assert.fail("Should not throw any exceptions");
    }
}
Also used : NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) ClaimsRetriever(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever) Test(org.junit.Test)

Aggregations

ClaimsRetriever (org.wso2.carbon.apimgt.impl.token.ClaimsRetriever)7 LinkedHashMap (java.util.LinkedHashMap)3 NotificationException (org.wso2.carbon.apimgt.impl.notification.exception.NotificationException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 Set (java.util.Set)1 Before (org.junit.Before)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)1 JWTConfigurationDto (org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 NewAPIVersionEmailNotifierWrapper (org.wso2.carbon.apimgt.impl.notification.util.NewAPIVersionEmailNotifierWrapper)1 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)1 ClaimManagementException (org.wso2.carbon.claim.mgt.ClaimManagementException)1