Java Code Examples for org.wso2.carbon.identity.oauth2.util.OAuth2Util#clearClientTenantId()

The following examples show how to use org.wso2.carbon.identity.oauth2.util.OAuth2Util#clearClientTenantId() . 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: EndpointUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the login page URL.
 *
 * @param checkAuthentication
 * @param forceAuthenticate
 * @param scopes
 * @return
 */
public static String getLoginPageURL(String clientId, String sessionDataKey,
                                     boolean forceAuthenticate, boolean checkAuthentication, Set<String> scopes)
        throws IdentityOAuth2Exception {

    try {
        SessionDataCacheEntry entry = SessionDataCache.getInstance()
                .getValueFromCache(new SessionDataCacheKey(sessionDataKey));

        return getLoginPageURL(clientId, sessionDataKey, forceAuthenticate,
                checkAuthentication, scopes, entry.getParamMap());
    } finally {
        OAuth2Util.clearClientTenantId();
    }
}
 
Example 2
Source File: EndpointUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the login page URL.
 *
 * @param clientId
 * @param sessionDataKey
 * @param reqParams
 * @param forceAuthenticate
 * @param checkAuthentication
 * @param scopes
 * @return
 * @throws UnsupportedEncodingException
 */
public static String getLoginPageURL(String clientId, String sessionDataKey,
                                     boolean forceAuthenticate, boolean checkAuthentication, Set<String> scopes,
                                     Map<String, String[]> reqParams) throws IdentityOAuth2Exception {

    try {

        String type = "oauth2";

        if (scopes != null && scopes.contains("openid")) {
            type = "oidc";
        }
        String commonAuthURL = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, false, true);
        String selfPath = "/oauth2/authorize";
        AuthenticationRequest authenticationRequest = new AuthenticationRequest();

        int tenantId = OAuth2Util.getClientTenatId();

        //Build the authentication request context.
        authenticationRequest.setCommonAuthCallerPath(selfPath);
        authenticationRequest.setForceAuth(forceAuthenticate);
        authenticationRequest.setPassiveAuth(checkAuthentication);
        authenticationRequest.setRelyingParty(clientId);
        authenticationRequest.setTenantDomain(OAuth2Util.getTenantDomain(tenantId));
        authenticationRequest.setRequestQueryParams(reqParams);

        //Build an AuthenticationRequestCacheEntry which wraps AuthenticationRequestContext
        AuthenticationRequestCacheEntry authRequest = new AuthenticationRequestCacheEntry
                (authenticationRequest);
        FrameworkUtils.addAuthenticationRequestToCache(sessionDataKey, authRequest);
        // Build new query param with only type and session data key
        StringBuilder queryStringBuilder = new StringBuilder();
        queryStringBuilder.append(commonAuthURL).
                append("?").
                append(FrameworkConstants.SESSION_DATA_KEY).
                append("=").
                append(sessionDataKey).
                append("&").
                append(FrameworkConstants.RequestParams.TYPE).
                append("=").
                append(type);

        return queryStringBuilder.toString();
    } finally {
        OAuth2Util.clearClientTenantId();
    }
}