Java源码示例:org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext

示例1
@Test
public void testPostAuthenticationHandlers() throws Exception {

    Cookie[] cookies = new Cookie[1];
    HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
    HttpServletResponse response = PowerMockito.mock(HttpServletResponse.class);
    AuthenticationContext context = prepareContextForPostAuthnTests();
    authenticationRequestHandler.handle(request, response, context);
    assertNull(context.getParameter(FrameworkConstants.POST_AUTHENTICATION_EXTENSION_COMPLETED));
    String pastrCookie = context.getParameter(FrameworkConstants.PASTR_COOKIE).toString();
    cookies[0] = new Cookie(FrameworkConstants.PASTR_COOKIE + "-" + context.getContextIdentifier(),
            pastrCookie);
    when(request.getCookies()).thenReturn(cookies);
    when(FrameworkUtils.getCookie(any(HttpServletRequest.class), anyString())).thenReturn
            (cookies[0]);
    authenticationRequestHandler.handle(request, response, context);
    assertTrue(Boolean.parseBoolean(context.getProperty(
            FrameworkConstants.POST_AUTHENTICATION_EXTENSION_COMPLETED).toString()));
}
 
示例2
/**
 * Set federated subject's SP Subject Claim URI as a property
 */
private void setSubjectClaimForLocalClaims(String tenantAwareUserId,
                                           UserStoreManager userStore,
                                           Map<String, String> attributesMap,
                                           String spStandardDialect,
                                           AuthenticationContext context) {

    String subjectURI = context.getSequenceConfig().getApplicationConfig().getSubjectClaimUri();
    if (subjectURI != null && !subjectURI.isEmpty()) {
        if (spStandardDialect != null) {
            setSubjectClaim(tenantAwareUserId, userStore, attributesMap, spStandardDialect, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst unfiltered local claims");
            }
        } else {
            setSubjectClaim(tenantAwareUserId, userStore, attributesMap, null, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst service provider mapped " +
                         "unfiltered local claims");
            }
        }
    }
}
 
示例3
/**
 * To add the missing claims.
 *
 * @param uriBuilder Relevant URI builder.
 * @param context    Authentication context.
 */
private void addMissingClaims(URIBuilder uriBuilder, AuthenticationContext context) {

    String[] missingClaims = FrameworkUtils.getMissingClaims(context);
    if (StringUtils.isNotEmpty(missingClaims[1])) {
        if (log.isDebugEnabled()) {
            String username = context.getSequenceConfig().getAuthenticatedUser()
                    .getAuthenticatedSubjectIdentifier();
            String idPName = context.getExternalIdP().getIdPName();
            log.debug("Mandatory claims for SP, " + missingClaims[1] + " is missing for the user : " + username
                    + " from the IDP " + idPName);
        }
        uriBuilder.addParameter(FrameworkConstants.MISSING_CLAIMS, missingClaims[1]);
        uriBuilder.addParameter(FrameworkConstants.MISSING_CLAIMS_DISPLAY_NAME, missingClaims[0]);
    }
}
 
示例4
private void setupAuthContextWithStepData(AuthenticationContext context, AuthenticatedUser authenticatedUser) {

        SequenceConfig sequenceConfig = new SequenceConfig();
        Map<Integer, StepConfig> stepConfigMap = new HashMap<>();
        StepConfig stepConfig = new StepConfig();
        stepConfig.setOrder(1);
        stepConfig.setAuthenticatedIdP(TEST_IDP);
        stepConfigMap.put(1, stepConfig);
        sequenceConfig.setStepMap(stepConfigMap);
        AuthenticationGraph authenticationGraph = new AuthenticationGraph();
        authenticationGraph.setStepMap(stepConfigMap);
        sequenceConfig.setAuthenticationGraph(authenticationGraph);
        context.setSequenceConfig(sequenceConfig);
        Map<String, AuthenticatedIdPData> idPDataMap = new HashMap<>();
        AuthenticatedIdPData idPData = new AuthenticatedIdPData();
        idPData.setUser(authenticatedUser);
        idPData.setIdpName(TEST_IDP);
        idPDataMap.put(TEST_IDP, idPData);
        context.setCurrentAuthenticatedIdPs(idPDataMap);
    }
 
