Search in sources :

Example 1 with CredentialMetaData

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

the class RemoteAddressCredentialTests method verifySerializeARemoteAddressCredentialToJson.

@Test
public void verifySerializeARemoteAddressCredentialToJson() throws IOException {
    final RemoteAddressCredential credentialWritten = new RemoteAddressCredential("80.123.456.78");
    MAPPER.writeValue(JSON_FILE, credentialWritten);
    final CredentialMetaData credentialRead = MAPPER.readValue(JSON_FILE, RemoteAddressCredential.class);
    assertEquals(credentialWritten, credentialRead);
}
Also used : CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) Test(org.junit.Test)

Example 2 with CredentialMetaData

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

the class SamlAuthenticationMetaDataPopulatorTests method newAuthenticationBuilder.

private static AuthenticationBuilder newAuthenticationBuilder(final Principal principal) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("test", new DefaultHandlerResult(handler, meta));
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 3 with CredentialMetaData

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

the class OAuth20ProfileControllerTests method getAuthentication.

private static Authentication getAuthentication(final Principal principal) {
    final CredentialMetaData metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(principal.getId()));
    final HandlerResult handlerResult = new DefaultHandlerResult(principal.getClass().getCanonicalName(), metadata, principal, new ArrayList<>());
    return DefaultAuthenticationBuilder.newInstance().setPrincipal(principal).addCredential(metadata).setAuthenticationDate(ZonedDateTime.now()).addSuccess(principal.getClass().getCanonicalName(), handlerResult).build();
}
Also used : BasicIdentifiableCredential(org.apereo.cas.authentication.BasicIdentifiableCredential) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) HandlerResult(org.apereo.cas.authentication.HandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 4 with CredentialMetaData

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

the class X509CertificateCredentialTests method verifySerializeAX509CertificateCredentialToJson.

@Test
public void verifySerializeAX509CertificateCredentialToJson() throws IOException {
    MAPPER.findAndRegisterModules();
    final X509Certificate certificate = new AbstractX509CertificateTests.CasX509Certificate(true);
    final X509CertificateCredential credentialWritten = new X509CertificateCredential(new X509Certificate[] { certificate });
    MAPPER.writeValue(JSON_FILE, credentialWritten);
    final CredentialMetaData credentialRead = MAPPER.readValue(JSON_FILE, X509CertificateCredential.class);
    assertEquals(credentialWritten, credentialRead);
}
Also used : CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 5 with CredentialMetaData

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

the class BaseOAuthWrapperController method createAuthentication.

/**
     * Create an authentication from a user profile.
     *
     * @param profile           the given user profile
     * @param registeredService the registered service
     * @param context           the context
     * @param service           the service
     * @return the built authentication
     */
protected Authentication createAuthentication(final UserProfile profile, final RegisteredService registeredService, final J2EContext context, final Service service) {
    final Principal newPrincipal = this.scopeToAttributesFilter.filter(service, this.principalFactory.createPrincipal(profile.getId(), profile.getAttributes()), registeredService, context);
    LOGGER.debug("Created final principal [{}] after filtering attributes based on [{}]", newPrincipal, registeredService);
    final String authenticator = profile.getClass().getCanonicalName();
    final CredentialMetaData metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(profile.getId()));
    final HandlerResult handlerResult = new DefaultHandlerResult(authenticator, metadata, newPrincipal, new ArrayList<>());
    final String state = StringUtils.defaultIfBlank(context.getRequestParameter(OAuthConstants.STATE), StringUtils.EMPTY);
    final String nonce = StringUtils.defaultIfBlank(context.getRequestParameter(OAuthConstants.NONCE), StringUtils.EMPTY);
    LOGGER.debug("OAuth [{}] is [{}], and [{}] is [{}]", OAuthConstants.STATE, state, OAuthConstants.NONCE, nonce);
    final AuthenticationBuilder bldr = DefaultAuthenticationBuilder.newInstance().addAttribute("permissions", profile.getPermissions()).addAttribute("roles", profile.getRoles()).addAttribute(OAuthConstants.STATE, state).addAttribute(OAuthConstants.NONCE, nonce).addCredential(metadata).setPrincipal(newPrincipal).setAuthenticationDate(ZonedDateTime.now()).addSuccess(profile.getClass().getCanonicalName(), handlerResult);
    // Add "other" profile attributes as authentication attributes.
    if (casProperties.getAuthn().getOauth().getAccessToken().isReleaseProtocolAttributes()) {
        profile.getAttributes().forEach((k, v) -> {
            if (!newPrincipal.getAttributes().containsKey(k)) {
                LOGGER.debug("Added attribute [{}] with value [{}] to the authentication", k, v);
                bldr.addAttribute(k, v);
            } else {
                LOGGER.debug("Skipped over attribute [{}] since it's already contained by the principal", k);
            }
        });
    }
    return bldr.build();
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) BasicIdentifiableCredential(org.apereo.cas.authentication.BasicIdentifiableCredential) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) HandlerResult(org.apereo.cas.authentication.HandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) Principal(org.apereo.cas.authentication.principal.Principal) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Aggregations

CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)10 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)6 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)6 HandlerResult (org.apereo.cas.authentication.HandlerResult)4 Test (org.junit.Test)4 BasicIdentifiableCredential (org.apereo.cas.authentication.BasicIdentifiableCredential)3 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)3 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)2 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)2 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)2 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)2 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)1 RememberMeUsernamePasswordCredential (org.apereo.cas.authentication.RememberMeUsernamePasswordCredential)1 AcceptAnyAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1