Search in sources :

Example 16 with Audit

use of org.apereo.inspektr.audit.annotation.Audit in project cas by apereo.

the class LdapPasswordManagementService method change.

@Audit(action = "CHANGE_PASSWORD", actionResolverName = "CHANGE_PASSWORD_ACTION_RESOLVER", resourceResolverName = "CHANGE_PASSWORD_RESOURCE_RESOLVER")
@Override
public boolean change(final Credential credential, final PasswordChangeBean bean) {
    Assert.notNull(credential, "Credential cannot be null");
    Assert.notNull(bean, "PasswordChangeBean cannot be null");
    try {
        final PasswordManagementProperties.Ldap ldap = passwordManagementProperties.getLdap();
        final UsernamePasswordCredential c = (UsernamePasswordCredential) credential;
        final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldap.getUserFilter(), Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(c.getId()));
        LOGGER.debug("Constructed LDAP filter [{}] to update account password", filter);
        final ConnectionFactory factory = Beans.newLdaptivePooledConnectionFactory(ldap);
        final Response<SearchResult> response = LdapUtils.executeSearchOperation(factory, ldap.getBaseDn(), filter);
        LOGGER.debug("LDAP response to update password is [{}]", response);
        if (LdapUtils.containsResultEntry(response)) {
            final String dn = response.getResult().getEntry().getDn();
            LOGGER.debug("Updating account password for [{}]", dn);
            if (LdapUtils.executePasswordModifyOperation(dn, factory, c.getPassword(), bean.getPassword(), passwordManagementProperties.getLdap().getType())) {
                LOGGER.debug("Successfully updated the account password for [{}]", dn);
                return true;
            }
            LOGGER.error("Could not update the LDAP entry's password for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
        } else {
            LOGGER.error("Could not locate an LDAP entry for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) SearchFilter(org.ldaptive.SearchFilter) SearchResult(org.ldaptive.SearchResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 17 with Audit

use of org.apereo.inspektr.audit.annotation.Audit in project cas by apereo.

the class PolicyBasedAuthenticationManager method authenticate.

@Override
@Audit(action = "AUTHENTICATION", actionResolverName = "AUTHENTICATION_RESOLVER", resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(transaction.getCredentials());
    final AuthenticationBuilder builder = authenticateInternal(transaction);
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(builder);
    final Authentication authentication = builder.build();
    addAuthenticationMethodAttribute(builder, authentication);
    populateAuthenticationMetadataAttributes(builder, transaction);
    invokeAuthenticationPostProcessors(builder, transaction);
    final Authentication auth = builder.build();
    final Principal principal = auth.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(auth);
    }
    LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(auth);
    return auth;
}
Also used : NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 18 with Audit

use of org.apereo.inspektr.audit.annotation.Audit in project cas by apereo.

the class BaseSamlProfileSamlResponseBuilder method build.

@Audit(action = "SAML2_RESPONSE", actionResolverName = "SAML2_RESPONSE_ACTION_RESOLVER", resourceResolverName = "SAML2_RESPONSE_RESOURCE_RESOLVER")
@Override
public T build(final RequestAbstractType authnRequest, final HttpServletRequest request, final HttpServletResponse response, final Object casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String binding) throws SamlException {
    final Assertion assertion = buildSamlAssertion(authnRequest, request, response, casAssertion, service, adaptor, binding);
    final T finalResponse = buildResponse(assertion, casAssertion, authnRequest, service, adaptor, request, response, binding);
    return encodeFinalResponse(request, response, service, adaptor, finalResponse, binding, authnRequest, casAssertion);
}
Also used : EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 19 with Audit

use of org.apereo.inspektr.audit.annotation.Audit in project cas by apereo.

the class DefaultOAuth2UserProfileDataCreator method createFrom.

@Override
@Audit(action = "OAUTH2_USER_PROFILE_DATA", actionResolverName = "OAUTH2_USER_PROFILE_DATA_ACTION_RESOLVER", resourceResolverName = "OAUTH2_USER_PROFILE_DATA_RESOURCE_RESOLVER")
public Map<String, Object> createFrom(final AccessToken accessToken, final J2EContext context) {
    final Principal principal = getAccessTokenAuthenticationPrincipal(accessToken, context);
    final Map<String, Object> map = new HashMap<>();
    map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ID, principal.getId());
    map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ATTRIBUTES, principal.getAttributes());
    finalizeProfileResponse(accessToken, map, principal);
    return map;
}
Also used : HashMap(java.util.HashMap) Principal(org.apereo.cas.authentication.principal.Principal) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 20 with Audit

use of org.apereo.inspektr.audit.annotation.Audit in project cas by apereo.

the class DefaultAuthenticationManager method authenticate.

@Override
@Audit(action = AuditableActions.AUTHENTICATION, actionResolverName = AuditActionResolvers.AUTHENTICATION_RESOLVER, resourceResolverName = AuditResourceResolvers.AUTHENTICATION_RESOURCE_RESOLVER)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
    val result = invokeAuthenticationPreProcessors(transaction);
    if (!result) {
        LOGGER.warn("An authentication pre-processor could not successfully process the authentication transaction");
        throw new AuthenticationException("Authentication pre-processor has failed to process transaction");
    }
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(transaction.getCredentials());
    val builder = authenticateInternal(transaction);
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(builder);
    val authentication = builder.build();
    addAuthenticationMethodAttribute(builder, authentication);
    populateAuthenticationMetadataAttributes(builder, transaction);
    invokeAuthenticationPostProcessors(builder, transaction);
    val auth = builder.build();
    val principal = auth.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(auth);
    }
    LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(auth);
    return auth;
}
Also used : lombok.val(lombok.val) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) Audit(org.apereo.inspektr.audit.annotation.Audit)

Aggregations

Audit (org.apereo.inspektr.audit.annotation.Audit)31 lombok.val (lombok.val)21 Counted (com.codahale.metrics.annotation.Counted)4 Metered (com.codahale.metrics.annotation.Metered)4 Timed (com.codahale.metrics.annotation.Timed)4 Principal (org.apereo.cas.authentication.principal.Principal)4 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)4 HashMap (java.util.HashMap)3 AuditActionResolvers (org.apereo.cas.audit.AuditActionResolvers)3 AuditResourceResolvers (org.apereo.cas.audit.AuditResourceResolvers)3 AuditableActions (org.apereo.cas.audit.AuditableActions)3 UnresolvedPrincipalException (org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException)3 NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)3 ServiceContext (org.apereo.cas.services.ServiceContext)3 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)3 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 AuditableContext (org.apereo.cas.audit.AuditableContext)2 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)2 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)2 UnauthorizedProxyingException (org.apereo.cas.services.UnauthorizedProxyingException)2