示例5
private void setSubjectClaimForStandardDialect(String tenantAwareUserId, UserStoreManager userStore,
                                               AuthenticationContext context, String subjectURI) {
    try {
        String value = userStore.getUserClaimValue(tenantAwareUserId, subjectURI, null);
        if (value != null) {
            context.setProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE, value);
            if (log.isDebugEnabled()) {
                log.debug("Setting \'ServiceProviderSubjectClaimValue\' property value " +
                          "from user store " + value);
            }
        } else {
            if(log.isDebugEnabled()) {
                log.debug("Subject claim for " + tenantAwareUserId + " not found in user store");
            }
        }
    } catch (UserStoreException e) {
        log.error("Error occurred while retrieving " + subjectURI + " claim value for user " + tenantAwareUserId,
                e);
    }
}
 
示例6
/**
 * Set federated subject's SP Subject Claim URI as a property
 */
private void setSubjectClaimForFederatedClaims(Map<String, String> attributesMap,
                                               String spStandardDialect,
                                               AuthenticationContext context) {

    String subjectURI = context.getSequenceConfig().getApplicationConfig().getSubjectClaimUri();
    if (subjectURI != null && !subjectURI.isEmpty()) {
        if (spStandardDialect != null) {
            setSubjectClaim(null, null, attributesMap, spStandardDialect, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst locally mapped " +
                         "unfiltered remote claims");
            }
        } else {
            setSubjectClaim(null, null, attributesMap, null, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst service provider mapped " +
                         "unfiltered remote claims");
            }
        }
    }
}
 
示例7
public static void publishSessionEvent(String sessionId, HttpServletRequest request, AuthenticationContext
        context, SessionContext sessionContext, AuthenticatedUser user, String status) {
    AuthenticationDataPublisher authnDataPublisherProxy = FrameworkServiceDataHolder.getInstance()
            .getAuthnDataPublisherProxy();
    if (authnDataPublisherProxy != null && authnDataPublisherProxy.isEnabled(context)) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put(FrameworkConstants.AnalyticsAttributes.USER, user);
        paramMap.put(FrameworkConstants.AnalyticsAttributes.SESSION_ID, sessionId);
        Map<String, Object> unmodifiableParamMap = Collections.unmodifiableMap(paramMap);
        if (FrameworkConstants.AnalyticsAttributes.SESSION_CREATE.equalsIgnoreCase(status)) {
            authnDataPublisherProxy.publishSessionCreation(request, context, sessionContext,
                    unmodifiableParamMap);
        } else if (FrameworkConstants.AnalyticsAttributes.SESSION_UPDATE.equalsIgnoreCase(status)) {
            authnDataPublisherProxy.publishSessionUpdate(request, context, sessionContext,
                    unmodifiableParamMap);
        } else if (FrameworkConstants.AnalyticsAttributes.SESSION_TERMINATE.equalsIgnoreCase(status)) {
            authnDataPublisherProxy.publishSessionTermination(request, context, sessionContext,
                    unmodifiableParamMap);
        }
    }
}
 
示例8
@Test(dataProvider = "noJsDataProvider")
public void testHandleStaticSequence(String spFileName, int authHistoryCount) throws
        Exception {
    ServiceProvider sp1 = getTestServiceProvider(spFileName);

    AuthenticationContext context = getAuthenticationContext(sp1);

    SequenceConfig sequenceConfig = configurationLoader
            .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);

    HttpServletRequest req = mock(HttpServletRequest.class);

    HttpServletResponse resp = mock(HttpServletResponse.class);

    UserCoreUtil.setDomainInThreadLocal("test_domain");

    graphBasedSequenceHandler.handle(req, resp, context);

    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(authHistories.size(), authHistoryCount);
}
 
示例9
@Test
public void testRemoteAddition() throws ScriptException {

    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    AuthenticationContext authenticationContext = new AuthenticationContext();
    setupAuthContextWithStepData(authenticationContext, authenticatedUser);

    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);

    scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'");

    ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false);
    String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping);
    assertEquals(claimCreatedByJs, "testValue");
}
 
