Search in sources :

Example 21 with CustomScriptConfiguration

use of io.jans.model.custom.script.conf.CustomScriptConfiguration in project jans by JanssenProject.

the class ExternalUpdateTokenService method getRefreshTokenLifetimeInSeconds.

public int getRefreshTokenLifetimeInSeconds(ExternalUpdateTokenContext context) {
    List<CustomScriptConfiguration> scripts = getScripts(context);
    if (scripts.isEmpty()) {
        return 0;
    }
    log.trace("Executing {} 'getRefreshTokenLifetimeInSeconds' scripts.", scripts.size());
    for (CustomScriptConfiguration script : scripts) {
        final int lifetime = getRefreshTokenLifetimeInSeconds(script, context);
        if (lifetime > 0) {
            log.trace("Finished 'getRefreshTokenLifetimeInSeconds' methods, lifetime: {}", lifetime);
            return lifetime;
        }
    }
    return 0;
}
Also used : CustomScriptConfiguration(io.jans.model.custom.script.conf.CustomScriptConfiguration)

Example 22 with CustomScriptConfiguration

use of io.jans.model.custom.script.conf.CustomScriptConfiguration in project jans by JanssenProject.

the class ExternalUpdateTokenService method getIdTokenLifetimeInSeconds.

public int getIdTokenLifetimeInSeconds(ExternalUpdateTokenContext context) {
    List<CustomScriptConfiguration> scripts = getScripts(context);
    if (scripts.isEmpty()) {
        return 0;
    }
    log.trace("Executing {} 'getIdTokenLifetimeInSeconds' scripts.", scripts.size());
    for (CustomScriptConfiguration script : scripts) {
        final int lifetime = getIdTokenLifetimeInSeconds(script, context);
        if (lifetime > 0) {
            log.trace("Finished 'getIdTokenLifetimeInSeconds' methods, lifetime: {}", lifetime);
            return lifetime;
        }
    }
    return 0;
}
Also used : CustomScriptConfiguration(io.jans.model.custom.script.conf.CustomScriptConfiguration)

Example 23 with CustomScriptConfiguration

use of io.jans.model.custom.script.conf.CustomScriptConfiguration in project jans by JanssenProject.

the class UmaGatherer method gather.

public boolean gather() {
    try {
        final HttpServletRequest httpRequest = (HttpServletRequest) externalContext.getRequest();
        final HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
        final SessionId session = umaSessionService.getSession(httpRequest, httpResponse);
        CustomScriptConfiguration script = getScript(session);
        UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, umaSessionService, umaPermissionService, umaPctService, pageClaims, appConfiguration);
        int step = umaSessionService.getStep(session);
        if (!umaSessionService.isPassedPreviousSteps(session, step)) {
            log.error("There are claims-gathering steps not marked as passed. scriptName: '{}', step: '{}'", script.getName(), step);
            return false;
        }
        boolean gatheredResult = external.gather(script, step, context);
        log.debug("Claims-gathering result for script '{}', step: '{}', gatheredResult: '{}'", script.getName(), step, gatheredResult);
        int overridenNextStep = external.getNextStep(script, step, context);
        if (!gatheredResult && overridenNextStep == -1) {
            return false;
        }
        if (overridenNextStep != -1) {
            umaSessionService.resetToStep(session, overridenNextStep, step);
            step = overridenNextStep;
        }
        int stepsCount = external.getStepsCount(script, context);
        if (step < stepsCount || overridenNextStep != -1) {
            int nextStep;
            if (overridenNextStep != -1) {
                nextStep = overridenNextStep;
            } else {
                nextStep = step + 1;
                umaSessionService.markStep(session, step, true);
            }
            umaSessionService.setStep(nextStep, session);
            context.persist();
            String page = external.getPageForStep(script, nextStep, context);
            log.trace("Redirecting to page: '{}'", page);
            facesService.redirect(page);
            return true;
        }
        if (step == stepsCount) {
            context.persist();
            onSuccess(session, context);
            return true;
        }
    } catch (Exception e) {
        log.error("Exception during gather() method call.", e);
    }
    log.error("Failed to perform gather() method successfully.");
    return false;
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) UmaGatherContext(io.jans.as.server.uma.authorization.UmaGatherContext) SessionId(io.jans.as.server.model.common.SessionId) CustomScriptConfiguration(io.jans.model.custom.script.conf.CustomScriptConfiguration)

