use of io.undertow.security.api.SecurityNotification in project undertow by undertow-io.
the class AuthenticationTestBase method assertNotifiactions.
protected static void assertNotifiactions(final SecurityNotification.EventType... eventTypes) {
List<SecurityNotification> notifications = auditReceiver.takeNotifications();
assertEquals("A single notification is expected.", eventTypes.length, notifications.size());
final List<SecurityNotification.EventType> types = new ArrayList<>();
for (SecurityNotification i : notifications) {
types.add(i.getEventType());
}
assertEquals("Expected EventType not matched.", Arrays.asList(eventTypes), types);
}
use of io.undertow.security.api.SecurityNotification in project undertow by undertow-io.
the class SingleSignOnAuthenticationMechanism method authenticate.
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
Cookie cookie = exchange.getRequestCookies().get(cookieName);
if (cookie != null) {
final String ssoId = cookie.getValue();
log.tracef("Found SSO cookie %s", ssoId);
try (SingleSignOn sso = this.singleSignOnManager.findSingleSignOn(ssoId)) {
if (sso != null) {
if (log.isTraceEnabled()) {
log.tracef("SSO session with ID: %s found.", ssoId);
}
Account verified = getIdentityManager(securityContext).verify(sso.getAccount());
if (verified == null) {
if (log.isTraceEnabled()) {
log.tracef("Account not found. Returning 'not attempted' here.");
}
//we return not attempted here to allow other mechanisms to proceed as normal
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
final Session session = getSession(exchange);
registerSessionIfRequired(sso, session);
securityContext.authenticationComplete(verified, sso.getMechanismName(), false);
securityContext.registerNotificationReceiver(new NotificationReceiver() {
@Override
public void handleNotification(SecurityNotification notification) {
if (notification.getEventType() == SecurityNotification.EventType.LOGGED_OUT) {
singleSignOnManager.removeSingleSignOn(sso);
}
}
});
log.tracef("Authenticated account %s using SSO", verified.getPrincipal().getName());
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
}
clearSsoCookie(exchange);
}
exchange.addResponseWrapper(responseListener);
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
use of io.undertow.security.api.SecurityNotification in project undertow by undertow-io.
the class AbstractSecurityContext method authenticationComplete.
protected void authenticationComplete(Account account, String mechanism, boolean programatic, final boolean cachingRequired) {
this.account = account;
this.mechanismName = mechanism;
UndertowLogger.SECURITY_LOGGER.debugf("Authenticated as %s, roles %s", account.getPrincipal().getName(), account.getRoles());
sendNoticiation(new SecurityNotification(exchange, EventType.AUTHENTICATED, account, mechanism, programatic, MESSAGES.userAuthenticated(account.getPrincipal().getName()), cachingRequired));
}
use of io.undertow.security.api.SecurityNotification in project undertow by undertow-io.
the class AbstractSecurityContext method authenticationFailed.
@Override
public void authenticationFailed(String message, String mechanism) {
UndertowLogger.SECURITY_LOGGER.debugf("Authentication failed with message %s and mechanism %s for %s", message, mechanism, exchange);
sendNoticiation(new SecurityNotification(exchange, EventType.FAILED_AUTHENTICATION, null, mechanism, false, message, true));
}
use of io.undertow.security.api.SecurityNotification in project undertow by undertow-io.
the class AbstractSecurityContext method logout.
@Override
public void logout() {
if (!isAuthenticated()) {
return;
}
UndertowLogger.SECURITY_LOGGER.debugf("Logged out %s", exchange);
sendNoticiation(new SecurityNotification(exchange, SecurityNotification.EventType.LOGGED_OUT, account, mechanismName, true, MESSAGES.userLoggedOut(account.getPrincipal().getName()), true));
this.account = null;
this.mechanismName = null;
}
Aggregations