Search in sources :

Example 1 with Event

use of org.springframework.webflow.execution.Event in project cas by apereo.

the class CasCoreAuditConfiguration method nullableReturnValueResourceResolver.

@Bean
public AuditResourceResolver nullableReturnValueResourceResolver() {
    return new AuditResourceResolver() {

        @Override
        public String[] resolveFrom(final JoinPoint joinPoint, final Object o) {
            if (o == null) {
                return new String[0];
            }
            if (o instanceof Event) {
                final Event event = Event.class.cast(o);
                final String sourceName = event.getSource().getClass().getSimpleName();
                final String result = new ToStringBuilder(event, ToStringStyle.NO_CLASS_NAME_STYLE).append("event", event.getId()).append("timestamp", new Date(event.getTimestamp())).append("source", sourceName).toString();
                return new String[] { result };
            }
            return returnValueResourceResolver().resolveFrom(joinPoint, o);
        }

        @Override
        public String[] resolveFrom(final JoinPoint joinPoint, final Exception e) {
            return returnValueResourceResolver().resolveFrom(joinPoint, e);
        }
    };
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) AuditResourceResolver(org.apereo.inspektr.audit.spi.AuditResourceResolver) Event(org.springframework.webflow.execution.Event) Date(java.util.Date) JoinPoint(org.aspectj.lang.JoinPoint) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with Event

use of org.springframework.webflow.execution.Event in project cas by apereo.

the class AbstractCasWebflowEventResolver method validateEventIdForMatchingTransitionInContext.

/**
     * Validate event for transition.
     *
     * @param eventId    the event id
     * @param context    the context
     * @param attributes the attributes
     * @return the event
     */