示例10
private AuthenticationContext getMockedContextForJitProvisioning(String provisioningUserStoreId,
                                                                 String provisioningUserStoreClaimUri,
                                                                 String tenantDomain) {

    ExternalIdPConfig externalIdPConfig = spy(new ExternalIdPConfig());
    when(externalIdPConfig.getProvisioningUserStoreId()).thenReturn(provisioningUserStoreId);
    when(externalIdPConfig.getProvisioningUserStoreClaimURI()).thenReturn(provisioningUserStoreClaimUri);

    ApplicationConfig applicationConfig = new ApplicationConfig(new ServiceProvider());
    applicationConfig.setApplicationName("DUMMY_NAME");

    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.setApplicationConfig(applicationConfig);

    context.setTenantDomain(tenantDomain);
    context.setSequenceConfig(sequenceConfig);
    context.setExternalIdP(externalIdPConfig);

    return context;
}
 
示例11
@Test(expectedExceptions = PostAuthenticationFailedException.class)
public void testPostAuthenticationHandlerFailures() throws Exception {

    Cookie[] cookies = new Cookie[1];
    HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
    HttpServletResponse response = PowerMockito.mock(HttpServletResponse.class);
    AuthenticationContext context = prepareContextForPostAuthnTests();
    when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(new DefaultStepBasedSequenceHandler());
    authenticationRequestHandler.handle(request, response, context);
    assertNull(context.getParameter(FrameworkConstants.POST_AUTHENTICATION_EXTENSION_COMPLETED));
    String pastrCookie = context.getParameter(FrameworkConstants.PASTR_COOKIE).toString();
    cookies[0] = new Cookie(FrameworkConstants.PASTR_COOKIE + "-" + context.getContextIdentifier(), pastrCookie);
    when(request.getCookies()).thenReturn(cookies);
    when(FrameworkUtils.getCookie(any(HttpServletRequest.class), anyString())).thenReturn
            (new Cookie(FrameworkConstants.PASTR_COOKIE + "-" + context.getContextIdentifier(),
                    "someGibberishValue"));
    authenticationRequestHandler.handle(request, response, context);
    assertTrue(Boolean.parseBoolean(context.getProperty(
            FrameworkConstants.POST_AUTHENTICATION_EXTENSION_COMPLETED).toString()));
}
 
示例12
/**
 * To process the logout flow.
 *
 * @param request  the httpServletRequest
 * @param response the httpServletResponse
 * @param context  the authentication context
 * @return the authentication flow status
 * @throws LogoutFailedException the exception in logout flow
 */
protected AuthenticatorFlowStatus processLogoutFlow(HttpServletRequest request, HttpServletResponse response,
                                                    AuthenticationContext context) throws LogoutFailedException {

    try {
        if (!canHandle(request)) {
            context.setCurrentAuthenticator(getName());
            initiateLogoutRequest(request, response, context);
            return AuthenticatorFlowStatus.INCOMPLETE;
        } else {
            processLogoutResponse(request, response, context);
            return AuthenticatorFlowStatus.SUCCESS_COMPLETED;
        }
    } catch (UnsupportedOperationException e) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring UnsupportedOperationException.", e);
        }
        return AuthenticatorFlowStatus.SUCCESS_COMPLETED;
    }
}
 
示例13
@Test
public void testHandleDynamicJavascript1() throws Exception {

    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn2", new CustomFunctionImpl2());

    AuthenticationContext context = processSequenceWithAcr(new String[] { "acr1" });
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(3, authHistories.size());
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");
}
 
示例14
@Test(dataProvider = "sendResponseDataProvider")
public void testSendResponse(boolean isRequestAuthenticated,
                             boolean isRememberMe,
                             String callerPath,
                             String sessionDataKey,
                             String expectedRedirectUrl) throws Exception {

    AuthenticationContext context = new AuthenticationContext();
    context.setRequestAuthenticated(isRequestAuthenticated);
    context.setRememberMe(isRememberMe);
    context.setCallerPath(callerPath);
    context.setCallerSessionKey(sessionDataKey);

    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    context.setSequenceConfig(sequenceConfig);

    DefaultAuthenticationRequestHandler requestHandler = spy(new DefaultAuthenticationRequestHandler());
    doNothing().when(requestHandler).populateErrorInformation(request, response, context);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    requestHandler.sendResponse(request, response, context);
    verify(response).sendRedirect(captor.capture());
    assertEquals(captor.getValue(), expectedRedirectUrl);
}
 
