mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-678: Use new URI property for existing configuration items.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
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.
|
||||
@@ -36,8 +36,8 @@ public class CASGuacamoleProperties {
|
||||
/**
|
||||
* The authorization endpoint (URI) of the CAS service.
|
||||
*/
|
||||
public static final StringGuacamoleProperty CAS_AUTHORIZATION_ENDPOINT =
|
||||
new StringGuacamoleProperty() {
|
||||
public static final UriGuacamoleProperty CAS_AUTHORIZATION_ENDPOINT =
|
||||
new UriGuacamoleProperty() {
|
||||
|
||||
@Override
|
||||
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
|
||||
* user would enter into their browser to access Guacamole.
|
||||
*/
|
||||
public static final StringGuacamoleProperty CAS_REDIRECT_URI =
|
||||
new StringGuacamoleProperty() {
|
||||
public static final UriGuacamoleProperty CAS_REDIRECT_URI =
|
||||
new UriGuacamoleProperty() {
|
||||
|
||||
@Override
|
||||
public String getName() { return "cas-redirect-uri"; }
|
||||
|
@@ -20,6 +20,7 @@
|
||||
package org.apache.guacamole.auth.cas.conf;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.net.URI;
|
||||
import java.security.PrivateKey;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.environment.Environment;
|
||||
@@ -47,7 +48,7 @@ public class ConfigurationService {
|
||||
* If guacamole.properties cannot be parsed, or if the authorization
|
||||
* endpoint property is missing.
|
||||
*/
|
||||
public String getAuthorizationEndpoint() throws GuacamoleException {
|
||||
public URI getAuthorizationEndpoint() throws GuacamoleException {
|
||||
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
|
||||
* property is missing.
|
||||
*/
|
||||
public String getRedirectURI() throws GuacamoleException {
|
||||
public URI getRedirectURI() throws GuacamoleException {
|
||||
return environment.getRequiredProperty(CASGuacamoleProperties.CAS_REDIRECT_URI);
|
||||
}
|
||||
|
||||
|
@@ -19,8 +19,8 @@
|
||||
|
||||
package org.apache.guacamole.auth.cas.form;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.URI;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import org.apache.guacamole.form.Field;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CASTicketField extends Field {
|
||||
/**
|
||||
* 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
|
||||
@@ -65,29 +65,15 @@ public class CASTicketField extends Field {
|
||||
* The URI that the CAS service should redirect to upon successful
|
||||
* authentication.
|
||||
*/
|
||||
public CASTicketField(String authorizationEndpoint, String redirectURI) {
|
||||
public CASTicketField(URI authorizationEndpoint, URI redirectURI) {
|
||||
|
||||
// Init base field properties
|
||||
super(PARAMETER_NAME, "GUAC_CAS_TICKET");
|
||||
|
||||
// Build authorization URI from given values
|
||||
try {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(authorizationEndpoint);
|
||||
// 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);
|
||||
}
|
||||
|
||||
this.authorizationURI = UriBuilder.fromUri(authorizationEndpoint)
|
||||
.path(CAS_LOGIN_URI)
|
||||
.queryParam("service", redirectURI)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@@ -99,7 +85,7 @@ public class CASTicketField extends Field {
|
||||
* The full URI that this field should link to.
|
||||
*/
|
||||
public String getAuthorizationURI() {
|
||||
return authorizationURI;
|
||||
return authorizationURI.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ package org.apache.guacamole.auth.cas.ticket;
|
||||
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.inject.Inject;
|
||||
import java.net.URI;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
@@ -83,13 +84,13 @@ public class TicketValidationService {
|
||||
// Retrieve the configured CAS URL, establish a ticket validator,
|
||||
// and then attempt to validate the supplied ticket. If that succeeds,
|
||||
// grab the principal returned by the validator.
|
||||
String casServerUrl = confService.getAuthorizationEndpoint();
|
||||
Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl);
|
||||
URI casServerUrl = confService.getAuthorizationEndpoint();
|
||||
Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl.toString());
|
||||
validator.setAcceptAnyProxy(true);
|
||||
validator.setEncoding("UTF-8");
|
||||
try {
|
||||
String confRedirectURI = confService.getRedirectURI();
|
||||
Assertion a = validator.validate(ticket, confRedirectURI);
|
||||
URI confRedirectURI = confService.getRedirectURI();
|
||||
Assertion a = validator.validate(ticket, confRedirectURI.toString());
|
||||
AttributePrincipal principal = a.getPrincipal();
|
||||
|
||||
// Retrieve username and set the credentials.
|
||||
|
Reference in New Issue
Block a user