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