示例15
private StepHandler getMockedStepHandlerForSuccessfulRequestAuthentication() throws Exception {
    // mock the step handler
    StepHandler stepHandler = mock(StepHandler.class);
    doAnswer(new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            AuthenticationContext context = invocationOnMock.getArgumentAt(2, AuthenticationContext.class);
            StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
            stepConfig.setCompleted(true);
            context.setRequestAuthenticated(true);
            return null;
        }
    }).when(stepHandler).handle(any(HttpServletRequest.class), any(HttpServletResponse.class),
            any(AuthenticationContext.class));

    return stepHandler;
}
 
示例16
/**
 * Set federated subject's SP Subject Claim URI as a property
 */
private void setSubjectClaimForLocalClaims(String tenantAwareUserId,
                                           UserStoreManager userStore,
                                           Map<String, String> attributesMap,
                                           String spStandardDialect,
                                           AuthenticationContext context) {

    String subjectURI = context.getSequenceConfig().getApplicationConfig().getSubjectClaimUri();
    if (subjectURI != null && !subjectURI.isEmpty()) {
        if (spStandardDialect != null) {
            setSubjectClaim(tenantAwareUserId, userStore, attributesMap, spStandardDialect, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst unfiltered local claims");
            }
        } else {
            setSubjectClaim(tenantAwareUserId, userStore, attributesMap, null, context);
            if (context.getProperty(SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE) == null) {
                log.warn("Subject claim could not be found amongst service provider mapped " +
                         "unfiltered local claims");
            }
        }
    }
}
 
示例17
/**
 * @param contextId
 * @return
 */
public static AuthenticationContext getAuthenticationContextFromCache(String contextId) {

    AuthenticationContext authenticationContext = null;
    AuthenticationContextCacheKey cacheKey = new AuthenticationContextCacheKey(contextId);
    AuthenticationContextCacheEntry authenticationContextCacheEntry = AuthenticationContextCache.getInstance().
            getValueFromCache(cacheKey);

    if (authenticationContextCacheEntry != null) {
        authenticationContext = authenticationContextCacheEntry.getContext();
    }

    if (log.isDebugEnabled() && authenticationContext == null) {
        log.debug("Authentication Context is null");
    }

    return authenticationContext;
}
 
示例18
private AuthenticationResult getAuthenticationResult(HttpServletRequest request,
                                                     HttpServletResponse response,
                                                     AuthenticationContext context) {

    AuthenticationResult authenticationResult = null;
    if (FrameworkUtils.getCacheDisabledAuthenticators().contains(context.getRequestType())
            && (response instanceof CommonAuthResponseWrapper) &&
            !((CommonAuthResponseWrapper) response).isWrappedByFramework()) {
        // Get the authentication result from the request
        authenticationResult =
                (AuthenticationResult) request.getAttribute(FrameworkConstants.RequestAttribute.AUTH_RESULT);
    } else {
        // Retrieve the authentication result from cache
        AuthenticationResultCacheEntry authenticationResultCacheEntry =
                FrameworkUtils.getAuthenticationResultFromCache(context.getCallerSessionKey());
        if (authenticationResultCacheEntry != null) {
            authenticationResult = authenticationResultCacheEntry.getResult();
        }
    }
    return authenticationResult;
}
 
示例19
@Override
protected void processAuthenticationResponse(HttpServletRequest request,
                                             HttpServletResponse response, AuthenticationContext context)
        throws AuthenticationFailedException {

    ExternalIdPConfig externalIdPConfig = context.getExternalIdP();

    if (request.getParameter(PassiveSTSConstants.HTTP_PARAM_PASSIVE_STS_RESULT) != null) {
        try {
            new PassiveSTSManager(externalIdPConfig).processResponse(request, context);
        } catch (PassiveSTSException e) {
            log.error("Exception while processing WS-Federation response", e);
            throw new AuthenticationFailedException(e.getMessage(), e);
        }
    } else {
        log.error("wresult can not be found in request");
        throw new AuthenticationFailedException("wresult can not be found in request");
    }

}
 
