Search in sources :

Example 71 with Authentication

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

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketNoAttributesReturned.

@Test
public void verifyValidateServiceTicketNoAttributesReturned() {
    final Service service = getService();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), service, ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), service);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(0, auth.getPrincipal().getAttributes().size());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 72 with Authentication

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

the class CentralAuthenticationServiceImplTests method verifyValidateServiceTicketWithDefaultUsernameAttribute.

@Test
public void verifyValidateServiceTicketWithDefaultUsernameAttribute() {
    final Service svc = getService("testDefault");
    final UsernamePasswordCredential cred = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), svc, ctx);
    final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), svc);
    final Authentication auth = assertion.getPrimaryAuthentication();
    assertEquals(auth.getPrincipal().getId(), cred.getUsername());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 73 with Authentication

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

the class AuthyAuthenticationHandler method doAuthentication.

@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
    final AuthyTokenCredential tokenCredential = (AuthyTokenCredential) credential;
    final Authentication authentication = WebUtils.getInProgressAuthentication();
    if (authentication == null) {
        throw new IllegalArgumentException("CAS has no reference to an authentication event to locate a principal");
    }
    final Principal principal = authentication.getPrincipal();
    final User user = instance.getOrCreateUser(principal);
    if (!user.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(user.getError()));
    }
    final Map<String, String> options = new HashMap<>(1);
    options.put("force", Boolean.toString(this.forceVerification));
    final Token verification = this.instance.getAuthyTokens().verify(user.getId(), tokenCredential.getToken(), options);
    if (!verification.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(verification.getError()));
    }
    return createHandlerResult(tokenCredential, principal, new ArrayList<>());
}
Also used : User(com.authy.api.User) FailedLoginException(javax.security.auth.login.FailedLoginException) HashMap(java.util.HashMap) Authentication(org.apereo.cas.authentication.Authentication) Token(com.authy.api.Token) Principal(org.apereo.cas.authentication.principal.Principal)

Example 74 with Authentication

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

the class CheckConsentRequiredAction method determineConsentEvent.

/**
 * Determine consent event string.
 *
 * @param requestContext the request context
 * @return the string
 */
protected String determineConsentEvent(final RequestContext requestContext) {
    final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
    if (service == null) {
        return null;
    }
    final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    if (authentication == null) {
        return null;
    }
    return isConsentRequired(service, registeredService, authentication, requestContext);
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 75 with Authentication

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

the class ConfirmConsentAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
    final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    final int optionValue = Integer.parseInt(request.getParameter("option"));
    final ConsentOptions option = ConsentOptions.valueOf(optionValue);
    final long reminder = Long.parseLong(request.getParameter("reminder"));
    final String reminderTimeUnit = request.getParameter("reminderTimeUnit");
    final ChronoUnit unit = ChronoUnit.valueOf(reminderTimeUnit.toUpperCase());
    consentEngine.storeConsentDecision(service, registeredService, authentication, reminder, unit, option);
    return new EventFactorySupport().success(this);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentOptions(org.apereo.cas.consent.ConsentOptions) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) ChronoUnit(java.time.temporal.ChronoUnit)

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