Search in sources :

Example 41 with Credential

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

the class KryoTranscoderTests method verifyEncodeDecodeTGTWithListOrderedMap.

@Test
public void verifyEncodeDecodeTGTWithListOrderedMap() throws Exception {
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    @SuppressWarnings("unchecked") final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, this.principalAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 42 with Credential

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

the class KryoTranscoderTests method verifyEncodeDecodeTGTWithSingletonMap.

@Test
public void verifyEncodeDecodeTGTWithSingletonMap() throws Exception {
    final Map<String, Object> newAttributes = Collections.singletonMap(NICKNAME_KEY, NICKNAME_VALUE);
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 43 with Credential

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

the class TokenAuthenticationAction method constructCredentialsFromRequest.

@Override
protected Credential constructCredentialsFromRequest(final RequestContext requestContext) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
    String authTokenValue = request.getParameter(TokenConstants.PARAMETER_NAME_TOKEN);
    if (StringUtils.isBlank(authTokenValue)) {
        authTokenValue = request.getHeader(TokenConstants.PARAMETER_NAME_TOKEN);
    }
    final Service service = WebUtils.getService(requestContext);
    if (StringUtils.isNotBlank(authTokenValue) && service != null) {
        try {
            final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
            RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
            final Credential credential = new TokenCredential(authTokenValue, service);
            LOGGER.debug("Received token authentication request [{}] ", credential);
            return credential;
        } catch (final Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TokenCredential(org.apereo.cas.token.authentication.TokenCredential) Credential(org.apereo.cas.authentication.Credential) RegisteredService(org.apereo.cas.services.RegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) TokenCredential(org.apereo.cas.token.authentication.TokenCredential)

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