Search in sources :

Example 61 with Credential

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingletonMap.

@Test
public void verifyEncodeDecodeTGTWithSingletonMap() {
    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);
    final CachedData result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) CachedData(net.spy.memcached.CachedData) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 62 with Credential

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

the class RegisteredServiceResource method authenticateRequest.

private Authentication authenticateRequest(final HttpServletRequest request, final HttpServletResponse response) {
    final BasicAuthExtractor extractor = new BasicAuthExtractor();
    final WebContext webContext = new J2EContext(request, response);
    final UsernamePasswordCredentials credentials = extractor.extract(webContext);
    if (credentials != null) {
        LOGGER.debug("Received basic authentication request from credentials [{}]", credentials);
        final Credential c = new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
        final Service serviceRequest = this.serviceFactory.createService(request);
        final AuthenticationResult result = authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(serviceRequest, c);
        return result.getAuthentication();
    }
    throw new BadRestRequestException("Could not authenticate request");
}
Also used : BasicAuthExtractor(org.pac4j.core.credentials.extractor.BasicAuthExtractor) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) WebContext(org.pac4j.core.context.WebContext) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) J2EContext(org.pac4j.core.context.J2EContext) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 63 with Credential

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

the class ECPProfileHandlerController method handleEcpRequest.

/**
 * Handle ecp request.
 *
 * @param response the response
 * @param request  the request
 */
@PostMapping(path = SamlIdPConstants.ENDPOINT_SAML2_IDP_ECP_PROFILE_SSO, consumes = { MediaType.TEXT_XML_VALUE, SamlIdPConstants.ECP_SOAP_PAOS_CONTENT_TYPE }, produces = { MediaType.TEXT_XML_VALUE, SamlIdPConstants.ECP_SOAP_PAOS_CONTENT_TYPE })
public void handleEcpRequest(final HttpServletResponse response, final HttpServletRequest request) {
    final MessageContext soapContext = decodeSoapRequest(request);
    final Credential credential = extractBasicAuthenticationCredential(request, response);
    if (credential == null) {
        LOGGER.error("Credentials could not be extracted from the SAML ECP request");
        return;
    }
    if (soapContext == null) {
        LOGGER.error("SAML ECP request could not be determined from the authentication request");
        return;
    }
    handleEcpRequest(response, request, soapContext, credential, SAMLConstants.SAML2_PAOS_BINDING_URI);
}
Also used : UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) MessageContext(org.opensaml.messaging.context.MessageContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 64 with Credential

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

the class GoogleAuthenticatorRestHttpRequestCredentialFactoryTests method verifyCredentials.

@Test
public void verifyCredentials() {
    final GoogleAuthenticatorRestHttpRequestCredentialFactory f = new GoogleAuthenticatorRestHttpRequestCredentialFactory();
    final LinkedMultiValueMap body = new LinkedMultiValueMap<>();
    body.add(GoogleAuthenticatorRestHttpRequestCredentialFactory.PARAMETER_NAME_GAUTH_OTP, "132456");
    final List<Credential> results = f.fromRequestBody(body);
    assertFalse(results.isEmpty());
    assertEquals("132456", results.get(0).getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 65 with Credential

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

the class SurrogateWebflowEventResolver method loadSurrogates.

private boolean loadSurrogates(final RequestContext requestContext) {
    final Credential c = WebUtils.getCredential(requestContext);
    if (c instanceof UsernamePasswordCredential) {
        final String username = c.getId();
        final Collection<String> surrogates = surrogateService.getEligibleAccountsForSurrogateToProxy(username);
        if (!surrogates.isEmpty()) {
            surrogates.add(username);
            requestContext.getFlowScope().put("surrogates", surrogates);
            return true;
        }
    }
    return false;
}
Also used : UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential)

Aggregations

Credential (org.apereo.cas.authentication.Credential)67 Test (org.junit.Test)39 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)29 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)26 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)18 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)13 Service (org.apereo.cas.authentication.principal.Service)13 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)11 HashMap (java.util.HashMap)10 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)10 CachedData (net.spy.memcached.CachedData)9 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)9 LinkedHashMap (java.util.LinkedHashMap)8 RegisteredService (org.apereo.cas.services.RegisteredService)8 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 MockServletContext (org.springframework.mock.web.MockServletContext)7 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)7 MockRequestContext (org.springframework.webflow.test.MockRequestContext)7