Java Code Examples for org.wso2.carbon.user.core.util.UserCoreUtil#addTenantDomainToEntry()

The following examples show how to use org.wso2.carbon.user.core.util.UserCoreUtil#addTenantDomainToEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdentityMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void sendEmail(String userName, int tenantId, String notification) {
    UserRecoveryDTO dto;
    String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);

    if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
        dto = new UserRecoveryDTO(userName);
    } else {
        UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
        userDTO.setTenantId(tenantId);
        dto = new UserRecoveryDTO(userDTO);
    }
    dto.setNotification(notification);
    dto.setNotificationType(EMAIL_NOTIFICATION_TYPE);
    try {
        IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
    } catch (IdentityException e) {
        //proceed with the rest of the flow even if the email is not sent
        log.error("Email notification sending failed for user:" + userName + " for " + notification);
    }
}
 
Example 2
Source File: WorkflowAuditLogger.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Trigger after adding a association
 *
 * @param associationName
 * @param workflowId
 * @param eventId
 * @param condition
 * @throws WorkflowException
 */
@Override
public void doPostAddAssociation(String associationName, String workflowId, String eventId, String condition)
        throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Association Name" + "\" : \"" + associationName+ "\",\""
            + "Workflow ID" + "\" : \"" + workflowId + "\",\""
            + "Event ID" + "\" : \"" + eventId + "\",\""
            + "Condition" + "\" : \"" + condition + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Add Association", auditData, AUDIT_SUCCESS));
}
 
Example 3
Source File: WorkflowExecutorAuditLogger.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Trigger after handling a callback
 *
 * @param uuid
 * @param status
 * @param additionalParams
 * @throws WorkflowException
 */
@Override
public void doPostHandleCallback(String uuid, String status, Map<String, Object> additionalParams) throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Request ID" + "\" : \"" + uuid
            + "\",\"" + "Callback Status" + "\" : \"" + status
            + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Callback for Workflow Request", auditData,
            AUDIT_SUCCESS));
}
 
Example 4
Source File: WorkflowAuditLogger.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Trigger after changing state of an association
 *
 * @param associationId
 * @param isEnable
 * @throws WorkflowException
 */
@Override
public void doPostChangeAssociationState(String associationId, boolean isEnable) throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Association ID" + "\" : \"" + associationId + "\",\""
            + "Resulting State" + "\" : \"" + isEnable + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Change Association State", auditData,
            AUDIT_SUCCESS));
}
 
Example 5
Source File: User.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {

    String username = null;
    if (StringUtils.isNotBlank(this.userName)) {
        username = this.userName;

        if (StringUtils.isNotBlank(this.userStoreDomain)) {
            username = UserCoreUtil.addDomainToName(username, userStoreDomain);
        }
        if (StringUtils.isNotBlank(this.tenantDomain)) {
            username = UserCoreUtil.addTenantDomainToEntry(username, tenantDomain);
        }
    }
    return username;
}
 
Example 6
Source File: User.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Returns full qualified username of the {@link User} object.
 * ie. We append the tenantDomain and userStoreDomain to the username.
 * <p>
 * Note that the PRIMARY domain will not be appended to username when building the full qualified username.
 * Therefore a full qualified name without the userStoreDomain indicates the user belongs to the PRIMARY
 * userStoreDomain.
 *
 * @return full qualified username
 */
public String toFullQualifiedUsername() {
    String username = null;
    if (StringUtils.isNotBlank(this.userName)) {
        username = this.userName;

        if (StringUtils.isNotBlank(this.tenantDomain)) {
            username = UserCoreUtil.addTenantDomainToEntry(username, tenantDomain);
        }

        if (StringUtils.isNotBlank(this.userStoreDomain)) {
            username = IdentityUtil.addDomainToName(username, userStoreDomain);
        }
    }
    return username;
}
 
Example 7
Source File: ApplicationMgtAuditLogger.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPostUpdateApplication(ServiceProvider serviceProvider, String tenantDomain, String userName)
        throws IdentityApplicationManagementException {

    int appId = -1;
    String name = "Undefined";
    if (serviceProvider != null) {
        appId = serviceProvider.getApplicationID();
        name = serviceProvider.getApplicationName();
    }

    // Append tenant domain to username.
    userName = UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain);

    audit.info(String.format(AUDIT_MESSAGE, userName, "update", appId, name, SUCCESS));
    return true;
}
 
