Search in sources :

Example 6 with Credential

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"));
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) Credential(org.apereo.cas.authentication.Credential) Test(org.junit.Test)

Example 7 with Credential

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);
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 8 with Credential

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));
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) MessageBuilder(org.springframework.binding.message.MessageBuilder) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 9 with Credential

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;
}
Also used : Credential(org.apereo.cas.authentication.Credential) FlowSession(org.springframework.webflow.execution.FlowSession)

Example 10 with 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);
}
Also used : Credential(org.apereo.cas.authentication.Credential)

Aggregations

Credential (org.apereo.cas.authentication.Credential)43 Test (org.junit.Test)27 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)19 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)13 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)11 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)10 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)9 Service (org.apereo.cas.authentication.principal.Service)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)7 MockServletContext (org.springframework.mock.web.MockServletContext)7 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)7 MockRequestContext (org.springframework.webflow.test.MockRequestContext)7 HashMap (java.util.HashMap)6 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)5 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)5 LinkedHashMap (java.util.LinkedHashMap)4 RegisteredService (org.apereo.cas.services.RegisteredService)4