use of org.wso2.carbon.identity.event.IdentityEventException in project carbon-identity-framework by wso2.
the class AbstractEventHandler method getSubscriptionProperties.
/**
* Each event has its own subscriptions (configure in identity-event.properties) and it is possible to define
* multiple properties for each subscription per event under the given module.
* This method will allow to get the properties for event subscription under the current module.
*
* @param eventName Current Event Name
* @return Property Map for the given event name under the current module.
* @throws IdentityEventException
*/
public Properties getSubscriptionProperties(String eventName) throws IdentityEventException {
if (log.isDebugEnabled()) {
log.debug("Get the subscription properties for event : " + eventName);
}
Properties subscriptionProperties = new Properties();
List<Subscription> subscriptions = configs.getSubscriptions();
for (Subscription sub : subscriptions) {
if (sub.getSubscriptionName().equals(eventName)) {
subscriptionProperties = sub.getSubscriptionProperties();
break;
}
}
if (log.isDebugEnabled() && subscriptionProperties != null) {
log.debug("List of subscription properties for event : " + eventName);
for (Object key : subscriptionProperties.keySet()) {
log.debug("Key : " + key + " Value : " + subscriptionProperties.getProperty((String) key));
}
}
return subscriptionProperties;
}
use of org.wso2.carbon.identity.event.IdentityEventException in project carbon-identity-framework by wso2.
the class IdentityEventServiceComponent method registerEventHandler.
@Reference(name = "event.handler", service = org.wso2.carbon.identity.event.handler.AbstractEventHandler.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "unRegisterEventHandler")
protected void registerEventHandler(AbstractEventHandler eventHandler) {
String handlerName = eventHandler.getName();
try {
eventHandler.init(IdentityEventConfigBuilder.getInstance().getModuleConfigurations(handlerName));
} catch (IdentityEventException | IdentityRuntimeException e) {
log.warn("Properties for " + handlerName + " is not configured. This event handler will not be activated");
}
eventHandlerList.add(eventHandler);
MessageHandlerComparator messageHandlerComparator = new MessageHandlerComparator(null);
Collections.sort(eventHandlerList, messageHandlerComparator);
}
use of org.wso2.carbon.identity.event.IdentityEventException in project identity-conditional-auth-functions by wso2-extensions.
the class SendEmailFunctionImpl method sendMail.
@Override
public boolean sendMail(JsAuthenticatedUser user, String templateId, Map<String, String> paramMap) {
String eventName = IdentityEventConstants.Event.TRIGGER_NOTIFICATION;
HashMap<String, Object> properties = new HashMap<>(paramMap);
properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getWrapped().getUserName());
properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getWrapped().getTenantDomain());
properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getWrapped().getUserStoreDomain());
properties.put(TEMPLATE_TYPE, templateId);
Event identityMgtEvent = new Event(eventName, properties);
try {
NotificationFunctionServiceHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
} catch (IdentityEventException | NotificationRuntimeException e) {
LOG.error(String.format("Error when sending notification of template %s to user %s", templateId, user.getWrapped().toFullQualifiedUsername()), e);
return false;
}
return true;
}
use of org.wso2.carbon.identity.event.IdentityEventException in project identity-conditional-auth-functions by wso2-extensions.
the class PublishToAnalyticsFunctionImpl method publishToAnalytics.
@Override
public void publishToAnalytics(Map<String, String> metadata, Map<String, Object> payloadData, JsAuthenticationContext context) {
String appName = metadata.get(PARAM_APP_NAME);
String inputStream = metadata.get(PARAM_INPUT_STREAM);
String targetPath = metadata.get(PARAM_EP_URL);
String epUrl = null;
try {
if (appName != null && inputStream != null) {
epUrl = "/" + appName + "/" + inputStream;
} else if (targetPath != null) {
epUrl = targetPath;
} else {
LOG.error("Target path cannot be found.");
return;
}
String tenantDomain = context.getContext().getTenantDomain();
String targetHostUrl = CommonUtils.getConnectorConfig(AnalyticsEngineConfigImpl.RECEIVER, tenantDomain);
if (targetHostUrl == null) {
LOG.error("Target host cannot be found.");
return;
}
HttpPost request = new HttpPost(epUrl);
request.setHeader(CONTENT_TYPE, TYPE_APPLICATION_JSON);
handleAuthentication(request, tenantDomain);
JSONObject jsonObject = new JSONObject();
JSONObject event = new JSONObject();
for (Map.Entry<String, Object> dataElements : payloadData.entrySet()) {
event.put(dataElements.getKey(), dataElements.getValue());
}
jsonObject.put("event", event);
request.setEntity(new StringEntity(jsonObject.toJSONString()));
String[] targetHostUrls = targetHostUrl.split(";");
HttpHost[] targetHosts = new HttpHost[targetHostUrls.length];
for (int i = 0; i < targetHostUrls.length; i++) {
URL hostUrl = new URL(targetHostUrls[i]);
targetHosts[i] = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), hostUrl.getProtocol());
}
CloseableHttpAsyncClient client = ClientManager.getInstance().getClient(tenantDomain);
for (final HttpHost targetHost : targetHosts) {
client.execute(targetHost, request, new FutureCallback<HttpResponse>() {
@Override
public void completed(final HttpResponse response) {
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode == 200) {
if (LOG.isDebugEnabled()) {
LOG.debug("Successfully published data to the analytics for session data key: " + context.getContext().getContextIdentifier());
}
} else {
LOG.error("Error while publishing data to analytics engine for session data key: " + context.getContext().getContextIdentifier() + ". Request completed successfully. " + "But response code was not 200");
}
}
@Override
public void failed(final Exception ex) {
LOG.error("Error while publishing data to analytics engine for session data key: " + context.getContext().getContextIdentifier() + ". Request failed with: " + ex);
}
@Override
public void cancelled() {
LOG.error("Error while publishing data to analytics engine for session data key: " + context.getContext().getContextIdentifier() + ". Request canceled.");
}
});
}
} catch (IOException e) {
LOG.error("Error while calling analytics engine for tenant: " + context.getContext().getTenantDomain(), e);
} catch (IdentityEventException e) {
LOG.error("Error while preparing authentication information for tenant: " + context.getContext().getTenantDomain(), e);
} catch (FrameworkException e) {
LOG.error("Error while building client to invoke analytics engine for tenant: " + context.getContext().getTenantDomain(), e);
}
}
use of org.wso2.carbon.identity.event.IdentityEventException in project identity-conditional-auth-functions by wso2-extensions.
the class AbstractAnalyticsFunction method handleAuthentication.
/**
* Handle the authentication of the external analytics calls.
*
* @param request Request sent to the analytics engine.
* @param tenantDomain tenant domain of the service provider.
* @throws IdentityEventException
*/
protected void handleAuthentication(HttpPost request, String tenantDomain) throws IdentityEventException {
if (Boolean.parseBoolean(isBasicAuthEnabled(tenantDomain))) {
if (LOG.isDebugEnabled()) {
LOG.debug("Basic Authentication enabled for outbound analytics calls in the tenant:" + tenantDomain);
}
String username = getUsername(tenantDomain);
String password = getPassword(tenantDomain);
AuthenticationManager authenticationManager = authenticationFactory.getAuthenticationManager("Basic");
request.setHeader(authenticationManager.authenticate(new UsernamePasswordCredentials(username, password), request));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Basic Authentication is not enabled for outbound analytics calls in for the tenant:" + tenantDomain);
}
}
}
Aggregations