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