mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-579: Clean up comments, implement convenience method for tokens without a prefix, and remove unneeded classes.
This commit is contained in:
@@ -22,9 +22,7 @@ package org.apache.guacamole.auth.cas;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.guacamole.form.Field;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
|
@@ -34,9 +34,9 @@ import java.util.Map.Entry;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.GuacamoleServerException;
|
||||
import org.apache.guacamole.auth.cas.CASTokenName;
|
||||
import org.apache.guacamole.auth.cas.conf.ConfigurationService;
|
||||
import org.apache.guacamole.net.auth.Credentials;
|
||||
import org.apache.guacamole.token.TokenName;
|
||||
import org.jasig.cas.client.authentication.AttributePrincipal;
|
||||
import org.jasig.cas.client.validation.Assertion;
|
||||
import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
|
||||
@@ -54,6 +54,11 @@ public class TicketValidationService {
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final Logger logger = LoggerFactory.getLogger(TicketValidationService.class);
|
||||
|
||||
/**
|
||||
* The prefix to use when generating token names.
|
||||
*/
|
||||
public static final String CAS_ATTRIBUTE_TOKEN_PREFIX = "CAS_";
|
||||
|
||||
/**
|
||||
* Service for retrieving CAS configuration information.
|
||||
@@ -96,7 +101,8 @@ public class TicketValidationService {
|
||||
String confRedirectURI = confService.getRedirectURI();
|
||||
Assertion a = validator.validate(ticket, confRedirectURI);
|
||||
AttributePrincipal principal = a.getPrincipal();
|
||||
Map<String, Object> ticketAttrs = principal.getAttributes();
|
||||
Map<String, Object> ticketAttrs =
|
||||
new HashMap<>(principal.getAttributes());
|
||||
|
||||
// Retrieve username and set the credentials.
|
||||
String username = principal.getName();
|
||||
@@ -112,8 +118,9 @@ public class TicketValidationService {
|
||||
}
|
||||
|
||||
// Convert remaining attributes that have values to Strings
|
||||
for (Entry attr : ticketAttrs.entrySet()) {
|
||||
String tokenName = CASTokenName.fromAttribute(attr.getKey().toString());
|
||||
for (Entry <String, Object> attr : ticketAttrs.entrySet()) {
|
||||
String tokenName = TokenName.fromAttribute(attr.getKey(),
|
||||
CAS_ATTRIBUTE_TOKEN_PREFIX);
|
||||
Object value = attr.getValue();
|
||||
if (value != null)
|
||||
tokens.put(tokenName, value.toString());
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.cas;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test which verifies automatic generation of LDAP-specific connection
|
||||
* parameter token names.
|
||||
*/
|
||||
public class CASTokenNameTest {
|
||||
|
||||
/**
|
||||
* Verifies that TokenName.fromAttribute() generates token names as
|
||||
* specified, regardless of the naming convention of the attribute.
|
||||
*/
|
||||
@Test
|
||||
public void testFromAttribute() {
|
||||
assertEquals("CAS_A", CASTokenName.fromAttribute("a"));
|
||||
assertEquals("CAS_B", CASTokenName.fromAttribute("b"));
|
||||
assertEquals("CAS_1", CASTokenName.fromAttribute("1"));
|
||||
assertEquals("CAS_SOME_URL", CASTokenName.fromAttribute("someURL"));
|
||||
assertEquals("CAS_LOWERCASE_WITH_DASHES", CASTokenName.fromAttribute("lowercase-with-dashes"));
|
||||
assertEquals("CAS_HEADLESS_CAMEL_CASE", CASTokenName.fromAttribute("headlessCamelCase"));
|
||||
assertEquals("CAS_CAMEL_CASE", CASTokenName.fromAttribute("CamelCase"));
|
||||
assertEquals("CAS_CAMEL_CASE", CASTokenName.fromAttribute("CamelCase"));
|
||||
assertEquals("CAS_LOWERCASE_WITH_UNDERSCORES", CASTokenName.fromAttribute("lowercase_with_underscores"));
|
||||
assertEquals("CAS_UPPERCASE_WITH_UNDERSCORES", CASTokenName.fromAttribute("UPPERCASE_WITH_UNDERSCORES"));
|
||||
assertEquals("CAS_A_VERY_INCONSISTENT_MIX_OF_ALL_STYLES", CASTokenName.fromAttribute("aVery-INCONSISTENTMix_ofAllStyles"));
|
||||
assertEquals("CAS_ABC_123_DEF_456", CASTokenName.fromAttribute("abc123def456"));
|
||||
assertEquals("CAS_ABC_123_DEF_456", CASTokenName.fromAttribute("ABC123DEF456"));
|
||||
assertEquals("CAS_WORD_A_WORD_AB_WORD_ABC_WORD", CASTokenName.fromAttribute("WordAWordABWordABCWord"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user