use of org.wso2.carbon.identity.mgt.mail.Notification in project product-iots by wso2.
the class AndroidOperation method testNotification.
@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android notification operation.")
public void testNotification() throws Exception {
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.NOTIFICATION_ENDPOINT, Constants.AndroidOperations.NOTIFICATION_PAYLOAD);
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
use of org.wso2.carbon.identity.mgt.mail.Notification in project product-iots by wso2.
the class NotificationManagementAPIJMeterTestCase method NotificationManagementTest.
@Test(description = "This test case tests the Notification Management APIs")
public void NotificationManagementTest() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader().getResource("jmeter-scripts" + File.separator + "NotificationManagementAPI.jmx");
JMeterTest script = new JMeterTest(new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running notification management api test cases using jmeter scripts");
manager.runTest(script);
}
use of org.wso2.carbon.identity.mgt.mail.Notification in project product-iots by wso2.
the class NotificationManagement method testAddNotification.
@Test(description = "Test add notification.")
public void testAddNotification() throws Exception {
HttpResponse response = client.post(Constants.NotificationManagement.NOTIFICATION_ENDPOINT, PayloadGenerator.getJsonPayload(Constants.NotificationManagement.NOTIFICATION_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.NotificationManagement.NOTIFICATION_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true);
}
use of org.wso2.carbon.identity.mgt.mail.Notification in project carbon-mediation by wso2.
the class CGAgentObserverImpl method update.
public void update(CGAgentSubject subject) {
try {
CGAgentAdminService service = new CGAgentAdminService();
String status = service.getServiceStatus(serviceName);
if (status.equals(CGConstant.CG_SERVICE_STATUS_UNPUBLISHED)) {
return;
}
// do the re-publishing of the service again
boolean isAutomatic = true;
if (!status.equals(CGConstant.CG_SERVICE_STATUS_PUBLISHED)) {
isAutomatic = false;
}
String serverName = service.getPublishedServer(serviceName);
service.unPublishService(serviceName, serverName, true);
service.publishService(serviceName, serverName, isAutomatic);
} catch (CGException e) {
log.error("Error while re-publishing the service '" + serviceName + "' via " + "received publish notification. You may need to re-publish the service manually!");
}
}
use of org.wso2.carbon.identity.mgt.mail.Notification in project identity-governance by wso2-extensions.
the class UserSelfRegistrationHandler method handleEvent.
@Override
public void handleEvent(Event event) throws IdentityEventException {
Map<String, Object> eventProperties = event.getEventProperties();
String userName = (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME);
UserStoreManager userStoreManager = (UserStoreManager) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
String tenantDomain = (String) eventProperties.get(IdentityEventConstants.EventProperty.TENANT_DOMAIN);
String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
String[] roleList = (String[]) eventProperties.get(IdentityEventConstants.EventProperty.ROLE_LIST);
User user = new User();
user.setUserName(userName);
user.setTenantDomain(tenantDomain);
user.setUserStoreDomain(domainName);
boolean enable = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP, user.getTenantDomain()));
if (!enable) {
if (log.isDebugEnabled()) {
log.debug("Self signup feature is disabled in tenant: " + tenantDomain);
}
return;
}
// Check selfSignupRole is in the request. If it is not there, this handler will not do anything. just retrun
if (roleList == null) {
return;
} else {
List<String> roles = Arrays.asList(roleList);
if (!roles.contains(IdentityRecoveryConstants.SELF_SIGNUP_ROLE)) {
return;
}
}
boolean isAccountLockOnCreation = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ACCOUNT_LOCK_ON_CREATION, user.getTenantDomain()));
boolean isEnableConfirmationOnCreation = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, user.getTenantDomain()));
boolean isNotificationInternallyManage = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, user.getTenantDomain()));
if (IdentityEventConstants.Event.POST_ADD_USER.equals(event.getEventName())) {
UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
try {
// Get the user preferred notification channel.
String preferredChannel = resolveNotificationChannel(eventProperties, userName, tenantDomain, domainName);
// If the preferred channel is already verified, no need to send the notifications or lock
// the account.
boolean notificationChannelVerified = isNotificationChannelVerified(userName, tenantDomain, preferredChannel, eventProperties);
if (notificationChannelVerified) {
return;
}
boolean isSelfRegistrationConfirmationNotify = Boolean.parseBoolean(Utils.getSignUpConfigs(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_NOTIFY_ACCOUNT_CONFIRMATION, user.getTenantDomain()));
// EnableConfirmationOnCreation are disabled then send account creation notification.
if (!isAccountLockOnCreation && !isEnableConfirmationOnCreation && isNotificationInternallyManage && isSelfRegistrationConfirmationNotify) {
triggerAccountCreationNotification(user);
}
// If notifications are externally managed, no send notifications.
if ((isAccountLockOnCreation || isEnableConfirmationOnCreation) && isNotificationInternallyManage) {
userRecoveryDataStore.invalidate(user);
// Create a secret key based on the preferred notification channel.
String secretKey = generateSecretKey(preferredChannel);
// Resolve event name.
String eventName = resolveEventName(preferredChannel, userName, domainName, tenantDomain);
UserRecoveryData recoveryDataDO = new UserRecoveryData(user, secretKey, RecoveryScenarios.SELF_SIGN_UP, RecoverySteps.CONFIRM_SIGN_UP);
// Notified channel is stored in remaining setIds for recovery purposes.
recoveryDataDO.setRemainingSetIds(preferredChannel);
userRecoveryDataStore.store(recoveryDataDO);
triggerNotification(user, preferredChannel, secretKey, Utils.getArbitraryProperties(), eventName);
}
} catch (IdentityRecoveryException e) {
throw new IdentityEventException("Error while sending self sign up notification ", e);
}
if (isAccountLockOnCreation || isEnableConfirmationOnCreation) {
HashMap<String, String> userClaims = new HashMap<>();
if (isAccountLockOnCreation) {
// Need to lock user account.
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM, Boolean.TRUE.toString());
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_REASON_CLAIM, IdentityMgtConstants.LockedReason.PENDING_SELF_REGISTRATION.toString());
}
if (Utils.isAccountStateClaimExisting(tenantDomain)) {
userClaims.put(IdentityRecoveryConstants.ACCOUNT_STATE_CLAIM_URI, IdentityRecoveryConstants.PENDING_SELF_REGISTRATION);
}
try {
userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
if (log.isDebugEnabled()) {
if (isAccountLockOnCreation) {
log.debug("Locked user account: " + user.getUserName());
}
if (isEnableConfirmationOnCreation) {
log.debug("Send verification notification for user account: " + user.getUserName());
}
}
} catch (UserStoreException e) {
throw new IdentityEventException("Error while lock user account :" + user.getUserName(), e);
}
}
}
}
Aggregations