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