示例20
private StepHandler getMockedStepHandlerForIncompleteStep(final boolean isRequestAuthenticated) throws Exception {
    // mock the step handler
    StepHandler stepHandler = mock(StepHandler.class);
    doAnswer(new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            AuthenticationContext context = invocationOnMock.getArgumentAt(2, AuthenticationContext.class);
            StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
            stepConfig.setCompleted(false);
            context.setRequestAuthenticated(isRequestAuthenticated);
            return null;
        }
    }).when(stepHandler).handle(any(HttpServletRequest.class), any(HttpServletResponse.class),
            any(AuthenticationContext.class));
    return stepHandler;
}
 
示例21
public AsyncCallback(
        AuthenticationContext authenticationContext,
        Function<AuthenticationContext, String> returnFunction) {

    this.authenticationContext = authenticationContext;
    this.returnFunction = returnFunction;
}
 
示例22
private Map<String, String> getLocalToIdpClaimMappingWithStandardDialect(Map<String, String> remoteClaims,
                                                                         ClaimMapping[] idPClaimMappings,
                                                                         AuthenticationContext context,
                                                                         String idPStandardDialect)
        throws FrameworkException {
    Map<String, String> localToIdPClaimMap;
    if (idPStandardDialect == null) {
        idPStandardDialect = ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT;
    }

    try {
        localToIdPClaimMap = getClaimMappings(idPStandardDialect,
                                              remoteClaims.keySet(), context.getTenantDomain(), true);
    } catch (Exception e) {
        throw new FrameworkException("Error occurred while getting claim mappings for " +
                                     "received remote claims from " +
                                     idPStandardDialect + " dialect to " +
                                     ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT + " dialect for " +
                                     context.getTenantDomain() + " to handle federated claims", e);
    }
    // adding remote claims with default values also to the key set because they may not come from the federated IdP
    for(ClaimMapping claimMapping : idPClaimMappings){
        if (StringUtils.isNotBlank(claimMapping.getDefaultValue()) && !localToIdPClaimMap.containsKey
                (claimMapping.getLocalClaim().getClaimUri())) {
            localToIdPClaimMap.put(claimMapping.getLocalClaim().getClaimUri(), claimMapping.getDefaultValue());
        }
    }
    return localToIdPClaimMap;
}
 
示例23
@Test
public void testClaimAssignment() throws ScriptException {

    ClaimMapping claimMapping1 = ClaimMapping.build("", "", "", false);

    ClaimMapping claimMapping2 = ClaimMapping.build("Test.Remote.Claim.Url.2", "Test.Remote.Claim.Url.2", "",
        false);

    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.getUserAttributes().put(claimMapping1, "TestClaimVal1");
    authenticatedUser.getUserAttributes().put(claimMapping2, "TestClaimVal2");
    AuthenticationContext authenticationContext = new AuthenticationContext();
    setupAuthContextWithStepData(authenticationContext, authenticatedUser);

    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);

    Object result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.1']");
    assertNull(result);
    result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']");
    assertEquals(result, "TestClaimVal2");

    scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2'] = 'Modified2'");
    result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']");
    assertEquals(result, "Modified2");

}
 
示例24
private Map<String, String> mapLocalSpClaimsToRemoteSPClaims(String spStandardDialect,
                                                             AuthenticationContext context,
                                                             Map<String, String> spClaimMappings)
        throws FrameworkException {
    Map<String, String> localToSPClaimMappings = null;

    if (spStandardDialect != null) {
        // passing null for keySet argument to get all claim mappings,
        // since we don't know required claim mappings in advance
        // Key:value -> carbon_dialect:standard_dialect
        try {
            localToSPClaimMappings = getClaimMappings(spStandardDialect, null,
                                                      context.getTenantDomain(), true);
        } catch (Exception e) {
            throw new FrameworkException("Error occurred while getting all claim mappings from " +
                                         spStandardDialect + " dialect to " +
                                         ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT + " dialect for " +
                                         context.getTenantDomain() + " to handle federated claims", e);
        }
    } else if (!spClaimMappings.isEmpty()) {
        localToSPClaimMappings = FrameworkUtils.getLocalToSPClaimMappings(spClaimMappings);
    } else { // no standard dialect and no custom claim mappings
        throw new AssertionError("Authenticator Error! Authenticator does not have a " +
                                 "standard dialect and no custom claim mappings defined for IdP");
    }
    return localToSPClaimMappings;
}
 
