use of org.apereo.cas.authentication.Credential in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyAttributesWithPrincipal.
@Test
public void verifyAttributesWithPrincipal() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
resolver.setPrincipalAttributeName("cn");
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final Principal p = resolver.resolve(c, null);
assertNotNull(p);
assertNotEquals(p.getId(), CoreAuthenticationTestUtils.CONST_USERNAME);
assertTrue(p.getAttributes().containsKey("memberOf"));
}
use of org.apereo.cas.authentication.Credential in project cas by apereo.
the class ServiceTicketRequestWebflowEventResolver method grantServiceTicket.
/**
* Grant service ticket for the given credential based on the service and tgt
* that are found in the request context.
*
* @param context the context
* @return the resulting event. Warning, authentication failure or error.
* @since 4.1.0
*/
protected Event grantServiceTicket(final RequestContext context) {
final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
final Credential credential = getCredentialFromContext(context);
try {
final Service service = WebUtils.getService(context);
final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicketId, service, authenticationResult);
WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
WebUtils.putWarnCookieIfRequestParameterPresent(this.warnCookieGenerator, context);
return newEvent(CasWebflowConstants.TRANSITION_ID_WARN);
} catch (final AuthenticationException | AbstractTicketException e) {
return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
}
}
use of org.apereo.cas.authentication.Credential in project cas by apereo.
the class AbstractCasWebflowEventResolver method handleAuthenticationTransactionAndGrantTicketGrantingTicket.
/**
* Handle authentication transaction and grant ticket granting ticket set.
*
* @param context the context
* @return the set
*/
protected Set<Event> handleAuthenticationTransactionAndGrantTicketGrantingTicket(final RequestContext context) {
try {
final Credential credential = getCredentialFromContext(context);
AuthenticationResultBuilder builder = WebUtils.getAuthenticationResultBuilder(context);
LOGGER.debug("Handling authentication transaction for credential [{}]", credential);
final Service service = WebUtils.getService(context);
builder = this.authenticationSystemSupport.handleAuthenticationTransaction(service, builder, credential);
LOGGER.debug("Issuing ticket-granting tickets for service [{}]", service);
return Collections.singleton(grantTicketGrantingTicketToAuthenticationResult(context, builder, service));
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
final MessageContext messageContext = context.getMessageContext();
messageContext.addMessage(new MessageBuilder().error().code(DEFAULT_MESSAGE_BUNDLE_PREFIX.concat(e.getClass().getSimpleName())).build());
return Collections.singleton(new EventFactorySupport().error(this));
}
}
use of org.apereo.cas.authentication.Credential in project cas by apereo.
the class WebUtils method getCredential.
/**
* Gets credential from the context.
*
* @param context the context
* @return the credential, or null if it cant be found in the context or if it has no id.
*/
public static Credential getCredential(final RequestContext context) {
final Credential cFromRequest = (Credential) context.getRequestScope().get(PARAMETER_CREDENTIAL);
final Credential cFromFlow = (Credential) context.getFlowScope().get(PARAMETER_CREDENTIAL);
Credential credential = cFromRequest != null ? cFromRequest : cFromFlow;
if (credential == null) {
final FlowSession session = context.getFlowExecutionContext().getActiveSession();
credential = session.getScope().get(PARAMETER_CREDENTIAL, Credential.class);
}
if (credential != null && StringUtils.isBlank(credential.getId())) {
return null;
}
return credential;
}
use of org.apereo.cas.authentication.Credential in project cas by apereo.
the class AbstractNonInteractiveCredentialsAction method doPreExecute.
@Override
protected Event doPreExecute(final RequestContext context) throws Exception {
final Credential credential = constructCredentialsFromRequest(context);
if (credential == null) {
LOGGER.warn("No credentials detected. Navigating to error...");
return error();
}
WebUtils.putCredential(context, credential);
return super.doPreExecute(context);
}
Aggregations