Search in sources :

Example 1 with REQUEST_PARAM_SP

use of org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.REQUEST_PARAM_SP in project carbon-identity-framework by wso2.

the class FrameworkUtils method sendToRetryPage.

/**
 * Send user to retry page during an authentication flow failure.
 *
 * @param request       Http servlet request.
 * @param response      Http servlet response.
 * @param context       Authentication Context.
 * @param status        Failure status.
 * @param statusMsg     Failure status message.
 * @throws IOException
 */
public static void sendToRetryPage(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context, String status, String statusMsg) throws IOException {
    try {
        URIBuilder uriBuilder = new URIBuilder(ConfigurationFacade.getInstance().getAuthenticationEndpointRetryURL());
        if (status != null && statusMsg != null) {
            uriBuilder.addParameter("status", status);
            uriBuilder.addParameter("statusMsg", statusMsg);
        }
        request.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.INCOMPLETE);
        if (context != null) {
            if (IdentityTenantUtil.isTenantedSessionsEnabled()) {
                uriBuilder.addParameter(USER_TENANT_DOMAIN_HINT, context.getUserTenantDomain());
            }
            uriBuilder.addParameter(REQUEST_PARAM_SP, context.getServiceProviderName());
            if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
                uriBuilder.addParameter(TENANT_DOMAIN, context.getTenantDomain());
            }
            response.sendRedirect(uriBuilder.build().toString());
        } else {
            response.sendRedirect(getRedirectURL(uriBuilder.build().toString(), request));
        }
    } catch (URISyntaxException e) {
        log.error("Error building redirect url for failure", e);
        FrameworkUtils.sendToRetryPage(request, response);
    } finally {
        List<String> cookiesToInvalidateConfig = IdentityUtil.getCookiesToInvalidateConfigurationHolder();
        if (ArrayUtils.isNotEmpty(request.getCookies())) {
            Arrays.stream(request.getCookies()).filter(cookie -> cookiesToInvalidateConfig.stream().anyMatch(cookieToInvalidate -> cookie.getName().contains(cookieToInvalidate))).forEach(cookie -> removeCookie(request, response, cookie.getName()));
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) ClaimManager(org.wso2.carbon.user.core.claim.ClaimManager) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) UserRealm(org.wso2.carbon.user.core.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdentityCookieConfig(org.wso2.carbon.identity.core.model.IdentityCookieConfig) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult) DefaultAuthenticationRequestHandler(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultAuthenticationRequestHandler) ResultSet(java.sql.ResultSet) Map(java.util.Map) ServiceURLBuilder(org.wso2.carbon.identity.core.ServiceURLBuilder) ScriptException(javax.script.ScriptException) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) URIBuilder(org.apache.http.client.utils.URIBuilder) AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) FederatedAssociationManager(org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager) UserSessionException(org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException) Set(java.util.Set) UserCoreConstants(org.wso2.carbon.user.core.UserCoreConstants) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) SessionContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey) SessionContextCache(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCache) UserSessionStore(org.wso2.carbon.identity.application.authentication.framework.store.UserSessionStore) MultitenantUtils(org.wso2.carbon.utils.multitenancy.MultitenantUtils) APPLICATION_DOMAIN(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.InternalRoleDomains.APPLICATION_DOMAIN) ResolvedUserResult(org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult) AuthenticationResultCache(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCache) UserCoreClaimConstants(org.wso2.carbon.user.core.constants.UserCoreClaimConstants) LogFactory(org.apache.commons.logging.LogFactory) CarbonConstants(org.wso2.carbon.CarbonConstants) RequestCoordinator(org.wso2.carbon.identity.application.authentication.framework.handler.request.RequestCoordinator) IdentityException(org.wso2.carbon.identity.base.IdentityException) REQUEST_PARAM_SP(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.REQUEST_PARAM_SP) USER_TENANT_DOMAIN_HINT(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.RequestParams.USER_TENANT_DOMAIN_HINT) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) GraphBasedStepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.GraphBasedStepHandler) InvalidCredentialsException(org.wso2.carbon.identity.application.authentication.framework.exception.InvalidCredentialsException) DatabaseMetaData(java.sql.DatabaseMetaData) CONSOLE_APP_PATH(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.Application.CONSOLE_APP_PATH) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.application.common.model.Property) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) HttpServletRequest(javax.servlet.http.HttpServletRequest) IdentityTenantUtil.isLegacySaaSAuthenticationEnabled(org.wso2.carbon.identity.core.util.IdentityTenantUtil.isLegacySaaSAuthenticationEnabled) AuthenticationRequestCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheKey) UserCoreUtil(org.wso2.carbon.user.core.util.UserCoreUtil) LogoutRequestHandler(org.wso2.carbon.identity.application.authentication.framework.handler.request.LogoutRequestHandler) DefaultRequestCoordinator(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) AuthenticationFrameworkWrapper(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationFrameworkWrapper) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) IOException(java.io.IOException) SameSiteCookie(org.wso2.carbon.core.SameSiteCookie) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) CallBackHandlerFactory(org.wso2.carbon.identity.application.authentication.framework.handler.request.CallBackHandlerFactory) SessionContextCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry) FileBasedConfigurationBuilder(org.wso2.carbon.identity.application.authentication.framework.config.builder.FileBasedConfigurationBuilder) TreeMap(java.util.TreeMap) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) UserStorePreferenceOrderSupplier(org.wso2.carbon.user.core.config.UserStorePreferenceOrderSupplier) MY_ACCOUNT_APP_PATH(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.Application.MY_ACCOUNT_APP_PATH) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) Connection(java.sql.Connection) IdentityDatabaseUtil(org.wso2.carbon.identity.core.util.IdentityDatabaseUtil) DefaultRequestPathBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.DefaultRequestPathBasedSequenceHandler) AuthenticationError(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationError) URISyntaxException(java.net.URISyntaxException) AuthenticationRequestHandler(org.wso2.carbon.identity.application.authentication.framework.handler.request.AuthenticationRequestHandler) AuthenticationRequestCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry) JSONObject(org.json.JSONObject) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) AuthenticatedIdPData(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedIdPData) URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) AnonymousSessionUtil(org.wso2.carbon.core.util.AnonymousSessionUtil) HomeRealmDiscoverer(org.wso2.carbon.identity.application.authentication.framework.handler.hrd.HomeRealmDiscoverer) ThreadContext(org.apache.logging.log4j.ThreadContext) FrameworkServiceComponent(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent) AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationContextCacheKey) StepBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler) AuthenticationErrorCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationErrorCacheKey) AuthenticationErrorCache(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationErrorCache) DefaultHomeRealmDiscoverer(org.wso2.carbon.identity.application.authentication.framework.handler.hrd.impl.DefaultHomeRealmDiscoverer) UUID(java.util.UUID) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AuthenticationRequestCache(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCache) IdentityEventService(org.wso2.carbon.identity.event.services.IdentityEventService) GraphBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler) CONTEXT_PROP_INVALID_EMAIL_USERNAME(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.CONTEXT_PROP_INVALID_EMAIL_USERNAME) ProvisioningHandler(org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.ProvisioningHandler) StepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler) ApplicationConstants(org.wso2.carbon.identity.application.mgt.ApplicationConstants) Base64(java.util.Base64) List(java.util.List) CarbonException(org.wso2.carbon.CarbonException) AuthenticationDataPublisher(org.wso2.carbon.identity.application.authentication.framework.AuthenticationDataPublisher) USER_SESSION_MAPPING_ENABLED(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.Config.USER_SESSION_MAPPING_ENABLED) Entry(java.util.Map.Entry) IdentityEventConstants(org.wso2.carbon.identity.event.IdentityEventConstants) NameValuePair(org.apache.http.NameValuePair) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SessionContext(org.wso2.carbon.identity.application.authentication.framework.context.SessionContext) CookieBuilder(org.wso2.carbon.identity.core.model.CookieBuilder) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) AuthenticationRequest(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationRequest) Event(org.wso2.carbon.identity.event.event.Event) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) Claim(org.wso2.carbon.identity.application.common.model.Claim) HashSet(java.util.HashSet) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) CollectionUtils(org.apache.commons.collections.CollectionUtils) WORKFLOW_DOMAIN(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.InternalRoleDomains.WORKFLOW_DOMAIN) RequestPathBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.RequestPathBasedSequenceHandler) AuthenticationErrorCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationErrorCacheEntry) Cookie(javax.servlet.http.Cookie) DefaultLogoutRequestHandler(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultLogoutRequestHandler) AuthenticationContextCache(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationContextCache) DefaultProvisioningHandler(org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.impl.DefaultProvisioningHandler) Iterator(java.util.Iterator) MapUtils(org.apache.commons.collections.MapUtils) IdPManagementUtil(org.wso2.carbon.idp.mgt.util.IdPManagementUtil) DefaultClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.impl.DefaultClaimHandler) IdpManager(org.wso2.carbon.idp.mgt.IdpManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) ClaimMetadataHandler(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataHandler) AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) TimeUnit(java.util.concurrent.TimeUnit) ClaimManagementException(org.wso2.carbon.claim.mgt.ClaimManagementException) SerializableJsFunction(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction) URLEncoder(java.net.URLEncoder) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityCoreConstants(org.wso2.carbon.identity.core.util.IdentityCoreConstants) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) ConfigurationFacade(org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) StringJoiner(java.util.StringJoiner) CarbonContext(org.wso2.carbon.context.CarbonContext) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) ScriptEngine(javax.script.ScriptEngine) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) Log(org.apache.commons.logging.Log) AuthenticationContextCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationContextCacheEntry) IdentityUtil.getLocalGroupsClaimURI(org.wso2.carbon.identity.core.util.IdentityUtil.getLocalGroupsClaimURI) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) ArrayUtils(org.apache.commons.lang.ArrayUtils) AuthenticationResultCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheKey) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 URLEncoder (java.net.URLEncoder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Base64 (java.util.Base64)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1