Search in sources :

Example 26 with Notification

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());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 27 with Notification

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);
}
Also used : JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) File(java.io.File) URL(java.net.URL) JMeterTestManager(org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) Test(org.testng.annotations.Test)

Example 28 with Notification

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);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 29 with Notification

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!");
    }
}
Also used : CGException(org.wso2.carbon.cloud.gateway.common.CGException) CGAgentAdminService(org.wso2.carbon.cloud.gateway.agent.service.CGAgentAdminService)

Example 30 with Notification

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);
            }
        }
    }
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) HashMap(java.util.HashMap) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) UserStoreException(org.wso2.carbon.user.core.UserStoreException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Aggregations

HashMap (java.util.HashMap)31 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)25 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)21 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)18 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Event (org.wso2.carbon.identity.event.event.Event)14 IdentityException (org.wso2.carbon.identity.base.IdentityException)13 User (org.wso2.carbon.identity.application.common.model.User)10 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)10 ArrayList (java.util.ArrayList)8 QName (javax.xml.namespace.QName)8 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)8 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 Property (org.wso2.carbon.identity.recovery.model.Property)7 NotificationChannels (org.wso2.carbon.identity.governance.service.notification.NotificationChannels)6 UserStoreException (org.wso2.carbon.user.core.UserStoreException)6 NotificationException (org.wso2.carbon.apimgt.impl.notification.exception.NotificationException)5 NotificationDataDTO (org.wso2.carbon.identity.mgt.dto.NotificationDataDTO)5