Search in sources :

Example 1 with SecurityNotification

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);
}
Also used : ArrayList(java.util.ArrayList) SecurityNotification(io.undertow.security.api.SecurityNotification)

Example 2 with SecurityNotification

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;
}
Also used : Cookie(io.undertow.server.handlers.Cookie) Account(io.undertow.security.idm.Account) NotificationReceiver(io.undertow.security.api.NotificationReceiver) Session(io.undertow.server.session.Session) SecurityNotification(io.undertow.security.api.SecurityNotification)

Example 3 with SecurityNotification

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));
}
Also used : SecurityNotification(io.undertow.security.api.SecurityNotification)

Example 4 with SecurityNotification

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));
}
Also used : SecurityNotification(io.undertow.security.api.SecurityNotification)

Example 5 with SecurityNotification

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;
}
Also used : SecurityNotification(io.undertow.security.api.SecurityNotification)

Aggregations

SecurityNotification (io.undertow.security.api.SecurityNotification)5 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 Account (io.undertow.security.idm.Account)1 Cookie (io.undertow.server.handlers.Cookie)1 Session (io.undertow.server.session.Session)1 ArrayList (java.util.ArrayList)1