Search in sources :

Example 1 with MetaProperty

use of org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty in project identity-governance by wso2-extensions.

the class UserAccountRecoveryManager method checkUserValidityForAccountRecovery.

/**
 * Check whether the user account is eligible for account recovery.
 *
 * @param user                         The user.
 * @param recoveryScenario             Account recovery scenario.
 * @param recoveryNotificationChannels Notification channel.
 * @param metaProperties               Meta details.
 * @throws IdentityRecoveryException If account doesn't satisfy the conditions to recover.
 */
private void checkUserValidityForAccountRecovery(User user, RecoveryScenarios recoveryScenario, List<NotificationChannel> recoveryNotificationChannels, Map<String, String> metaProperties) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER, user);
    properties.put(IdentityEventConstants.EventProperty.USER_STORE_MANAGER, getUserStoreManager(user));
    properties.put(IdentityEventConstants.EventProperty.RECOVERY_SCENARIO, recoveryScenario);
    properties.put(IdentityEventConstants.EventProperty.NOTIFICATION_CHANNEL, recoveryNotificationChannels);
    if (MapUtils.isNotEmpty(metaProperties)) {
        for (Map.Entry<String, String> metaProperty : metaProperties.entrySet()) {
            if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
                properties.put(metaProperty.getKey(), metaProperty.getValue());
            }
        }
    }
    Event identityMgtEvent = new Event(IdentityEventConstants.Event.PRE_ACCOUNT_RECOVERY, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error occurred while validating user account " + user.getUserName() + " for account recovery.");
        }
        String errorMessage = e.getMessage();
        String errorCode = IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_RECOVERY_VALIDATION_FAILED.getCode();
        if (USERNAME_RECOVERY.equals(recoveryScenario)) {
            errorCode = IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USERNAME_RECOVERY_VALIDATION_FAILED.getCode();
        } else if (NOTIFICATION_BASED_PW_RECOVERY.equals(recoveryScenario) || QUESTION_BASED_PWD_RECOVERY.equals(recoveryScenario)) {
            errorCode = IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_PASSWORD_RECOVERY_VALIDATION_FAILED.getCode();
        }
        throw Utils.handleClientException(errorCode, errorMessage, user.getUserName());
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MetaProperty

use of org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty in project identity-governance by wso2-extensions.

the class NotificationPasswordRecoveryManager method publishEvent.

private void publishEvent(User user, String notify, String code, String password, Property[] metaProperties, String eventName, UserRecoveryData userRecoveryData) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER, user);
    properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getUserName());
    properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
    properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());
    if (userRecoveryData != null) {
        properties.put(IdentityEventConstants.EventProperty.RECOVERY_SCENARIO, userRecoveryData.getRecoveryScenario().name());
    }
    if (StringUtils.isNotBlank(code)) {
        properties.put(IdentityRecoveryConstants.CONFIRMATION_CODE, code);
    }
    if (StringUtils.isNotBlank(notify)) {
        properties.put(IdentityRecoveryConstants.NOTIFY, notify);
    }
    if (metaProperties != null) {
        for (Property metaProperty : metaProperties) {
            if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
                properties.put(metaProperty.getKey(), metaProperty.getValue());
            }
        }
    }
    Event identityMgtEvent = new Event(eventName, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventClientException e) {
        throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_HANDLING_THE_EVENT.getCode(), e.getMessage(), null);
    } catch (IdentityEventException e) {
        log.error("Error occurred while publishing event " + eventName + " for user " + user);
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_PUBLISH_EVENT, eventName, e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) IdentityEventClientException(org.wso2.carbon.identity.event.IdentityEventClientException) JSONObject(org.json.JSONObject) Property(org.wso2.carbon.identity.recovery.model.Property)

Example 3 with MetaProperty

use of org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty in project identity-api-server by wso2.

the class ServerIdpManagementService method createMetaOutboundConnector.