Example 24 with CustomScriptConfiguration

use of io.jans.model.custom.script.conf.CustomScriptConfiguration in project jans by JanssenProject.

the class UmaGatheringWS method gatherClaims.

public Response gatherClaims(String clientId, String ticket, String claimRedirectUri, String state, Boolean authenticationRedirect, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    try {
        if (log.isTraceEnabled()) {
            log.trace("gatherClaims client_id: {}, ticket: {}, claims_redirect_uri: {}, state: {}, authenticationRedirect: {}, queryString: {}", escapeLog(clientId), escapeLog(ticket), escapeLog(claimRedirectUri), escapeLog(state), escapeLog(authenticationRedirect), httpRequest.getQueryString());
        }
        errorResponseFactory.validateComponentEnabled(ComponentType.UMA);
        SessionId session = sessionService.getSession(httpRequest, httpResponse);
        if (authenticationRedirect != null && authenticationRedirect) {
            // restore parameters from session
            log.debug("Authentication redirect, restoring parameters from session ...");
            if (session == null) {
                log.error("Session is null however authentication=true. Wrong workflow! Please correct custom Glaims-Gathering Script.");
                throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_SESSION, "Session is null however authentication=true. Wrong workflow! Please correct custom Glaims-Gathering Script.");
            }
            clientId = sessionService.getClientId(session);
            ticket = sessionService.getTicket(session);
            claimRedirectUri = sessionService.getClaimsRedirectUri(session);
            state = sessionService.getState(session);
            if (log.isDebugEnabled()) {
                log.debug("Restored parameters from session, clientId: {}, ticket: {}, claims_redirect_uri: {}, state: {}", escapeLog(clientId), escapeLog(ticket), escapeLog(claimRedirectUri), escapeLog(state));
            }
        }
        validationService.validateClientAndClaimsRedirectUri(clientId, claimRedirectUri, state);
        List<UmaPermission> permissions = validationService.validateTicketWithRedirect(ticket, claimRedirectUri, state);
        String[] scriptNames = validationService.validatesGatheringScriptNames(getScriptNames(permissions), claimRedirectUri, state);
        CustomScriptConfiguration script = external.determineScript(scriptNames);
        if (script == null) {
            if (log.isErrorEnabled()) {
                log.error("Failed to determine claims-gathering script for names: {}", Arrays.toString(scriptNames));
            }
            throw new UmaWebException(claimRedirectUri, errorResponseFactory, INVALID_CLAIMS_GATHERING_SCRIPT_NAME, state);
        }
        sessionService.configure(session, script.getName(), permissions, clientId, claimRedirectUri, state);
        UmaGatherContext context = new UmaGatherContext(script.getConfigurationAttributes(), httpRequest, session, sessionService, permissionService, pctService, new HashMap<>(), appConfiguration);
        int step = sessionService.getStep(session);
        int stepsCount = external.getStepsCount(script, context);
        if (step < stepsCount) {
            String page = external.getPageForStep(script, step, context);
            context.persist();
            String baseEndpoint = StringUtils.removeEnd(appConfiguration.getBaseEndpoint(), "/");
            baseEndpoint = StringUtils.removeEnd(baseEndpoint, "restv1");
            baseEndpoint = StringUtils.removeEnd(baseEndpoint, "/");
            String fullUri = baseEndpoint + page;
            fullUri = StringUtils.removeEnd(fullUri, ".xhtml") + ".htm";
            log.trace("Redirecting to page: '{}', fullUri: {}", page, fullUri);
            return Response.status(FOUND).location(new URI(fullUri)).build();
        } else {
            log.error("Step '{}' is more or equal to stepCount: '{}'", step, stepsCount);
        }
    } catch (Exception ex) {
        log.error("Exception happened", ex);
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
    }
    log.error("Failed to handle call to UMA Claims Gathering Endpoint.");
    throw errorResponseFactory.createWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, UmaErrorResponseType.SERVER_ERROR, "Failed to handle call to UMA Claims Gathering Endpoint.");
}
Also used : UmaWebException(io.jans.as.server.uma.authorization.UmaWebException) WebApplicationException(jakarta.ws.rs.WebApplicationException) URI(java.net.URI) UmaWebException(io.jans.as.server.uma.authorization.UmaWebException) WebApplicationException(jakarta.ws.rs.WebApplicationException) UmaPermission(io.jans.as.model.uma.persistence.UmaPermission) UmaGatherContext(io.jans.as.server.uma.authorization.UmaGatherContext) SessionId(io.jans.as.server.model.common.SessionId) CustomScriptConfiguration(io.jans.model.custom.script.conf.CustomScriptConfiguration)

