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