Java Code Examples for org.wso2.carbon.base.MultitenantConstants#INVALID_TENANT_ID

The following examples show how to use org.wso2.carbon.base.MultitenantConstants#INVALID_TENANT_ID . 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: IdentityUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Check the case sensitivity of the user store.
 *
 * @param userStoreDomain user store domain
 * @param tenantId        tenant id of the user store
 * @return
 */
public static boolean isUserStoreCaseSensitive(String userStoreDomain, int tenantId) {

    boolean isUsernameCaseSensitive = true;
    if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
        //this is to handle federated scenarios
        return true;
    }
    try {
        UserRealm tenantUserRealm = IdentityTenantUtil.getRealmService().getTenantUserRealm(tenantId);
        if (tenantUserRealm != null) {
            org.wso2.carbon.user.core.UserStoreManager userStoreManager = (org.wso2.carbon.user.core.UserStoreManager) tenantUserRealm
                    .getUserStoreManager();
            org.wso2.carbon.user.core.UserStoreManager userAvailableUserStoreManager = userStoreManager.getSecondaryUserStoreManager(userStoreDomain);
            return isUserStoreCaseSensitive(userAvailableUserStoreManager);
        }
    } catch (UserStoreException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while reading user store property CaseInsensitiveUsername. Considering as case " +
                    "sensitive.");
        }
    }
    return isUsernameCaseSensitive;
}
 
Example 2
Source File: IdentityUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Check the case sensitivity of the user store.
 *
 * @param userStoreDomain user store domain
 * @param tenantId        tenant id of the user store
 * @return
 */
public static boolean isUserStoreCaseSensitive(String userStoreDomain, int tenantId) {

    boolean isUsernameCaseSensitive = true;
    if (tenantId == MultitenantConstants.INVALID_TENANT_ID){
        //this is to handle federated scenarios
        return true;
    }
    try {
        org.wso2.carbon.user.core.UserStoreManager userStoreManager = (org.wso2.carbon.user.core
                .UserStoreManager) IdentityTenantUtil.getRealmService()
                .getTenantUserRealm(tenantId).getUserStoreManager();
        org.wso2.carbon.user.core.UserStoreManager userAvailableUserStoreManager = userStoreManager
                .getSecondaryUserStoreManager(userStoreDomain);
        return isUserStoreCaseSensitive(userAvailableUserStoreManager);
    } catch (UserStoreException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while reading user store property CaseInsensitiveUsername. Considering as case " +
                    "sensitive.");
        }
    }
    return isUsernameCaseSensitive;
}
 
Example 3
Source File: JWTTokenGenerator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private String getMultiAttributeSeparator(String authenticatedUser, int tenantId) {
    String claimSeparator = null;
    String userDomain = IdentityUtil.extractDomainFromName(authenticatedUser);

    try {
        RealmConfiguration realmConfiguration = null;
        RealmService realmService = OAuthComponentServiceHolder.getRealmService();

        if (realmService != null && tenantId != MultitenantConstants.INVALID_TENANT_ID) {
            UserStoreManager userStoreManager = (UserStoreManager) realmService.getTenantUserRealm(tenantId)
                    .getUserStoreManager();
            realmConfiguration = userStoreManager.getSecondaryUserStoreManager(userDomain).getRealmConfiguration();
        }

        if (realmConfiguration != null) {
            claimSeparator = realmConfiguration.getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
            if (claimSeparator != null && !claimSeparator.trim().isEmpty()) {
                return claimSeparator;
            }
        }
    } catch (UserStoreException e) {
        log.error("Error occurred while getting the realm configuration, User store properties might not be " +
                  "returned", e);
    }
    return null;
}
 
Example 4
Source File: AbstractJWTGenerator.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
protected String getMultiAttributeSeparator(int tenantId) {
    try {
        RealmConfiguration realmConfiguration = null;
        RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();

        if (realmService != null && tenantId != MultitenantConstants.INVALID_TENANT_ID) {
            UserStoreManager userStoreManager = (UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();


            realmConfiguration = userStoreManager.getRealmConfiguration();
        }

        if (realmConfiguration != null) {
            String claimSeparator = realmConfiguration.getUserStoreProperty(APIConstants.MULTI_ATTRIBUTE_SEPARATOR);
            if (claimSeparator != null && !claimSeparator.trim().isEmpty()) {
                return claimSeparator;
            }
        }
    } catch (UserStoreException e) {
        log.error("Error occurred while getting the realm configuration, User store properties might not be " +
                  "returned", e);
    }
    return null;
}
 
Example 5
Source File: IdentityContextCache.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public void addToCache(String key, IdentityMessageContext context) {
    super.addToCache(key, context);
    if (enableRequestScopeCache) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = context.getRequest().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }
        SessionDataStore.getInstance().storeSessionData(key, INBOUND_CONTEXT_CACHE_NAME, context, tenantId);
    }
}
 
