Java Code Examples for org.wso2.carbon.identity.core.util.IdentityTenantUtil#getTenantDomain()

The following examples show how to use org.wso2.carbon.identity.core.util.IdentityTenantUtil#getTenantDomain() . 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: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get all identity provider's Basic information along with additionally requested information depends on the
 * requiredAttributes for a given matching filter.
 *
 * @param tenantId           Tenant Id of the identity provider.
 * @param expressionNode     List of filter value for IdP search.
 * @param limit              Limit per page.
 * @param offset             Offset value.
 * @param sortOrder          Order of IdP ASC/DESC.
 * @param sortBy             The attribute need to sort.
 * @param requiredAttributes Required attributes which needs to be return.
 * @return Identity Provider's Basic Information array along with requested attribute information.
 * @throws IdentityProviderManagementServerException Error when getting list of Identity Providers.
 * @throws IdentityProviderManagementClientException Error when append the filer string.
 */
List<IdentityProvider> getIdPsSearch(int tenantId, List<ExpressionNode> expressionNode, int limit, int offset,
                                     String sortOrder, String sortBy, List<String> requiredAttributes)
        throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {

    FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
    appendFilterQuery(expressionNode, filterQueryBuilder);
    String sortedOrder = sortBy + " " + sortOrder;
    try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
         ResultSet resultSet = getIdpQueryResultSet(dbConnection, sortedOrder, tenantId, offset, limit,
                 filterQueryBuilder, requiredAttributes)) {
        return populateIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId);
    } catch (SQLException e) {
        String message = "Error occurred while retrieving Identity Provider for tenant: " +
                IdentityTenantUtil.getTenantDomain(tenantId);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage
                .ERROR_CODE_CONNECTING_DATABASE, message, e);
    }
}
 
Example 3
Source File: SessionDataStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private long getCleanupTimeout(String type, int tenantId) {
    if (isTempCache(type)) {
        return TimeUnit.MINUTES.toNanos(IdentityUtil.getTempDataCleanUpTimeout());
    } else if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
        String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);
        return TimeUnit.SECONDS.toNanos(IdPManagementUtil.getRememberMeTimeout(tenantDomain));
    } else {
        return TimeUnit.MINUTES.toNanos(IdentityUtil.getCleanUpTimeout());
    }
}
 
Example 4
Source File: UserSessionTerminationListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void terminateSessionsOfUser(String username, UserStoreManager userStoreManager) throws UserStoreException {

        String userStoreDomain = userStoreManager.getRealmConfiguration()
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
        String tenantDomain = IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId());

        try {
            IdentityMgtServiceComponent.getUserSessionManagementService()
                    .terminateSessionsOfUser(username, userStoreDomain, tenantDomain);
        } catch (UserSessionException e) {
            log.error("Failed to terminate active sessions of user: " + username, e);
        }
    }
 
Example 5
Source File: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> claims, String profileName,
        UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }

    if (log.isDebugEnabled()) {
        String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
        if (StringUtils.isBlank(userStoreDomain)) {
            userStoreDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
        }
        String tenantDomain = IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId());
        log.debug("doPreSetUserClaimValues method executed in ProfileMgtEventListener for user: " +
                getFullQualifiedUsername(userName, userStoreDomain, tenantDomain));
    }

    //The following black listed patterns contain possible invalid inputs for profile which could be used for a
    // stored XSS attack.
    String[] whiteListPatternKeys = {ALPHANUMERICS_ONLY, DIGITS_ONLY};
    String[] blackListPatternKeys = {WHITESPACE_EXISTS, URI_RESERVED_EXISTS, HTML_META_EXISTS, XML_META_EXISTS,
                                     REGEX_META_EXISTS, URL};

    if (!IdentityValidationUtil.isValid(profileName, whiteListPatternKeys, blackListPatternKeys)) {
        throw new UserStoreException("profile name contains invalid characters!");
    }
    return true;
}
 
Example 6
Source File: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Delete federated idp account associations from IDN_ASSOCIATED_ID table
 *
 * @param tenantAwareUsername
 * @param userStoreDomain
 * @param tenantId
 * @throws UserStoreException
 */
private void deleteFederatedIdpAccountAssociations(String tenantAwareUsername,
        String userStoreDomain,
        int tenantId) throws UserStoreException {

    // Run this code only if IDN_ASSOCIATED_ID table presents. We are doing this because of this feature can be used
    // by products which does not have the IDN tables.
    if (!ServiceHodler.isIDNTableExist()) {
        return;
    }

    String sql = "DELETE FROM IDN_ASSOCIATED_ID WHERE USER_NAME=? AND DOMAIN_NAME=? AND TENANT_ID=?";

    String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantId);
    // get tenant domain and user store domain appended username for logging
    String fullyQualifiedUsername = getFullQualifiedUsername(tenantAwareUsername, userStoreDomain, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug("Deleting federated IDP user account associations of user:" + fullyQualifiedUsername);
    }

    try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
        try (PreparedStatement prepStmt = connection.prepareStatement(sql)) {
            prepStmt.setString(1, tenantAwareUsername);
            prepStmt.setString(2, userStoreDomain);
            prepStmt.setInt(3, tenantId);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e1) {
            IdentityDatabaseUtil.rollbackTransaction(connection);
            throw new UserStoreException(String.format("Error when trying to delete the federated IDP user "
                    + "account associations of user:%s", fullyQualifiedUsername), e1);
        }
    } catch (SQLException e) {
        String msg = "Error when trying to delete the federated IDP user account associations of user:%s";
        throw new UserStoreException(String.format(msg, fullyQualifiedUsername), e);
    }
}