Search in sources :

Example 16 with RequestContext

use of org.springframework.webflow.execution.RequestContext in project cas by apereo.

the class ServiceThemeResolverTests method verifyGetServiceThemeDoesNotExist.

@Test
public void verifyGetServiceThemeDoesNotExist() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setTheme("myTheme");
    r.setId(1000);
    r.setName("Test Service");
    r.setServiceId("myServiceId");
    this.servicesManager.save(r);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final RequestContext ctx = mock(RequestContext.class);
    final MutableAttributeMap scope = new LocalAttributeMap();
    scope.put("service", RegisteredServiceTestUtils.getService(r.getServiceId()));
    when(ctx.getFlowScope()).thenReturn(scope);
    RequestContextHolder.setRequestContext(ctx);
    request.addHeader(WebUtils.USER_AGENT_HEADER, MOZILLA);
    assertEquals(DEFAULT_THEME_NAME, this.serviceThemeResolver.resolveThemeName(request));
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RequestContext(org.springframework.webflow.execution.RequestContext) Test(org.junit.Test)

Example 17 with RequestContext

use of org.springframework.webflow.execution.RequestContext in project cas by apereo.

the class CasWebflowContextConfigurationTests method verifyFlowExecutorByClient.

@Test
public void verifyFlowExecutorByClient() {
    final RequestContext ctx = getMockRequestContext();
    final LocalAttributeMap map = new LocalAttributeMap<>();
    flowExecutorViaClientFlowExecution.launchExecution("login", map, ctx.getExternalContext());
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockRequestContext(org.springframework.webflow.test.MockRequestContext) RequestContext(org.springframework.webflow.execution.RequestContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with RequestContext

use of org.springframework.webflow.execution.RequestContext in project cas by apereo.

the class Pac4jWebflowConfigurer method createStopWebflowViewState.

private void createStopWebflowViewState(final Flow flow) {
    final ViewState state = createViewState(flow, DelegatedClientAuthenticationAction.STOP_WEBFLOW, DelegatedClientAuthenticationAction.VIEW_ID_STOP_WEBFLOW);
    state.getEntryActionList().add(new AbstractAction() {

        @Override
        protected Event doExecute(final RequestContext requestContext) throws Exception {
            final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
            final HttpServletResponse response = WebUtils.getHttpServletResponse(requestContext);
            final Optional<ModelAndView> mv = DelegatedClientAuthenticationAction.hasDelegationRequestFailed(request, response.getStatus());
            mv.ifPresent(modelAndView -> modelAndView.getModel().forEach((k, v) -> requestContext.getFlowScope().put(k, v)));
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionState(org.springframework.webflow.engine.ActionState) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) AbstractAction(org.springframework.webflow.action.AbstractAction) HttpServletResponse(javax.servlet.http.HttpServletResponse) Flow(org.springframework.webflow.engine.Flow) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) Action(org.springframework.webflow.execution.Action) DecisionState(org.springframework.webflow.engine.DecisionState) RequestContext(org.springframework.webflow.execution.RequestContext) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletRequest(javax.servlet.http.HttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) DelegatedClientAuthenticationAction(org.apereo.cas.support.pac4j.web.flow.DelegatedClientAuthenticationAction) Optional(java.util.Optional) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) Optional(java.util.Optional) Event(org.springframework.webflow.execution.Event) HttpServletResponse(javax.servlet.http.HttpServletResponse) ViewState(org.springframework.webflow.engine.ViewState) RequestContext(org.springframework.webflow.execution.RequestContext) AbstractAction(org.springframework.webflow.action.AbstractAction)

Example 19 with RequestContext

use of org.springframework.webflow.execution.RequestContext in project cas by apereo.

the class AzureAuthenticatorAuthenticationHandler method doAuthentication.

@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    try {
        final AzureAuthenticatorTokenCredential c = (AzureAuthenticatorTokenCredential) credential;
        final RequestContext context = RequestContextHolder.getRequestContext();
        final Principal principal = WebUtils.getAuthentication(context).getPrincipal();
        LOGGER.debug("Received principal id [{}]", principal.getId());
        final PFAuthParams params = authenticationRequestBuilder.build(principal, c);
        final PFAuthResult r = azureAuthenticatorInstance.authenticate(params);
        if (r.getAuthenticated()) {
            return createHandlerResult(c, principalFactory.createPrincipal(principal.getId()), null);
        }
        LOGGER.error("Authentication failed. Call status: [{}]-[{}]. Error: [{}]", r.getCallStatus(), r.getCallStatusString(), r.getMessageError());
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    throw new FailedLoginException("Failed to authenticate user");
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) PFAuthResult(net.phonefactor.pfsdk.PFAuthResult) RequestContext(org.springframework.webflow.execution.RequestContext) PFAuthParams(net.phonefactor.pfsdk.PFAuthParams) Principal(org.apereo.cas.authentication.principal.Principal) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException) PreventedException(org.apereo.cas.authentication.PreventedException)

Example 20 with RequestContext

use of org.springframework.webflow.execution.RequestContext in project cas by apereo.

the class VerifySecurityQuestionsAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
    final String username = requestContext.getFlowScope().getString("username");
    final PasswordManagementProperties pm = casProperties.getAuthn().getPm();
    if (!pm.getReset().isSecurityQuestionsEnabled()) {
        LOGGER.debug("Security questions are not enabled");
        return success();
    }
    final Map<String, String> questions = passwordManagementService.getSecurityQuestions(username);
    final AtomicInteger i = new AtomicInteger(0);
    final long c = questions.values().stream().filter(v -> {
        final String answer = request.getParameter("q" + i.getAndIncrement());
        return answer.equals(v);
    }).count();
    if (c == questions.size()) {
        return success();
    }
    return error();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) Logger(org.slf4j.Logger) AbstractAction(org.springframework.webflow.action.AbstractAction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestContext(org.springframework.webflow.execution.RequestContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PasswordManagementService(org.apereo.cas.pm.PasswordManagementService) Map(java.util.Map) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

RequestContext (org.springframework.webflow.execution.RequestContext)24 WebUtils (org.apereo.cas.web.support.WebUtils)8 Event (org.springframework.webflow.execution.Event)8 RegisteredService (org.apereo.cas.services.RegisteredService)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Map (java.util.Map)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Authentication (org.apereo.cas.authentication.Authentication)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 Principal (org.apereo.cas.authentication.principal.Principal)5 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)5 ServicesManager (org.apereo.cas.services.ServicesManager)5 Optional (java.util.Optional)4 Set (java.util.Set)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 StringUtils (org.apache.commons.lang3.StringUtils)4 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)4 AuthenticationSystemSupport (org.apereo.cas.authentication.AuthenticationSystemSupport)4