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());
}
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());
}
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<>());
}
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);
}
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);
}
Aggregations