Example 6
Source File: UserSessionManagementServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void validate(String username, String userStoreDomain, String tenantDomain) throws UserSessionException {

        if (StringUtils.isBlank(username) || StringUtils.isBlank(userStoreDomain) || StringUtils.isBlank(tenantDomain)) {
            throw new UserSessionException("Username, userstore domain or tenant domain cannot be empty");
        }

        int tenantId = getTenantId(tenantDomain);
        if (MultitenantConstants.INVALID_TENANT_ID == tenantId) {
            throw new UserSessionException("Invalid tenant domain: " + tenantDomain + " provided.");
        }
    }
 
Example 7
Source File: AuthenticationResultCache.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationResultCacheKey key, AuthenticationResultCacheEntry entry) {
    super.addToCache(key, entry);
    if (isTemporarySessionDataPersistEnabled) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        if (entry.getResult() != null && entry.getResult().getSubject() != null) {
            String tenantDomain = entry.getResult().getSubject().getTenantDomain();
            if (tenantDomain != null) {
                tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
            }
        }
        SessionDataStore.getInstance().storeSessionData(key.getResultId(), CACHE_NAME, entry, tenantId);
    }
}
 
Example 8
Source File: AuthenticationRequestCache.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationRequestCacheKey key, AuthenticationRequestCacheEntry entry) {
    super.addToCache(key,entry);
    if (isTemporarySessionDataPersistEnabled) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = entry.getAuthenticationRequest().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }
        SessionDataStore.getInstance().storeSessionData(key.getResultId(), AUTHENTICATION_REQUEST_CACHE_NAME,
                entry, tenantId);
    }
}
 
Example 9
Source File: AuthenticationContextCache.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {
    super.addToCache(key, entry);
    if (isTemporarySessionDataPersistEnabled) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = entry.getContext().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }

        if (entry.getContext() != null && entry.getContext().getProperties() != null) {
            Iterator it = entry.getContext().getProperties().entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> item = (Map.Entry<String, Object>) it.next();
                if (!(item.getValue() instanceof Serializable)) {
                    it.remove();
                }
            }
            if (log.isDebugEnabled()) {
                String message = "[ Context Id : " + key.getContextId() +
                        ", Cache type : " + AUTHENTICATION_CONTEXT_CACHE_NAME +
                        ", Operation : STORE ]";
                log.debug("Authentication context is stored with details " + message);
            }
            SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
                    entry, tenantId);
        }
    }
}
 
Example 10
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 11
Source File: InboundAuthenticationContextCache.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public void addToCache(InboundAuthenticationContextCacheKey key, InboundAuthenticationContextCacheEntry entry) {
    super.addToCache(key, entry);
    if (enableRequestScopeCache) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = entry.getInboundAuthenticationContext().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }
        SessionDataStore.getInstance().storeSessionData(key.getResultId(),
                INBOUND_AUTHENTICATION_CONTEXT_CACHE_NAME, entry, tenantId);
    }
}
 
Example 12
Source File: AuthenticationResultCache.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationResultCacheKey key, AuthenticationResultCacheEntry entry) {
    super.addToCache(key, entry);
    if (isTemporarySessionDataPersistEnabled) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        if (entry.getResult() != null && entry.getResult().getSubject() != null) {
            String tenantDomain = entry.getResult().getSubject().getTenantDomain();
            if (tenantDomain != null) {
                tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
            }
        }
        SessionDataStore.getInstance().storeSessionData(key.getResultId(), CACHE_NAME, entry, tenantId);
    }
}
 
Example 13
Source File: AuthenticationRequestCache.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationRequestCacheKey key, AuthenticationRequestCacheEntry entry){
    super.addToCache(key,entry);
    if(isTemporarySessionDataPersistEnabled){
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = entry.getAuthenticationRequest().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }
        SessionDataStore.getInstance().storeSessionData(key.getResultId(), AUTHENTICATION_REQUEST_CACHE_NAME,
                entry, tenantId);
    }
}
 
Example 14
Source File: AuthenticationContextCache.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {
    super.addToCache(key, entry);
    if (isTemporarySessionDataPersistEnabled) {
        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
        String tenantDomain = entry.getContext().getTenantDomain();
        if (tenantDomain != null) {
            tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        }
        SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
                entry, tenantId);
    }
}