Example 8
Source File: ApplicationMgtAuditLogger.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPostCreateApplication(ServiceProvider serviceProvider, String tenantDomain, String userName)
        throws IdentityApplicationManagementException {

    int appId = -1;
    String name = "Undefined";
    if (serviceProvider != null) {
        appId = serviceProvider.getApplicationID();
        name = serviceProvider.getApplicationName();
    }

    // Append tenant domain to username.
    userName = UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain);

    audit.info(String.format(AUDIT_MESSAGE, userName, "create", appId, name, SUCCESS));
    return true;
}
 
Example 9
Source File: AuthenticatedUser.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Sets authenticated subject identifier according to the useTenantDomainInLocalSubjectIdentifier and
 * useUserstoreDomainInLocalSubjectIdentifier properties.
 *
 * @param authenticatedSubjectIdentifier authenticated subject identifier
 * @param serviceProvider service provider
 */

public void setAuthenticatedSubjectIdentifier(String authenticatedSubjectIdentifier, ServiceProvider serviceProvider) {

    if (!isFederatedUser() && serviceProvider != null) {
        boolean useUserstoreDomainInLocalSubjectIdentifier = serviceProvider.getLocalAndOutBoundAuthenticationConfig()
                .isUseUserstoreDomainInLocalSubjectIdentifier();
        boolean useTenantDomainInLocalSubjectIdentifier = serviceProvider.getLocalAndOutBoundAuthenticationConfig()
                .isUseTenantDomainInLocalSubjectIdentifier();
        if (useUserstoreDomainInLocalSubjectIdentifier && StringUtils.isNotEmpty(userStoreDomain)) {
            authenticatedSubjectIdentifier = IdentityUtil.addDomainToName(userName, userStoreDomain);
        }
        if (useTenantDomainInLocalSubjectIdentifier && StringUtils.isNotEmpty(tenantDomain) &&
                StringUtils.isNotEmpty(authenticatedSubjectIdentifier)) {
            authenticatedSubjectIdentifier = UserCoreUtil.addTenantDomainToEntry(authenticatedSubjectIdentifier,
                    tenantDomain);
        }
    }
    this.authenticatedSubjectIdentifier = authenticatedSubjectIdentifier;
}
 
Example 10
Source File: User.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    String username = null;
    if (StringUtils.isNotBlank(this.userName)) {
        username = this.userName;
    }
    if (StringUtils.isNotBlank(this.userStoreDomain)) {
        username = UserCoreUtil.addDomainToName(username, userStoreDomain);
    }
    if (StringUtils.isNotBlank(this.tenantDomain)) {
        username = UserCoreUtil.addTenantDomainToEntry(username, tenantDomain);
    }
    return username;
}
 
Example 11
Source File: UserIdentityManagementAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Admin unlocks the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_UNLOCK);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
        }
        log.info("Account unlocked for: " + userName);
    } catch (UserStoreException|IdentityException e) {
        String message = "Error occurred while unlocking account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 12
Source File: UserIdentityManagementAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Admin unlocks the user account.
 *
 * @param userName
 * @throws IdentityMgtServiceException
 */
public void unlockUserAccount(String userName, String notificationType) throws IdentityMgtServiceException {
    try {
        UserStoreManager userStoreManager = getUserStore(userName);
        String userNameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
        UserIdentityManagementUtil.unlockUserAccount(userNameWithoutDomain, userStoreManager);
        int tenantID = userStoreManager.getTenantId();
        String tenantDomain = IdentityMgtServiceComponent.getRealmService().getTenantManager().getDomain(tenantID);
        boolean isNotificationSending = IdentityMgtConfig.getInstance().isNotificationSending();
        if (notificationType != null && isNotificationSending) {
            UserRecoveryDTO dto;
            if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
                dto = new UserRecoveryDTO(userName);
            } else {
                UserDTO userDTO = new UserDTO(UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain));
                userDTO.setTenantId(tenantID);
                dto = new UserRecoveryDTO(userDTO);
            }
            dto.setNotification(IdentityMgtConstants.Notification.ACCOUNT_UNLOCK);
            dto.setNotificationType(notificationType);
            IdentityMgtServiceComponent.getRecoveryProcessor().recoverWithNotification(dto);
        }
        log.info("Account unlocked for: " + userName);
    } catch (UserStoreException|IdentityException e) {
        String message = "Error occurred while unlocking account for: " + userName;
        log.error(message, e);
        throw new IdentityMgtServiceException(message, e);
    }
}
 