Example 25 with CustomScriptConfiguration

use of io.jans.model.custom.script.conf.CustomScriptConfiguration in project jans by JanssenProject.

the class ExternalAuthenticationServiceTest method determineCustomScriptConfiguration_withAuthModesEmptyIfAcrsNull_false.

@Test
public void determineCustomScriptConfiguration_withAuthModesEmptyIfAcrsNull_false() {
    final List<String> acrValuesList = new ArrayList<>();
    externalAuthenticationService.setCustomScriptConfigurationsMapByUsageType(createCustomScriptConfigurationsMapByUsageTypeWithInteractive());
    Mockito.doReturn(acrValuesList).when(externalAuthenticationService).getAuthModesByAcrValues(anyList());
    Mockito.doReturn(false).when(appConfiguration).getUseHighestLevelScriptIfAcrScriptNotFound();
    final CustomScriptConfiguration customScriptConfiguration = externalAuthenticationService.determineCustomScriptConfiguration(AuthenticationScriptUsageType.INTERACTIVE, acrValuesList);
    assertNull(customScriptConfiguration);
}
Also used : CustomScriptConfiguration(io.jans.model.custom.script.conf.CustomScriptConfiguration) Test(org.testng.annotations.Test)

Aggregations

CustomScriptConfiguration (io.jans.model.custom.script.conf.CustomScriptConfiguration)58 SessionId (io.jans.as.server.model.common.SessionId)8 Test (org.testng.annotations.Test)8 WebApplicationException (jakarta.ws.rs.WebApplicationException)7 CustomScript (io.jans.model.custom.script.model.CustomScript)6 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)5 ArrayList (java.util.ArrayList)5 AuthenticationScriptUsageType (io.jans.model.AuthenticationScriptUsageType)4 Client (io.jans.as.common.model.registration.Client)3 ConsentGatheringContext (io.jans.as.server.service.external.context.ConsentGatheringContext)3 UmaGatherContext (io.jans.as.server.uma.authorization.UmaGatherContext)3 SimpleCustomProperty (io.jans.model.SimpleCustomProperty)3 AuthenticationCustomScript (io.jans.model.custom.script.model.auth.AuthenticationCustomScript)3 ClientRegistrationType (io.jans.model.custom.script.type.client.ClientRegistrationType)3 User (io.jans.as.common.model.common.User)2 Scope (io.jans.as.persistence.model.Scope)2 CustomScriptType (io.jans.model.custom.script.CustomScriptType)2 BaseExternalType (io.jans.model.custom.script.type.BaseExternalType)2 DiscoveryType (io.jans.model.custom.script.type.discovery.DiscoveryType)2