mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUACAMOLE-1780: Allow SAML, SSL sessions to be resumed after another auth provider vetoes the auth attempt.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.guacamole.auth.saml;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.auth.saml.acs.SAMLAuthenticationSessionManager;
|
||||
import org.apache.guacamole.net.event.AuthenticationFailureEvent;
|
||||
import org.apache.guacamole.net.event.AuthenticationSuccessEvent;
|
||||
import org.apache.guacamole.net.event.listener.Listener;
|
||||
|
||||
/**
|
||||
* A Listener that will reactivate or invalidate SAML auth sessions depending on
|
||||
* overall auth success or failure.
|
||||
*/
|
||||
public class AuthenticationEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* Manager of active SAML authentication attempts.
|
||||
*
|
||||
* Requires static injection due to the fact that the webapp just calls the
|
||||
* constructor directly when creating new Listeners. The instances will not
|
||||
* be constructed by guice.
|
||||
*/
|
||||
@Inject
|
||||
private static SAMLAuthenticationSessionManager sessionManager;
|
||||
|
||||
@Override
|
||||
public void handleEvent(Object event) throws GuacamoleException {
|
||||
|
||||
if (event instanceof AuthenticationSuccessEvent)
|
||||
|
||||
// After an auth attempt has fully succeeded, invalidate the session
|
||||
// associated with the successful login event so it can't be reused
|
||||
sessionManager.invalidateSession(
|
||||
AuthenticationProviderService.getSessionIdentifier(
|
||||
((AuthenticationSuccessEvent) event).getCredentials()));
|
||||
|
||||
else if (event instanceof AuthenticationFailureEvent)
|
||||
|
||||
// If the SSL auth succeeded, but other auth providers failed to
|
||||
// authenticate the user associated with the credentials in this
|
||||
// failure event, they may wish to make another login attempt. To
|
||||
// avoid an infinite login attempt loop, re-enable the session
|
||||
// associated with these credentials, allowing the auth attempt to be
|
||||
// resumed without requiring another round trip to the SAML provider.
|
||||
sessionManager.reactivateSession(
|
||||
AuthenticationProviderService.getSessionIdentifier(
|
||||
((AuthenticationFailureEvent) event).getCredentials()));
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -69,6 +69,26 @@ public class AuthenticationProviderService implements SSOAuthenticationProviderS
|
||||
@Inject
|
||||
private SAMLService saml;
|
||||
|
||||
/**
|
||||
* Return the value of the session identifier associated with the given
|
||||
* credentials, or null if no session identifier is found in the
|
||||
* credentials.
|
||||
*
|
||||
* @param credentials The credentials from which to extract the session
|
||||
* identifier.
|
||||
*
|
||||
* @return The session identifier associated with the given credentials, or
|
||||
* null if no identifier is found.
|
||||
*/
|
||||
public static String getSessionIdentifier(Credentials credentials) {
|
||||
|
||||
// Return the session identifier from the request params, if set, or
|
||||
// null otherwise
|
||||
return credentials != null && credentials.getRequest() != null
|
||||
? credentials.getRequest().getParameter(AUTH_SESSION_QUERY_PARAM)
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SAMLAuthenticatedUser authenticateUser(Credentials credentials)
|
||||
throws GuacamoleException {
|
||||
@@ -80,7 +100,9 @@ public class AuthenticationProviderService implements SSOAuthenticationProviderS
|
||||
return null;
|
||||
|
||||
// Use established SAML identity if already provided by the SAML IdP
|
||||
AssertedIdentity identity = sessionManager.getIdentity(request.getParameter(AUTH_SESSION_QUERY_PARAM));
|
||||
AssertedIdentity identity = sessionManager.getIdentity(
|
||||
getSessionIdentifier(credentials));
|
||||
|
||||
if (identity != null) {
|
||||
|
||||
// Back-port the username to the credentials
|
||||
|
@@ -36,6 +36,8 @@ public class SAMLAuthenticationProviderModule extends AbstractModule {
|
||||
bind(ConfigurationService.class);
|
||||
bind(SAMLAuthenticationSessionManager.class);
|
||||
bind(SAMLService.class);
|
||||
|
||||
requestStaticInjection(AuthenticationEventListener.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,6 +9,10 @@
|
||||
"org.apache.guacamole.auth.saml.SAMLAuthenticationProvider"
|
||||
],
|
||||
|
||||
"listeners" : [
|
||||
"org.apache.guacamole.auth.saml.AuthenticationEventListener"
|
||||
],
|
||||
|
||||
"css" : [
|
||||
"styles/sso-providers.css"
|
||||
],
|
||||
|
Reference in New Issue
Block a user