Example 13
Source File: JITProvisioningPostAuthenticationHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To get the user name with tenant domain.
 * @param userName Name of the user.
 * @param tenantDomain Relevant tenant domain.
 * @return tenant domain appeneded username
 */
private String getTenantDomainAppendedUserName(String userName, String tenantDomain) {

    // To handle the scenarios where email comes as username, but EnableEmailUserName is not set true in carbon.xml
    if (!userName.endsWith("@" + tenantDomain)) {
        userName = MultitenantUtils.getTenantAwareUsername(userName);

        if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
            userName = UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain);
        }
    }
    return userName;
}
 
Example 14
Source File: ListenerUtils.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To get the current user, who is doing the current task.
 *
 * @return current logged-in user
 */
public static String getUser() {

    String user = CarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isNotEmpty(user)) {
        user = UserCoreUtil
                .addTenantDomainToEntry(user, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    } else {
        user = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }
    return user;
}
 
Example 15
Source File: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String getFullQualifiedUsername(String tenantAwareUsername,
        String userStoreDomain,
        String tenantDomain) {

    String fullyQualifiedUsername = UserCoreUtil.addDomainToName(tenantAwareUsername, userStoreDomain);
    fullyQualifiedUsername = UserCoreUtil.addTenantDomainToEntry(fullyQualifiedUsername, tenantDomain);
    return fullyQualifiedUsername;
}
 
Example 16
Source File: WorkflowAuditLogger.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger after deleting the request
 *
 * @param workflowRequest
 * @throws WorkflowException
 */
@Override
public void doPostDeleteWorkflowRequest(WorkflowRequest workflowRequest) throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Request ID" + "\" : \"" + workflowRequest.getRequestId() + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Remove workflow request", auditData,
            AUDIT_SUCCESS));
}
 
Example 17
Source File: WorkflowAuditLogger.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger after delete the workflow
 *
 * @param workflow
 * @throws WorkflowException
 */
@Override
public void doPostDeleteWorkflow(Workflow workflow) throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Workflow ID" + "\" : \"" + workflow.getWorkflowId() + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Remove workflow", auditData, AUDIT_SUCCESS));
}
 
Example 18
Source File: AuthenticatedUser.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public String getUsernameAsSubjectIdentifier(boolean useUserstoreDomainInLocalSubjectIdentifier, boolean
        useTenantDomainInLocalSubjectIdentifier) {
    String userName = this.userName;
    if (useUserstoreDomainInLocalSubjectIdentifier && userStoreDomain != null) {
        userName = UserCoreUtil.addDomainToName(userName, userStoreDomain);
    }
    if (useTenantDomainInLocalSubjectIdentifier && tenantDomain != null) {
        userName = UserCoreUtil.addTenantDomainToEntry(userName, tenantDomain);
    }
    return userName;
}
 
Example 19
Source File: TokenValidationHandler.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
    * 
    * @param accessTokenDO
    * @return
    */
   private String getAuthzUser(AccessTokenDO accessTokenDO) {
User user = accessTokenDO.getAuthzUser();
String authzUser = UserCoreUtil.addDomainToName(user.getUserName(), user.getUserStoreDomain());
return UserCoreUtil.addTenantDomainToEntry(authzUser, user.getTenantDomain());
   }
 
Example 20
Source File: OAuthUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static void clearOAuthCache(String consumerKey, User authorizedUser, String scope) {

        String user = UserCoreUtil.addDomainToName(authorizedUser.getUserName(), authorizedUser.getUserStoreDomain());
        user = UserCoreUtil.addTenantDomainToEntry(user, authorizedUser.getTenantDomain());
        clearOAuthCache(consumerKey, user, scope);
    }