private MetaOutboundConnector createMetaOutboundConnector(ProvisioningConnectorConfig connectorConfig) {
    MetaOutboundConnector metaOutboundProvisioningConnector = new MetaOutboundConnector();
    metaOutboundProvisioningConnector.setName(connectorConfig.getName());
    metaOutboundProvisioningConnector.setDisplayName(connectorConfig.getName());
    metaOutboundProvisioningConnector.setConnectorId(base64URLEncode(connectorConfig.getName()));
    Property[] properties = connectorConfig.getProvisioningProperties();
    List<MetaProperty> metaProperties = Arrays.stream(properties).map(propertyToExternalMeta).collect(Collectors.toList());
    metaOutboundProvisioningConnector.setProperties(metaProperties);
    return metaOutboundProvisioningConnector;
}
Also used : MetaOutboundConnector(org.wso2.carbon.identity.api.server.idp.v1.model.MetaOutboundConnector) MetaProperty(org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) SubProperty(org.wso2.carbon.identity.application.common.model.SubProperty) MetaProperty(org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty)

Example 4 with MetaProperty

use of org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty in project identity-governance by wso2-extensions.

the class UserSelfRegistrationManager method publishEvent.

/**
 * Method to publish pre and post self sign up register event.
 *
 * @param user           self sign up user
 * @param claims         claims of the user
 * @param metaProperties other properties of the request
 * @param eventName      event name (PRE_SELF_SIGNUP_REGISTER,POST_SELF_SIGNUP_REGISTER)
 * @throws IdentityRecoveryException
 */
private void publishEvent(User user, Claim[] claims, Property[] metaProperties, String eventName) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getUserName());
    properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
    properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());
    properties.put(IdentityEventConstants.EventProperty.USER_CLAIMS, claims);
    if (metaProperties != null) {
        for (Property metaProperty : metaProperties) {
            if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
                properties.put(metaProperty.getKey(), metaProperty.getValue());
            }
        }
    }
    handleEvent(eventName, properties, user);
}
Also used : HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) Property(org.wso2.carbon.identity.recovery.model.Property)

Example 5 with MetaProperty

use of org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty in project identity-governance by wso2-extensions.

the class ResendConfirmationManager method triggerNotification.

/**
 * Trigger notification to send userName recovery information.
 *
 * @param user                User
 * @param notificationChannel Notification channel (Eg: EMAIL or SMS)
 * @param templateName        Notification Template name
 * @param code                Secret key
 * @param eventName           Event name
 * @param metaProperties      Meta properties to be send with the notification.
 * @throws IdentityRecoveryException Error while triggering notification.
 */
private void triggerNotification(User user, String notificationChannel, String templateName, String code, String eventName, Property[] metaProperties) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getUserName());
    properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
    properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());
    if (StringUtils.isBlank(notificationChannel)) {
        notificationChannel = NotificationChannels.EMAIL_CHANNEL.getChannelType();
    }
    properties.put(IdentityEventConstants.EventProperty.NOTIFICATION_CHANNEL, notificationChannel);
    if (StringUtils.isNotBlank(code)) {
        properties.put(IdentityRecoveryConstants.CONFIRMATION_CODE, code);
    }
    if (metaProperties != null) {
        for (Property metaProperty : metaProperties) {
            if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
                properties.put(metaProperty.getKey(), metaProperty.getValue());
            }
        }
    }
    properties.put(IdentityRecoveryConstants.TEMPLATE_TYPE, templateName);
    Event identityMgtEvent = new Event(eventName, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_TRIGGER_NOTIFICATION, user.getUserName(), e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) Property(org.wso2.carbon.identity.recovery.model.Property)

Aggregations

HashMap (java.util.HashMap)5 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)4 Event (org.wso2.carbon.identity.event.event.Event)4 Property (org.wso2.carbon.identity.recovery.model.Property)4 JSONObject (org.json.JSONObject)3 MetaProperty (org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty)2 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 SubProperty (org.wso2.carbon.identity.application.common.model.SubProperty)2 Map (java.util.Map)1 MetaFederatedAuthenticator (org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticator)1 MetaOutboundConnector (org.wso2.carbon.identity.api.server.idp.v1.model.MetaOutboundConnector)1 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)1 IdentityEventClientException (org.wso2.carbon.identity.event.IdentityEventClientException)1