protected Event validateEventIdForMatchingTransitionInContext(final String eventId, final RequestContext context, final Map<String, Object> attributes) {
    try {
        final AttributeMap<Object> attributesMap = new LocalAttributeMap<>(attributes);
        final Event event = new Event(this, eventId, attributesMap);
        LOGGER.debug("Resulting event id is [{}]. Locating transitions in the context for that event id...", event.getId());
        final TransitionDefinition def = context.getMatchingTransition(event.getId());
        if (def == null) {
            LOGGER.warn("Transition definition cannot be found for event [{}]", event.getId());
            throw new AuthenticationException();
        }
        LOGGER.debug("Found matching transition [{}] with target [{}] for event [{}] with attributes [{}].", def.getId(), def.getTargetStateId(), event.getId(), event.getAttributes());
        return event;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Event(org.springframework.webflow.execution.Event) TransitionDefinition(org.springframework.webflow.definition.TransitionDefinition) AuthenticationException(org.apereo.cas.authentication.AuthenticationException)

Example 3 with Event

use of org.springframework.webflow.execution.Event in project cas by apereo.

the class AbstractCasWebflowEventResolver method resolveEventViaSingleAttribute.

private Set<Event> resolveEventViaSingleAttribute(final Principal principal, final Object attributeValue, final RegisteredService service, final RequestContext context, final MultifactorAuthenticationProvider provider, final Predicate<String> predicate) {
    try {
        if (attributeValue instanceof String) {
            LOGGER.debug("Attribute value [{}] is a single-valued attribute", attributeValue);
            if (predicate.test((String) attributeValue)) {
                LOGGER.debug("Attribute value predicate [{}] has matched the [{}]", predicate, attributeValue);
                LOGGER.debug("Attempting to isAvailable multifactor authentication provider [{}] for [{}]", provider, service);
                if (provider.isAvailable(service)) {
                    LOGGER.debug("Provider [{}] is successfully verified", provider);
                    final String id = provider.getId();
                    final Event event = validateEventIdForMatchingTransitionInContext(id, context, buildEventAttributeMap(principal, service, provider));
                    return Collections.singleton(event);
                } else {
                    LOGGER.debug("Provider [{}] could not be verified", provider);
                }
            } else {
                LOGGER.debug("Attribute value predicate [{}] could not match the [{}]", predicate, attributeValue);
            }
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
    LOGGER.debug("Attribute value [{}] is not a single-valued attribute", attributeValue);
    return null;
}
Also used : Event(org.springframework.webflow.execution.Event) AuthenticationException(org.apereo.cas.authentication.AuthenticationException)

Example 4 with Event

use of org.springframework.webflow.execution.Event in project cas by apereo.

the class AbstractCasWebflowEventResolver method resolveEventViaMultivaluedAttribute.

private Set<Event> resolveEventViaMultivaluedAttribute(final Principal principal, final Object attributeValue, final RegisteredService service, final RequestContext context, final MultifactorAuthenticationProvider provider, final Predicate<String> predicate) {
    final Set<Event> events = new HashSet<>();
    if (attributeValue instanceof Collection) {
        LOGGER.debug("Attribute value [{}] is a multi-valued attribute", attributeValue);
        final Collection<String> values = (Collection<String>) attributeValue;
        values.forEach(value -> {
            try {
                if (predicate.test(value)) {
                    LOGGER.debug("Attribute value predicate [{}] has successfully matched the [{}]", predicate, value);
                    LOGGER.debug("Attempting to verify multifactor authentication provider [{}] for [{}]", provider, service);
                    if (provider.isAvailable(service)) {
                        LOGGER.debug("Provider [{}] is successfully verified", provider);
                        final String id = provider.getId();
                        final Event event = validateEventIdForMatchingTransitionInContext(id, context, buildEventAttributeMap(principal, service, provider));
                        events.add(event);
                    }
                } else {
                    LOGGER.debug("Attribute value predicate [{}] could not match the [{}]", predicate, value);
                }
            } catch (final Exception e) {
                LOGGER.debug("Ignoring [{}] since no matching transition could be found", value);
            }
        });
        return events;
    }
    LOGGER.debug("Attribute value [{}] of type [{}] is not a multi-valued attribute", attributeValue, attributeValue.getClass());
    return null;
}
Also used : Event(org.springframework.webflow.execution.Event) Collection(java.util.Collection) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) HashSet(java.util.HashSet)

Example 5 with Event

use of org.springframework.webflow.execution.Event in project cas by apereo.

the class AdaptiveMultifactorAuthenticationPolicyEventResolver method resolveInternal.

@Override
public Set<Event> resolveInternal(final RequestContext context) {
    final RegisteredService service = resolveRegisteredServiceInRequestContext(context);
    final Authentication authentication = WebUtils.getAuthentication(context);
    if (service == null || authentication == null) {
        LOGGER.debug("No service or authentication is available to determine event for principal");
        return null;
    }
    if (multifactorMap == null || multifactorMap.isEmpty()) {
        LOGGER.debug("Adaptive authentication is not configured to require multifactor authentication");
        return null;
    }
    final Map<String, MultifactorAuthenticationProvider> providerMap = WebUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
    if (providerMap == null || providerMap.isEmpty()) {
        LOGGER.error("No multifactor authentication providers are available in the application context");
        throw new AuthenticationException();
    }
    final Set<Event> providerFound = checkRequireMultifactorProvidersForRequest(context, service, authentication);
    if (providerFound != null && !providerFound.isEmpty()) {
        LOGGER.warn("Found multifactor authentication providers [{}] required for this authentication event", providerFound);
        return providerFound;
    }
    return null;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Authentication(org.apereo.cas.authentication.Authentication) Event(org.springframework.webflow.execution.Event) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider)

Aggregations

Event (org.springframework.webflow.execution.Event)56 Test (org.junit.Test)26 MockRequestContext (org.springframework.webflow.test.MockRequestContext)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 Authentication (org.apereo.cas.authentication.Authentication)13 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)13 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)13 RegisteredService (org.apereo.cas.services.RegisteredService)12 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)11 MockServletContext (org.springframework.mock.web.MockServletContext)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)8 LogoutProperties (org.apereo.cas.configuration.model.core.logout.LogoutProperties)8 WebUtils (org.apereo.cas.web.support.WebUtils)8 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)8 RequestContext (org.springframework.webflow.execution.RequestContext)8 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Map (java.util.Map)6