GUACAMOLE-678: Use new URI property for existing configuration items.

This commit is contained in:
Virtually Nick
2019-03-24 15:53:53 -04:00
parent d761f55cf1
commit 704c7b6d81
9 changed files with 64 additions and 65 deletions

View File

@@ -261,6 +261,14 @@
<version>2.5</version> <version>2.5</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Jersey - JAX-RS Implementation -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>

View File

@@ -19,7 +19,7 @@
package org.apache.guacamole.auth.cas.conf; package org.apache.guacamole.auth.cas.conf;
import org.apache.guacamole.properties.StringGuacamoleProperty; import org.apache.guacamole.properties.UriGuacamoleProperty;
/** /**
* Provides properties required for use of the CAS authentication provider. * Provides properties required for use of the CAS authentication provider.
@@ -36,8 +36,8 @@ public class CASGuacamoleProperties {
/** /**
* The authorization endpoint (URI) of the CAS service. * The authorization endpoint (URI) of the CAS service.
*/ */
public static final StringGuacamoleProperty CAS_AUTHORIZATION_ENDPOINT = public static final UriGuacamoleProperty CAS_AUTHORIZATION_ENDPOINT =
new StringGuacamoleProperty() { new UriGuacamoleProperty() {
@Override @Override
public String getName() { return "cas-authorization-endpoint"; } public String getName() { return "cas-authorization-endpoint"; }
@@ -49,8 +49,8 @@ public class CASGuacamoleProperties {
* authentication process is complete. This must be the full URL that a * authentication process is complete. This must be the full URL that a
* user would enter into their browser to access Guacamole. * user would enter into their browser to access Guacamole.
*/ */
public static final StringGuacamoleProperty CAS_REDIRECT_URI = public static final UriGuacamoleProperty CAS_REDIRECT_URI =
new StringGuacamoleProperty() { new UriGuacamoleProperty() {
@Override @Override
public String getName() { return "cas-redirect-uri"; } public String getName() { return "cas-redirect-uri"; }

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.auth.cas.conf; package org.apache.guacamole.auth.cas.conf;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.net.URI;
import java.security.PrivateKey; import java.security.PrivateKey;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.Environment;
@@ -47,7 +48,7 @@ public class ConfigurationService {
* If guacamole.properties cannot be parsed, or if the authorization * If guacamole.properties cannot be parsed, or if the authorization
* endpoint property is missing. * endpoint property is missing.
*/ */
public String getAuthorizationEndpoint() throws GuacamoleException { public URI getAuthorizationEndpoint() throws GuacamoleException {
return environment.getRequiredProperty(CASGuacamoleProperties.CAS_AUTHORIZATION_ENDPOINT); return environment.getRequiredProperty(CASGuacamoleProperties.CAS_AUTHORIZATION_ENDPOINT);
} }
@@ -65,7 +66,7 @@ public class ConfigurationService {
* If guacamole.properties cannot be parsed, or if the redirect URI * If guacamole.properties cannot be parsed, or if the redirect URI
* property is missing. * property is missing.
*/ */
public String getRedirectURI() throws GuacamoleException { public URI getRedirectURI() throws GuacamoleException {
return environment.getRequiredProperty(CASGuacamoleProperties.CAS_REDIRECT_URI); return environment.getRequiredProperty(CASGuacamoleProperties.CAS_REDIRECT_URI);
} }

View File

@@ -19,8 +19,8 @@
package org.apache.guacamole.auth.cas.form; package org.apache.guacamole.auth.cas.form;
import java.io.UnsupportedEncodingException; import java.net.URI;
import java.net.URLEncoder; import javax.ws.rs.core.UriBuilder;
import org.apache.guacamole.form.Field; import org.apache.guacamole.form.Field;
@@ -47,7 +47,7 @@ public class CASTicketField extends Field {
/** /**
* The full URI which the field should link to. * The full URI which the field should link to.
*/ */
private final String authorizationURI; private final URI authorizationURI;
/** /**
* Creates a new CAS "ticket" field which links to the given CAS * Creates a new CAS "ticket" field which links to the given CAS
@@ -65,29 +65,15 @@ public class CASTicketField extends Field {
* The URI that the CAS service should redirect to upon successful * The URI that the CAS service should redirect to upon successful
* authentication. * authentication.
*/ */
public CASTicketField(String authorizationEndpoint, String redirectURI) { public CASTicketField(URI authorizationEndpoint, URI redirectURI) {
// Init base field properties // Init base field properties
super(PARAMETER_NAME, "GUAC_CAS_TICKET"); super(PARAMETER_NAME, "GUAC_CAS_TICKET");
// Build authorization URI from given values this.authorizationURI = UriBuilder.fromUri(authorizationEndpoint)
try { .path(CAS_LOGIN_URI)
final StringBuilder sb = new StringBuilder(); .queryParam("service", redirectURI)
sb.append(authorizationEndpoint); .build();
// user might configure the endpoint with a trailing slash
if (sb.charAt(sb.length() - 1) != '/') {
sb.append('/');
}
sb.append(CAS_LOGIN_URI);
sb.append("?service=");
sb.append(URLEncoder.encode(redirectURI, "UTF-8"));
this.authorizationURI = sb.toString();
}
// Java is required to provide UTF-8 support
catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException("Unexpected lack of UTF-8 support.", e);
}
} }
@@ -99,7 +85,7 @@ public class CASTicketField extends Field {
* The full URI that this field should link to. * The full URI that this field should link to.
*/ */
public String getAuthorizationURI() { public String getAuthorizationURI() {
return authorizationURI; return authorizationURI.toString();
} }
} }

View File

@@ -21,6 +21,7 @@ package org.apache.guacamole.auth.cas.ticket;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.net.URI;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey; import java.security.PrivateKey;
@@ -83,13 +84,13 @@ public class TicketValidationService {
// Retrieve the configured CAS URL, establish a ticket validator, // Retrieve the configured CAS URL, establish a ticket validator,
// and then attempt to validate the supplied ticket. If that succeeds, // and then attempt to validate the supplied ticket. If that succeeds,
// grab the principal returned by the validator. // grab the principal returned by the validator.
String casServerUrl = confService.getAuthorizationEndpoint(); URI casServerUrl = confService.getAuthorizationEndpoint();
Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl); Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl.toString());
validator.setAcceptAnyProxy(true); validator.setAcceptAnyProxy(true);
validator.setEncoding("UTF-8"); validator.setEncoding("UTF-8");
try { try {
String confRedirectURI = confService.getRedirectURI(); URI confRedirectURI = confService.getRedirectURI();
Assertion a = validator.validate(ticket, confRedirectURI); Assertion a = validator.validate(ticket, confRedirectURI.toString());
AttributePrincipal principal = a.getPrincipal(); AttributePrincipal principal = a.getPrincipal();
// Retrieve username and set the credentials. // Retrieve username and set the credentials.

View File

@@ -246,6 +246,14 @@
<version>2.5</version> <version>2.5</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Jersey - JAX-RS Implementation -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>

View File

@@ -20,10 +20,12 @@
package org.apache.guacamole.auth.openid.conf; package org.apache.guacamole.auth.openid.conf;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.net.URI;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.properties.IntegerGuacamoleProperty; import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty; import org.apache.guacamole.properties.StringGuacamoleProperty;
import org.apache.guacamole.properties.UriGuacamoleProperty;
/** /**
* Service for retrieving configuration information regarding the OpenID * Service for retrieving configuration information regarding the OpenID
@@ -63,8 +65,8 @@ public class ConfigurationService {
/** /**
* The authorization endpoint (URI) of the OpenID service. * The authorization endpoint (URI) of the OpenID service.
*/ */
private static final StringGuacamoleProperty OPENID_AUTHORIZATION_ENDPOINT = private static final UriGuacamoleProperty OPENID_AUTHORIZATION_ENDPOINT =
new StringGuacamoleProperty() { new UriGuacamoleProperty() {
@Override @Override
public String getName() { return "openid-authorization-endpoint"; } public String getName() { return "openid-authorization-endpoint"; }
@@ -75,8 +77,8 @@ public class ConfigurationService {
* The endpoint (URI) of the JWKS service which defines how received ID * The endpoint (URI) of the JWKS service which defines how received ID
* tokens (JWTs) shall be validated. * tokens (JWTs) shall be validated.
*/ */
private static final StringGuacamoleProperty OPENID_JWKS_ENDPOINT = private static final UriGuacamoleProperty OPENID_JWKS_ENDPOINT =
new StringGuacamoleProperty() { new UriGuacamoleProperty() {
@Override @Override
public String getName() { return "openid-jwks-endpoint"; } public String getName() { return "openid-jwks-endpoint"; }
@@ -174,8 +176,8 @@ public class ConfigurationService {
* authentication process is complete. This must be the full URL that a * authentication process is complete. This must be the full URL that a
* user would enter into their browser to access Guacamole. * user would enter into their browser to access Guacamole.
*/ */
private static final StringGuacamoleProperty OPENID_REDIRECT_URI = private static final UriGuacamoleProperty OPENID_REDIRECT_URI =
new StringGuacamoleProperty() { new UriGuacamoleProperty() {
@Override @Override
public String getName() { return "openid-redirect-uri"; } public String getName() { return "openid-redirect-uri"; }
@@ -200,7 +202,7 @@ public class ConfigurationService {
* If guacamole.properties cannot be parsed, or if the authorization * If guacamole.properties cannot be parsed, or if the authorization
* endpoint property is missing. * endpoint property is missing.
*/ */
public String getAuthorizationEndpoint() throws GuacamoleException { public URI getAuthorizationEndpoint() throws GuacamoleException {
return environment.getRequiredProperty(OPENID_AUTHORIZATION_ENDPOINT); return environment.getRequiredProperty(OPENID_AUTHORIZATION_ENDPOINT);
} }
@@ -236,7 +238,7 @@ public class ConfigurationService {
* If guacamole.properties cannot be parsed, or if the redirect URI * If guacamole.properties cannot be parsed, or if the redirect URI
* property is missing. * property is missing.
*/ */
public String getRedirectURI() throws GuacamoleException { public URI getRedirectURI() throws GuacamoleException {
return environment.getRequiredProperty(OPENID_REDIRECT_URI); return environment.getRequiredProperty(OPENID_REDIRECT_URI);
} }
@@ -270,7 +272,7 @@ public class ConfigurationService {
* If guacamole.properties cannot be parsed, or if the JWKS endpoint * If guacamole.properties cannot be parsed, or if the JWKS endpoint
* property is missing. * property is missing.
*/ */
public String getJWKSEndpoint() throws GuacamoleException { public URI getJWKSEndpoint() throws GuacamoleException {
return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT); return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
} }

View File

@@ -19,8 +19,8 @@
package org.apache.guacamole.auth.openid.form; package org.apache.guacamole.auth.openid.form;
import java.io.UnsupportedEncodingException; import java.net.URI;
import java.net.URLEncoder; import javax.ws.rs.core.UriBuilder;
import org.apache.guacamole.form.Field; import org.apache.guacamole.form.Field;
/** /**
@@ -38,7 +38,7 @@ public class TokenField extends Field {
/** /**
* The full URI which the field should link to. * The full URI which the field should link to.
*/ */
private final String authorizationURI; private final URI authorizationURI;
/** /**
* Creates a new field which requests authentication via OpenID connect. * Creates a new field which requests authentication via OpenID connect.
@@ -69,26 +69,19 @@ public class TokenField extends Field {
* A random string unique to this request. To defend against replay * A random string unique to this request. To defend against replay
* attacks, this value must cease being valid after its first use. * attacks, this value must cease being valid after its first use.
*/ */
public TokenField(String authorizationEndpoint, String scope, public TokenField(URI authorizationEndpoint, String scope,
String clientID, String redirectURI, String nonce) { String clientID, URI redirectURI, String nonce) {
// Init base field properties // Init base field properties
super(PARAMETER_NAME, "GUAC_OPENID_TOKEN"); super(PARAMETER_NAME, "GUAC_OPENID_TOKEN");
// Build authorization URI from given values this.authorizationURI = UriBuilder.fromUri(authorizationEndpoint)
try { .queryParam("scope", scope)
this.authorizationURI = authorizationEndpoint .queryParam("response_type", "id_token")
+ "?scope=" + URLEncoder.encode(scope, "UTF-8") .queryParam("client_id","clientID")
+ "&response_type=id_token" .queryParam("redirect_uri", redirectURI)
+ "&client_id=" + URLEncoder.encode(clientID, "UTF-8") .queryParam("nonce", nonce)
+ "&redirect_uri=" + URLEncoder.encode(redirectURI, "UTF-8") .build();
+ "&nonce=" + nonce;
}
// Java is required to provide UTF-8 support
catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException("Unexpected lack of UTF-8 support.", e);
}
} }
@@ -100,7 +93,7 @@ public class TokenField extends Field {
* The full URI that this field should link to. * The full URI that this field should link to.
*/ */
public String getAuthorizationURI() { public String getAuthorizationURI() {
return authorizationURI; return authorizationURI.toString();
} }
} }

View File

@@ -74,7 +74,7 @@ public class TokenValidationService {
public String processUsername(String token) throws GuacamoleException { public String processUsername(String token) throws GuacamoleException {
// Validating the token requires a JWKS key resolver // Validating the token requires a JWKS key resolver
HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint()); HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint().toString());
HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks); HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks);
// Create JWT consumer for validating received token // Create JWT consumer for validating received token