示例25
private void handleRememberMeOptionFromLoginPage(HttpServletRequest request, AuthenticationContext context) {
    String rememberMe = request.getParameter("chkRemember");

    if (rememberMe != null && "on".equalsIgnoreCase(rememberMe)) {
        context.setRememberMe(true);
    } else {
        context.setRememberMe(false);
    }
}
 
示例26
/**
 * Returns whether post authentication handler execution is ended or not.
 *
 * @param authenticationContext Authentication context.
 * @return True if post authentication handlers have finished execution on this context. else false.
 */
public static boolean isPostAuthenticationExtensionCompleted(AuthenticationContext authenticationContext) {

    Object object = authenticationContext.getProperty(FrameworkConstants.POST_AUTHENTICATION_EXTENSION_COMPLETED);
    if (object != null && object instanceof Boolean) {
        return (Boolean) object;
    } else {
        return false;
    }
}
 
示例27
protected boolean isStepHasMultiOption(AuthenticationContext context) {
    Map<Integer, StepConfig> stepMap = context.getSequenceConfig().getStepMap();
    boolean stepHasMultiOption = false;

    if (stepMap != null && !stepMap.isEmpty()) {
        StepConfig stepConfig = stepMap.get(context.getCurrentStep());

        if (stepConfig != null) {
            stepHasMultiOption = stepConfig.isMultiOption();
        }
    }
    return stepHasMultiOption;
}
 
示例28
/**
 * Constructs the builder with the given authentication context.
 *
 * @param authenticationContext current authentication context.
 * @param stepConfigMap         The Step map from the service provider configuration.
 * @param scriptEngine          Script engine.
 * @param currentNode           Current authentication graph node.
 */
public JsGraphBuilder(AuthenticationContext authenticationContext, Map<Integer, StepConfig> stepConfigMap,
                      ScriptEngine scriptEngine, AuthGraphNode currentNode) {

    this.engine = scriptEngine;
    this.authenticationContext = authenticationContext;
    this.currentNode = currentNode;
    stepNamedMap = stepConfigMap.entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
 
示例29
protected void resetAuthenticationContext(AuthenticationContext context)
        throws FrameworkException {

    context.setSubject(null);
    context.setStateInfo(null);
    context.setExternalIdP(null);
    context.setAuthenticatorProperties(new HashMap<String, String>());
    context.setRetryCount(0);
    context.setRetrying(false);
    context.setCurrentAuthenticator(null);
}
 
示例30
private List<String> getSPMandatoryLocalClaims(AuthenticationContext context)
        throws PostAuthenticationFailedException {

    List<String> spMandatoryLocalClaims = new ArrayList<>();
    ApplicationConfig applicationConfig = context.getSequenceConfig().getApplicationConfig();

    if (applicationConfig == null) {
        ServiceProvider serviceProvider = getServiceProvider(context);
        String error = "Application configs are null in AuthenticationContext for SP: " + serviceProvider
                .getApplicationName() + " in tenant domain: " + getSPTenantDomain(serviceProvider);
        throw new PostAuthenticationFailedException("Authentication failed. Error while processing application " +
                                                    "claim configurations.", error);
    }

    Map<String, String> claimMappings = applicationConfig.getMandatoryClaimMappings();

    if (isNotEmpty(claimMappings) && isNotEmpty(claimMappings.values())) {
        spMandatoryLocalClaims = new ArrayList<>(claimMappings.values());
    }
    String subjectClaimUri = getSubjectClaimUri(applicationConfig);
    if (!spMandatoryLocalClaims.contains(subjectClaimUri)) {
        spMandatoryLocalClaims.add(subjectClaimUri);
    }

    if (isDebugEnabled()) {
        String message = String.format("Mandatory claims for SP: %s - " + spMandatoryLocalClaims,
                applicationConfig.getApplicationName());
        logDebug(message);
    }
    return spMandatoryLocalClaims;
}