Search in sources :

Example 1 with TokenCredential

use of org.apereo.cas.token.authentication.TokenCredential in project cas by apereo.

the class TokenAuthenticationAction method constructCredentialsFromRequest.

@Override
protected Credential constructCredentialsFromRequest(final RequestContext requestContext) {
    val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    val authTokenValue = this.tokenRequestExtractor.extract(request);
    val service = WebUtils.getService(requestContext);
    if (service != null && StringUtils.isNotBlank(authTokenValue)) {
        try {
            val registeredService = this.servicesManager.findServiceBy(service);
            RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
            val credential = new TokenCredential(authTokenValue, service);
            LOGGER.debug("Received token authentication request [{}] ", credential);
            return credential;
        } catch (final Exception e) {
            LoggingUtils.warn(LOGGER, e);
        }
    }
    return null;
}
Also used : lombok.val(lombok.val) TokenCredential(org.apereo.cas.token.authentication.TokenCredential)

Example 2 with TokenCredential

use of org.apereo.cas.token.authentication.TokenCredential in project cas by apereo.

the class TokenCredentialTests method verifyTokenFromParameter.

@Test
public void verifyTokenFromParameter() {
    val credential = new TokenCredential("tokenid", RegisteredServiceTestUtils.getService());
    val metadata = new BasicCredentialMetaData(credential);
    assertNotNull(metadata.getCredentialClass());
}
Also used : lombok.val(lombok.val) TokenCredential(org.apereo.cas.token.authentication.TokenCredential) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test)

Example 3 with TokenCredential

use of org.apereo.cas.token.authentication.TokenCredential 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

TokenCredential (org.apereo.cas.token.authentication.TokenCredential)3 lombok.val (lombok.val)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Credential (org.apereo.cas.authentication.Credential)1 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)1 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 Test (org.junit.jupiter.api.Test)1