GUACAMOLE-210: Refactor source referencing OAuth to OpenID. This extension uses OpenID, not OAuth.

This commit is contained in:
Michael Jumper
2017-02-21 12:43:15 -08:00
parent 1034612a47
commit d04d61225a
12 changed files with 110 additions and 109 deletions

View File

@@ -17,16 +17,16 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth;
package org.apache.guacamole.auth.openid;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import org.apache.guacamole.auth.oauth.conf.ConfigurationService;
import org.apache.guacamole.auth.oauth.form.OAuthTokenField;
import org.apache.guacamole.auth.oauth.token.TokenValidationService;
import org.apache.guacamole.auth.oauth.user.AuthenticatedUser;
import org.apache.guacamole.auth.openid.conf.ConfigurationService;
import org.apache.guacamole.auth.openid.form.TokenField;
import org.apache.guacamole.auth.openid.token.TokenValidationService;
import org.apache.guacamole.auth.openid.user.AuthenticatedUser;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.form.Field;
import org.apache.guacamole.net.auth.Credentials;
@@ -36,7 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Service providing convenience functions for the OAuth AuthenticationProvider
* Service providing convenience functions for the OpenID AuthenticationProvider
* implementation.
*/
public class AuthenticationProviderService {
@@ -47,7 +47,7 @@ public class AuthenticationProviderService {
private final Logger logger = LoggerFactory.getLogger(AuthenticationProviderService.class);
/**
* Service for retrieving OAuth configuration information.
* Service for retrieving OpenID configuration information.
*/
@Inject
private ConfigurationService confService;
@@ -84,10 +84,10 @@ public class AuthenticationProviderService {
String token = null;
// Pull OAuth token from request if present
// Pull OpenID token from request if present
HttpServletRequest request = credentials.getRequest();
if (request != null)
token = request.getParameter(OAuthTokenField.PARAMETER_NAME);
token = request.getParameter(TokenField.PARAMETER_NAME);
// If token provided, validate and produce authenticated user
if (token != null) {
@@ -99,13 +99,13 @@ public class AuthenticationProviderService {
}
// Request OAuth token
// Request OpenID token
throw new GuacamoleInvalidCredentialsException("Invalid login.",
new CredentialsInfo(Arrays.asList(new Field[] {
// OAuth-specific token (will automatically redirect the user
// OpenID-specific token (will automatically redirect the user
// to the authorization page via JavaScript)
new OAuthTokenField(
new TokenField(
confService.getAuthorizationEndpoint(),
confService.getClientID(),
confService.getRedirectURI()

View File

@@ -17,7 +17,7 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth;
package org.apache.guacamole.auth.openid;
import com.google.inject.Guice;
import com.google.inject.Injector;
@@ -29,11 +29,11 @@ import org.apache.guacamole.net.auth.UserContext;
/**
* Guacamole authentication backend which authenticates users using an
* arbitrary external system implementing OAuth. No storage for connections is
* arbitrary external system implementing OpenID. No storage for connections is
* provided - only authentication. Storage must be provided by some other
* extension.
*/
public class OAuthAuthenticationProvider implements AuthenticationProvider {
public class OpenIDAuthenticationProvider implements AuthenticationProvider {
/**
* Injector which will manage the object graph of this authentication
@@ -42,25 +42,25 @@ public class OAuthAuthenticationProvider implements AuthenticationProvider {
private final Injector injector;
/**
* Creates a new OAuthAuthenticationProvider that authenticates users
* against an OAuth service
* Creates a new OpenIDAuthenticationProvider that authenticates users
* against an OpenID service.
*
* @throws GuacamoleException
* If a required property is missing, or an error occurs while parsing
* a property.
*/
public OAuthAuthenticationProvider() throws GuacamoleException {
public OpenIDAuthenticationProvider() throws GuacamoleException {
// Set up Guice injector.
injector = Guice.createInjector(
new OAuthAuthenticationProviderModule(this)
new OpenIDAuthenticationProviderModule(this)
);
}
@Override
public String getIdentifier() {
return "oauth";
return "openid";
}
@Override

View File

@@ -17,20 +17,20 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth;
package org.apache.guacamole.auth.openid;
import com.google.inject.AbstractModule;
import org.apache.guacamole.auth.oauth.conf.ConfigurationService;
import org.apache.guacamole.auth.oauth.token.TokenValidationService;
import org.apache.guacamole.auth.openid.conf.ConfigurationService;
import org.apache.guacamole.auth.openid.token.TokenValidationService;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.environment.LocalEnvironment;
import org.apache.guacamole.net.auth.AuthenticationProvider;
/**
* Guice module which configures OAuth-specific injections.
* Guice module which configures openid-specific injections.
*/
public class OAuthAuthenticationProviderModule extends AbstractModule {
public class OpenIDAuthenticationProviderModule extends AbstractModule {
/**
* Guacamole server environment.
@@ -38,14 +38,14 @@ public class OAuthAuthenticationProviderModule extends AbstractModule {
private final Environment environment;
/**
* A reference to the OAuthAuthenticationProvider on behalf of which this
* A reference to the OpenIDAuthenticationProvider on behalf of which this
* module has configured injection.
*/
private final AuthenticationProvider authProvider;
/**
* Creates a new OAuth authentication provider module which configures
* injection for the OAuthAuthenticationProvider.
* Creates a new OpenID authentication provider module which configures
* injection for the OpenIDAuthenticationProvider.
*
* @param authProvider
* The AuthenticationProvider for which injection is being configured.
@@ -54,7 +54,7 @@ public class OAuthAuthenticationProviderModule extends AbstractModule {
* If an error occurs while retrieving the Guacamole server
* environment.
*/
public OAuthAuthenticationProviderModule(AuthenticationProvider authProvider)
public OpenIDAuthenticationProviderModule(AuthenticationProvider authProvider)
throws GuacamoleException {
// Get local environment
@@ -72,7 +72,7 @@ public class OAuthAuthenticationProviderModule extends AbstractModule {
bind(AuthenticationProvider.class).toInstance(authProvider);
bind(Environment.class).toInstance(environment);
// Bind OAuth-specific services
// Bind openid-specific services
bind(ConfigurationService.class);
bind(TokenValidationService.class);

View File

@@ -17,14 +17,15 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth.conf;
package org.apache.guacamole.auth.openid.conf;
import com.google.inject.Inject;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment;
/**
* Service for retrieving configuration information regarding the OAuth service.
* Service for retrieving configuration information regarding the OpenID
* service.
*/
public class ConfigurationService {
@@ -35,11 +36,11 @@ public class ConfigurationService {
private Environment environment;
/**
* Returns the authorization endpoint (URI) of the OAuth service as
* Returns the authorization endpoint (URI) of the OpenID service as
* configured with guacamole.properties.
*
* @return
* The authorization endpoint of the OAuth service, as configured with
* The authorization endpoint of the OpenID service, as configured with
* guacamole.properties.
*
* @throws GuacamoleException
@@ -47,17 +48,17 @@ public class ConfigurationService {
* endpoint property is missing.
*/
public String getAuthorizationEndpoint() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_AUTHORIZATION_ENDPOINT);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_AUTHORIZATION_ENDPOINT);
}
/**
* Returns the OAuth client ID which should be submitted to the OAuth
* Returns the OpenID client ID which should be submitted to the OpenID
* service when necessary, as configured with guacamole.properties. This
* value is typically provided by the OAuth service when OAuth credentials
* value is typically provided by the OpenID service when OpenID credentials
* are generated for your application.
*
* @return
* The client ID to use when communicating with the OAuth service,
* The client ID to use when communicating with the OpenID service,
* as configured with guacamole.properties.
*
* @throws GuacamoleException
@@ -65,17 +66,17 @@ public class ConfigurationService {
* property is missing.
*/
public String getClientID() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_CLIENT_ID);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_CLIENT_ID);
}
/**
* Returns the URI that the OAuth service should redirect to after
* Returns the URI that the OpenID service should redirect to after
* the authentication process is complete, as configured with
* guacamole.properties. This must be the full URL that a user would enter
* into their browser to access Guacamole.
*
* @return
* The client secret to use when communicating with the OAuth service,
* The client secret to use when communicating with the OpenID service,
* as configured with guacamole.properties.
*
* @throws GuacamoleException
@@ -83,7 +84,7 @@ public class ConfigurationService {
* property is missing.
*/
public String getRedirectURI() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_REDIRECT_URI);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_REDIRECT_URI);
}
/**
@@ -99,7 +100,7 @@ public class ConfigurationService {
* is missing.
*/
public String getIssuer() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_ISSUER);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_ISSUER);
}
/**
@@ -117,7 +118,7 @@ public class ConfigurationService {
* property is missing.
*/
public String getJWKSEndpoint() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_JWKS_ENDPOINT);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_JWKS_ENDPOINT);
}
/**
@@ -133,7 +134,7 @@ public class ConfigurationService {
* type property is missing.
*/
public String getUsernameClaimType() throws GuacamoleException {
return environment.getRequiredProperty(OAuthGuacamoleProperties.OAUTH_USERNAME_CLAIM_TYPE);
return environment.getRequiredProperty(OpenIDGuacamoleProperties.OPENID_USERNAME_CLAIM_TYPE);
}
}

View File

@@ -17,30 +17,30 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth.conf;
package org.apache.guacamole.auth.openid.conf;
import org.apache.guacamole.properties.StringGuacamoleProperty;
/**
* Provides properties required for use of the OAuth authentication provider.
* These properties will be read from guacamole.properties when the OAuth
* Provides properties required for use of the OpenID authentication provider.
* These properties will be read from guacamole.properties when the OpenID
* authentication provider is used.
*/
public class OAuthGuacamoleProperties {
public class OpenIDGuacamoleProperties {
/**
* This class should not be instantiated.
*/
private OAuthGuacamoleProperties() {}
private OpenIDGuacamoleProperties() {}
/**
* The authorization endpoint (URI) of the OAuth service.
* The authorization endpoint (URI) of the OpenID service.
*/
public static final StringGuacamoleProperty OAUTH_AUTHORIZATION_ENDPOINT =
public static final StringGuacamoleProperty OPENID_AUTHORIZATION_ENDPOINT =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-authorization-endpoint"; }
public String getName() { return "openid-authorization-endpoint"; }
};
@@ -48,22 +48,22 @@ public class OAuthGuacamoleProperties {
* The endpoint (URI) of the JWKS service which defines how received ID
* tokens (JWTs) shall be validated.
*/
public static final StringGuacamoleProperty OAUTH_JWKS_ENDPOINT =
public static final StringGuacamoleProperty OPENID_JWKS_ENDPOINT =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-jwks-endpoint"; }
public String getName() { return "openid-jwks-endpoint"; }
};
/**
* The issuer to expect for all received ID tokens.
*/
public static final StringGuacamoleProperty OAUTH_ISSUER =
public static final StringGuacamoleProperty OPENID_ISSUER =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-issuer"; }
public String getName() { return "openid-issuer"; }
};
@@ -71,37 +71,37 @@ public class OAuthGuacamoleProperties {
* The claim type which contains the authenticated user's username within
* any valid JWT.
*/
public static final StringGuacamoleProperty OAUTH_USERNAME_CLAIM_TYPE =
public static final StringGuacamoleProperty OPENID_USERNAME_CLAIM_TYPE =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-username-claim-type"; }
public String getName() { return "openid-username-claim-type"; }
};
/**
* OAuth client ID which should be submitted to the OAuth service when
* necessary. This value is typically provided by the OAuth service when
* OAuth credentials are generated for your application.
* OpenID client ID which should be submitted to the OpenID service when
* necessary. This value is typically provided by the OpenID service when
* OpenID credentials are generated for your application.
*/
public static final StringGuacamoleProperty OAUTH_CLIENT_ID =
public static final StringGuacamoleProperty OPENID_CLIENT_ID =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-client-id"; }
public String getName() { return "openid-client-id"; }
};
/**
* The URI that the OAuth service should redirect to after the
* The URI that the OpenID service should redirect to after the
* authentication process is complete. This must be the full URL that a
* user would enter into their browser to access Guacamole.
*/
public static final StringGuacamoleProperty OAUTH_REDIRECT_URI =
public static final StringGuacamoleProperty OPENID_REDIRECT_URI =
new StringGuacamoleProperty() {
@Override
public String getName() { return "oauth-redirect-uri"; }
public String getName() { return "openid-redirect-uri"; }
};

View File

@@ -17,7 +17,7 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth.form;
package org.apache.guacamole.auth.openid.form;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
@@ -26,15 +26,15 @@ import java.security.SecureRandom;
import org.apache.guacamole.form.Field;
/**
* Field definition which represents the token returned by an OAuth service.
* Field definition which represents the token returned by an OpenID service.
* Within the user interface, this will be rendered as an appropriate "Log in
* with ..." button which links to the OAuth service.
* with ..." button which links to the OpenID service.
*/
public class OAuthTokenField extends Field {
public class TokenField extends Field {
/**
* The standard HTTP parameter which will be included within the URL by all
* OAuth services upon successful authentication and redirect.
* OpenID services upon successful authentication and redirect.
*/
public static final String PARAMETER_NAME = "id_token";
@@ -61,31 +61,31 @@ public class OAuthTokenField extends Field {
}
/**
* Creates a new OAuth "id_token" field which links to the given OAuth
* Creates a new OpenID "id_token" field which links to the given OpenID
* service using the provided client ID. Successful authentication at the
* OAuth service will result in the client being redirected to the specified
* redirect URI. The OAuth token will be embedded in the fragment (the part
* OpenID service will result in the client being redirected to the specified
* redirect URI. The OpenID token will be embedded in the fragment (the part
* following the hash symbol) of that URI, which the JavaScript side of
* this extension will move to the query parameters.
*
* @param authorizationEndpoint
* The full URL of the endpoint accepting OAuth authentication
* The full URL of the endpoint accepting OpenID authentication
* requests.
*
* @param clientID
* The ID of the OAuth client. This is normally determined ahead of
* time by the OAuth service through some manual credential request
* The ID of the OpenID client. This is normally determined ahead of
* time by the OpenID service through some manual credential request
* procedure.
*
* @param redirectURI
* The URI that the OAuth service should redirect to upon successful
* The URI that the OpenID service should redirect to upon successful
* authentication.
*/
public OAuthTokenField(String authorizationEndpoint, String clientID,
public TokenField(String authorizationEndpoint, String clientID,
String redirectURI) {
// Init base field properties
super(PARAMETER_NAME, "GUAC_OAUTH_TOKEN");
super(PARAMETER_NAME, "GUAC_OPENID_TOKEN");
// Build authorization URI from given values
try {
@@ -106,7 +106,7 @@ public class OAuthTokenField extends Field {
/**
* Returns the full URI that this field should link to when a new token
* needs to be obtained from the OAuth service.
* needs to be obtained from the OpenID service.
*
* @return
* The full URI that this field should link to.

View File

@@ -17,10 +17,10 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth.token;
package org.apache.guacamole.auth.openid.token;
import com.google.inject.Inject;
import org.apache.guacamole.auth.oauth.conf.ConfigurationService;
import org.apache.guacamole.auth.openid.conf.ConfigurationService;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleSecurityException;
import org.apache.guacamole.GuacamoleServerException;
@@ -34,12 +34,12 @@ import org.jose4j.keys.resolvers.HttpsJwksVerificationKeyResolver;
/**
* Service for validating ID tokens forwarded to us by the client, verifying
* that they did indeed come from the OAuth service.
* that they did indeed come from the OpenID service.
*/
public class TokenValidationService {
/**
* Service for retrieving OAuth configuration information.
* Service for retrieving OpenID configuration information.
*/
@Inject
private ConfigurationService confService;

View File

@@ -17,7 +17,7 @@
* under the License.
*/
package org.apache.guacamole.auth.oauth.user;
package org.apache.guacamole.auth.openid.user;
import com.google.inject.Inject;
import org.apache.guacamole.net.auth.AbstractAuthenticatedUser;
@@ -25,8 +25,8 @@ import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Credentials;
/**
* An OAuth-specific implementation of AuthenticatedUser, associating a
* username and particular set of credentials with the OAuth authentication
* An openid-specific implementation of AuthenticatedUser, associating a
* username and particular set of credentials with the OpenID authentication
* provider.
*/
public class AuthenticatedUser extends AbstractAuthenticatedUser {

View File

@@ -2,17 +2,17 @@
"guacamoleVersion" : "0.9.11-incubating",
"name" : "OAuth Authentication Extension",
"namespace" : "guac-oauth",
"name" : "OpenID Authentication Extension",
"namespace" : "guac-openid",
"authProviders" : [
"org.apache.guacamole.auth.oauth.OAuthAuthenticationProvider"
"org.apache.guacamole.auth.openid.OpenIDAuthenticationProvider"
],
"js" : [
"oauthModule.js",
"oauthController.js",
"oauthConfig.js"
"openidModule.js",
"openidController.js",
"openidConfig.js"
]
}

View File

@@ -18,16 +18,16 @@
*/
/**
* Config block which registers OAuth-specific field types.
* Config block which registers openid-specific field types.
*/
angular.module('guacOAuth').config(['formServiceProvider',
function guacOAuthConfig(formServiceProvider) {
angular.module('guacOpenID').config(['formServiceProvider',
function guacOpenIDConfig(formServiceProvider) {
// Define field for token from OAuth service
formServiceProvider.registerFieldType("GUAC_OAUTH_TOKEN", {
// Define field for token from OpenID service
formServiceProvider.registerFieldType("GUAC_OPENID_TOKEN", {
template : '',
controller : 'guacOAuthController',
module : 'guacOAuth'
controller : 'guacOpenIDController',
module : 'guacOpenID'
});
}]);

View File

@@ -18,11 +18,11 @@
*/
/**
* Controller for the "GUAC_OAUTH_TOKEN" field which simply redirects the user
* Controller for the "GUAC_OPENID_TOKEN" field which simply redirects the user
* immediately to the authorization URI.
*/
angular.module('guacOAuth').controller('guacOAuthController', ['$scope',
function guacOAuthController($scope) {
angular.module('guacOpenID').controller('guacOpenIDController', ['$scope',
function guacOpenIDController($scope) {
// Redirect to authorization URI
window.location = $scope.field.authorizationURI;

View File

@@ -18,11 +18,11 @@
*/
/**
* Module which provides handling for OAuth authentication.
* Module which provides handling for OpenID authentication.
*/
angular.module('guacOAuth', [
angular.module('guacOpenID', [
'form'
]);
// Ensure the OAuth module is loaded along with the rest of the app
angular.module('index').requires.push('guacOAuth');
// Ensure the OpenID module is loaded along with the rest of the app
angular.module('index').requires.push('guacOpenID');