Search in sources :

Example 86 with Authentication

use of org.apereo.cas.authentication.Authentication in project cas by apereo.

the class AbstractServiceValidateController method validateAuthenticationContext.

/**
 * Validate authentication context pair.
 *
 * @param assertion the assertion
 * @param request   the request
 * @return the pair
 */
protected Pair<Boolean, Optional<MultifactorAuthenticationProvider>> validateAuthenticationContext(final Assertion assertion, final HttpServletRequest request) {
    LOGGER.debug("Locating the primary authentication associated with this service request [{}]", assertion.getService());
    final RegisteredService service = this.servicesManager.findServiceBy(assertion.getService());
    RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(assertion.getService(), service);
    final Map<String, MultifactorAuthenticationProvider> providers = this.applicationContext.getBeansOfType(MultifactorAuthenticationProvider.class, false, true);
    final Authentication authentication = assertion.getPrimaryAuthentication();
    final Optional<String> requestedContext = this.multifactorTriggerSelectionStrategy.resolve(providers.values(), request, service, authentication);
    if (!requestedContext.isPresent()) {
        LOGGER.debug("No particular authentication context is required for this request");
        return Pair.of(Boolean.TRUE, Optional.empty());
    }
    return this.authenticationContextValidator.validate(authentication, requestedContext.get(), service);
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider)

Example 87 with Authentication

use of org.apereo.cas.authentication.Authentication in project cas by apereo.

the class Cas30JsonResponseView method createAuthenticationSuccess.

private CasJsonServiceResponseAuthenticationSuccess createAuthenticationSuccess(final Map<String, Object> model) {
    final CasJsonServiceResponseAuthenticationSuccess success = new CasJsonServiceResponseAuthenticationSuccess();
    success.setAttributes(getModelAttributes(model));
    final Principal principal = getPrincipal(model);
    success.setUser(principal.getId());
    success.setProxyGrantingTicket(getProxyGrantingTicketIou(model));
    final Collection<Authentication> chainedAuthentications = getChainedAuthentications(model);
    if (chainedAuthentications != null && !chainedAuthentications.isEmpty()) {
        final List<String> proxies = chainedAuthentications.stream().map(authn -> authn.getPrincipal().getId()).collect(Collectors.toList());
        success.setProxies(proxies);
    }
    return success;
}
Also used : Setter(lombok.Setter) Getter(lombok.Getter) Cas30ResponseView(org.apereo.cas.web.view.Cas30ResponseView) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ProtocolAttributeEncoder(org.apereo.cas.authentication.ProtocolAttributeEncoder) Slf4j(lombok.extern.slf4j.Slf4j) View(org.springframework.web.servlet.View) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) Authentication(org.apereo.cas.authentication.Authentication) Map(java.util.Map) ToString(lombok.ToString) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Principal(org.apereo.cas.authentication.principal.Principal) AuthenticationAttributeReleasePolicy(org.apereo.cas.authentication.AuthenticationAttributeReleasePolicy) CasProtocolAttributesRenderer(org.apereo.cas.validation.CasProtocolAttributesRenderer) ServicesManager(org.apereo.cas.services.ServicesManager) Authentication(org.apereo.cas.authentication.Authentication) ToString(lombok.ToString) Principal(org.apereo.cas.authentication.principal.Principal)

Example 88 with Authentication

use of org.apereo.cas.authentication.Authentication in project cas by apereo.

the class Cas10ResponseViewTests method setUp.

@Before
public void setUp() {
    this.model = new HashMap<>();
    final List<Authentication> list = new ArrayList<>();
    list.add(CoreAuthenticationTestUtils.getAuthentication("someothername"));
    this.model.put("assertion", new DefaultAssertionBuilder(CoreAuthenticationTestUtils.getAuthentication()).with(list).with(CoreAuthenticationTestUtils.getService("TestService")).with(true).build());
}
Also used : DefaultAssertionBuilder(org.apereo.cas.validation.DefaultAssertionBuilder) Authentication(org.apereo.cas.authentication.Authentication) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 89 with Authentication

use of org.apereo.cas.authentication.Authentication in project cas by apereo.

the class OidcCasClientRedirectActionBuilder method build.

@Override
public RedirectAction build(final CasClient casClient, final WebContext context) {
    final Optional<Authentication> auth = oidcAuthorizationRequestSupport.isCasAuthenticationAvailable(context);
    auth.ifPresent(authentication -> oidcAuthorizationRequestSupport.configureClientForMaxAgeAuthorizationRequest(casClient, context, authentication));
    OidcAuthorizationRequestSupport.configureClientForPromptLoginAuthorizationRequest(casClient, context);
    OidcAuthorizationRequestSupport.configureClientForPromptNoneAuthorizationRequest(casClient, context);
    final RedirectAction action = super.build(casClient, context);
    LOGGER.debug("Final redirect action is [{}]", action);
    return action;
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) RedirectAction(org.pac4j.core.redirect.RedirectAction)

Example 90 with Authentication

use of org.apereo.cas.authentication.Authentication in project cas by apereo.

the class OAuth20AccessTokenControllerTests method addRefreshToken.

private RefreshToken addRefreshToken(final Principal principal, final RegisteredService registeredService) {
    final Authentication authentication = getAuthentication(principal);
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final Service service = factory.createService(registeredService.getServiceId());
    final RefreshToken refreshToken = oAuthRefreshTokenFactory.create(service, authentication);
    oAuth20AccessTokenController.getTicketRegistry().addTicket(refreshToken);
    return refreshToken;
}
Also used : RefreshToken(org.apereo.cas.ticket.refreshtoken.RefreshToken) Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Aggregations

Authentication (org.apereo.cas.authentication.Authentication)144 RegisteredService (org.apereo.cas.services.RegisteredService)61 Test (org.junit.Test)48 Service (org.apereo.cas.authentication.principal.Service)44 Principal (org.apereo.cas.authentication.principal.Principal)38 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)24 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)21 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)21 Event (org.springframework.webflow.execution.Event)20 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)15 HashMap (java.util.HashMap)14 Assertion (org.apereo.cas.validation.Assertion)14 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)13 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)12 Collection (java.util.Collection)11 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)11