CASC-120
Add type parameters to fix unchecked compiler warnings where possible,
otherwise add SuppressWarnings("unchecked") compiler directive in a couple
places.
Use ReflectUtils.newInstance for creating new instances of objects from
class names.
This commit is contained in:
parent
82d03364c8
commit
c6b1bc775a
|
|
@ -209,7 +209,7 @@ public class CasLoginModule implements LoginModule {
|
|||
this.assertion = null;
|
||||
this.callbackHandler = handler;
|
||||
this.subject = subject;
|
||||
this.sharedState = new HashMap(state);
|
||||
this.sharedState = new HashMap<String, Object>(state);
|
||||
|
||||
String ticketValidatorClass = null;
|
||||
|
||||
|
|
@ -346,8 +346,8 @@ public class CasLoginModule implements LoginModule {
|
|||
if (this.roleAttributeNames.contains(key)) {
|
||||
// Attribute value is Object if singular or Collection if plural
|
||||
final Object value = attributes.get(key);
|
||||
if (value instanceof Collection) {
|
||||
for (final Object o : (Collection) value) {
|
||||
if (value instanceof Collection<?>) {
|
||||
for (final Object o : (Collection<?>) value) {
|
||||
roleGroup.addMember(new SimplePrincipal(o.toString()));
|
||||
}
|
||||
} else {
|
||||
|
|
@ -407,8 +407,8 @@ public class CasLoginModule implements LoginModule {
|
|||
private TicketValidator createTicketValidator(final String className, final Map<String,?> propertyMap) {
|
||||
CommonUtils.assertTrue(propertyMap.containsKey("casServerUrlPrefix"), "Required property casServerUrlPrefix not found.");
|
||||
|
||||
final Class validatorClass = ReflectUtils.loadClass(className);
|
||||
final TicketValidator validator = (TicketValidator) ReflectUtils.newInstance(validatorClass, new Object[] {propertyMap.get("casServerUrlPrefix")});
|
||||
final Class<TicketValidator> validatorClass = ReflectUtils.loadClass(className);
|
||||
final TicketValidator validator = ReflectUtils.newInstance(validatorClass, propertyMap.get("casServerUrlPrefix"));
|
||||
|
||||
try {
|
||||
final BeanInfo info = Introspector.getBeanInfo(validatorClass);
|
||||
|
|
@ -479,11 +479,12 @@ public class CasLoginModule implements LoginModule {
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug("Cleaning assertion cache of size " + CasLoginModule.ASSERTION_CACHE.size());
|
||||
}
|
||||
final Iterator iter = CasLoginModule.ASSERTION_CACHE.entrySet().iterator();
|
||||
final Iterator<Map.Entry<TicketCredential,Assertion>> iter =
|
||||
CasLoginModule.ASSERTION_CACHE.entrySet().iterator();
|
||||
final Calendar cutoff = Calendar.getInstance();
|
||||
cutoff.add(Calendar.MINUTE, -CasLoginModule.this.cacheTimeout);
|
||||
while (iter.hasNext()) {
|
||||
final Assertion assertion = (Assertion) ((Map.Entry) iter.next()).getValue();
|
||||
final Assertion assertion = iter.next().getValue();
|
||||
final Calendar created = Calendar.getInstance();
|
||||
created.setTime(assertion.getValidFromDate());
|
||||
if (created.before(cutoff)) {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.jasig.cas.client.session;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.util.AbstractConfigurationFilter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public final class CommonUtils {
|
|||
* @param c the collecion to check.
|
||||
* @param message the message to display if the object is null.
|
||||
*/
|
||||
public static void assertNotEmpty(final Collection c, final String message) {
|
||||
public static void assertNotEmpty(final Collection<?> c, final String message) {
|
||||
assertNotNull(c, message);
|
||||
if (c.isEmpty()) {
|
||||
throw new IllegalArgumentException(message);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package org.jasig.cas.client.util;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
|
@ -90,8 +89,7 @@ public final class ErrorRedirectFilter implements Filter {
|
|||
public void init(final FilterConfig filterConfig) throws ServletException {
|
||||
this.defaultErrorRedirectPage = filterConfig.getInitParameter("defaultErrorRedirectPage");
|
||||
|
||||
final Enumeration enumeration = filterConfig.getInitParameterNames();
|
||||
|
||||
final Enumeration<?> enumeration = filterConfig.getInitParameterNames();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final String className = (String) enumeration.nextElement();
|
||||
try {
|
||||
|
|
@ -106,7 +104,7 @@ public final class ErrorRedirectFilter implements Filter {
|
|||
|
||||
protected final class ErrorHolder {
|
||||
|
||||
private Class className;
|
||||
private Class<?> className;
|
||||
|
||||
private String url;
|
||||
|
||||
|
|
|
|||
|
|
@ -123,9 +123,8 @@ public final class HttpServletRequestWrapperFilter extends AbstractConfiguration
|
|||
|
||||
final Object value = this.principal.getAttributes().get(roleAttribute);
|
||||
|
||||
if (value instanceof Collection) {
|
||||
final Collection c = (Collection) value;
|
||||
for (final Object o : c) {
|
||||
if (value instanceof Collection<?>) {
|
||||
for (final Object o : (Collection<?>) value) {
|
||||
if (rolesEqual(role, o)) {
|
||||
log.debug("User [" + getRemoteUser() + "] is in role [" + role + "]: " + true);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -45,9 +45,10 @@ public final class ReflectUtils {
|
|||
* @return the class. CANNOT be NULL.
|
||||
* @throws IllegalArgumentException if the className does not exist.
|
||||
*/
|
||||
public static Class loadClass(final String className) throws IllegalArgumentException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Class<T> loadClass(final String className) throws IllegalArgumentException {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
return (Class<T>) Class.forName(className);
|
||||
} catch (final ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(className + " class not found.");
|
||||
}
|
||||
|
|
@ -61,12 +62,8 @@ public final class ReflectUtils {
|
|||
* @param args Constructor arguments.
|
||||
* @return New instance of given class.
|
||||
*/
|
||||
public static Object newInstance(final String className, final Object[] args) {
|
||||
try {
|
||||
return newInstance(Class.forName(className), args);
|
||||
} catch (final ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(className + " not found");
|
||||
}
|
||||
public static <T> T newInstance(final String className, final Object ... args) {
|
||||
return newInstance(ReflectUtils.<T>loadClass(className), args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,8 +73,8 @@ public final class ReflectUtils {
|
|||
* @param args Constructor arguments.
|
||||
* @return New instance of given class.
|
||||
*/
|
||||
public static Object newInstance(final Class clazz, final Object[] args) {
|
||||
final Class[] argClasses = new Class[args.length];
|
||||
public static <T> T newInstance(final Class<T> clazz, final Object ... args) {
|
||||
final Class<?>[] argClasses = new Class[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
argClasses[i] = args[i].getClass();
|
||||
}
|
||||
|
|
@ -95,7 +92,7 @@ public final class ReflectUtils {
|
|||
* @return Property descriptor for given property or null if no property with given
|
||||
* name exists in given class.
|
||||
*/
|
||||
public static PropertyDescriptor getPropertyDescriptor(final Class clazz, final String propertyName) {
|
||||
public static PropertyDescriptor getPropertyDescriptor(final Class<?> clazz, final String propertyName) {
|
||||
try {
|
||||
return getPropertyDescriptor(Introspector.getBeanInfo(clazz), propertyName);
|
||||
} catch (final IntrospectionException e) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jasig.cas.client.validation;
|
|||
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
import org.jasig.cas.client.util.CommonUtils;
|
||||
import org.jasig.cas.client.util.ReflectUtils;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.servlet.FilterChain;
|
||||
|
|
@ -31,7 +32,6 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* The filter that handles all the work of validating ticket requests.
|
||||
|
|
@ -86,23 +86,10 @@ public abstract class AbstractTicketValidationFilter extends AbstractCasFilter {
|
|||
log.trace("Using hostnameVerifier parameter: " + className);
|
||||
final String config = getPropertyFromInitParams(filterConfig, "hostnameVerifierConfig", null);
|
||||
log.trace("Using hostnameVerifierConfig parameter: " + config);
|
||||
HostnameVerifier verifier = null;
|
||||
if (className != null) {
|
||||
try {
|
||||
final Class verifierClass = Class.forName(className);
|
||||
if (config != null) {
|
||||
final Constructor cons = verifierClass.getConstructor(new Class[] {String.class});
|
||||
verifier = (HostnameVerifier) cons.newInstance(config);
|
||||
} else {
|
||||
verifier = (HostnameVerifier) verifierClass.newInstance();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Invalid HostnameVerifier class " + className);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Error creating instance of " + className, e);
|
||||
}
|
||||
return ReflectUtils.newInstance(className, config);
|
||||
}
|
||||
return verifier;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void initInternal(final FilterConfig filterConfig) throws ServletException {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.jasig.cas.client.proxy.*;
|
||||
import org.jasig.cas.client.util.CommonUtils;
|
||||
import org.jasig.cas.client.util.ReflectUtils;
|
||||
|
||||
/**
|
||||
* Creates either a CAS20ProxyTicketValidator or a CAS20ServiceTicketValidator depending on whether any of the
|
||||
|
|
@ -74,12 +75,7 @@ public class Cas20ProxyReceivingTicketValidationFilter extends AbstractTicketVal
|
|||
final String proxyGrantingTicketStorageClass = getPropertyFromInitParams(filterConfig, "proxyGrantingTicketStorageClass", null);
|
||||
|
||||
if (proxyGrantingTicketStorageClass != null) {
|
||||
try {
|
||||
final Class storageClass = Class.forName(proxyGrantingTicketStorageClass);
|
||||
this.proxyGrantingTicketStorage = (ProxyGrantingTicketStorage) storageClass.newInstance();
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.proxyGrantingTicketStorage = ReflectUtils.newInstance(proxyGrantingTicketStorageClass);
|
||||
}
|
||||
|
||||
log.trace("Setting proxyReceptorUrl parameter: " + this.proxyReceptorUrl);
|
||||
|
|
@ -128,9 +124,9 @@ public class Cas20ProxyReceivingTicketValidationFilter extends AbstractTicketVal
|
|||
validator.setEncoding(getPropertyFromInitParams(filterConfig, "encoding", null));
|
||||
|
||||
final Map<String,String> additionalParameters = new HashMap<String,String>();
|
||||
final List params = Arrays.asList(RESERVED_INIT_PARAMS);
|
||||
final List<String> params = Arrays.asList(RESERVED_INIT_PARAMS);
|
||||
|
||||
for (final Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) {
|
||||
for (final Enumeration<?> e = filterConfig.getInitParameterNames(); e.hasMoreElements();) {
|
||||
final String s = (String) e.nextElement();
|
||||
|
||||
if (!params.contains(s)) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import java.io.StringReader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ public final class Saml11TicketValidator extends AbstractUrlBasedTicketValidator
|
|||
throw new TicketValidationException("No assertions found.");
|
||||
}
|
||||
|
||||
boolean foundValidAssertion = false;
|
||||
for (final Iterator iter = samlResponse.getAssertions(); iter.hasNext();) {
|
||||
for (final Iterator<?> iter = samlResponse.getAssertions(); iter.hasNext();) {
|
||||
final SAMLAssertion assertion = (SAMLAssertion) iter.next();
|
||||
|
||||
if (!isValidAssertion(assertion)) {
|
||||
|
|
@ -88,20 +87,17 @@ public final class Saml11TicketValidator extends AbstractUrlBasedTicketValidator
|
|||
}
|
||||
|
||||
final SAMLAttribute[] attributes = getAttributesFor(assertion, subject);
|
||||
|
||||
final Map personAttributes = new HashMap();
|
||||
|
||||
final Map<String,Object> personAttributes = new HashMap<String,Object>();
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
final SAMLAttribute samlAttribute = attributes[i];
|
||||
final List values = getValuesFrom(samlAttribute);
|
||||
final List<?> values = getValuesFrom(samlAttribute);
|
||||
|
||||
personAttributes.put(samlAttribute.getName(), values.size() == 1 ? values.get(0) : values);
|
||||
}
|
||||
|
||||
final AttributePrincipal principal = new AttributePrincipalImpl(subject.getNameIdentifier().getName(), personAttributes);
|
||||
|
||||
|
||||
final Map authenticationAttributes = new HashMap();
|
||||
final Map<String,Object> authenticationAttributes = new HashMap<String,Object>();
|
||||
authenticationAttributes.put("samlAuthenticationStatement::authMethod", authenticationStatement.getAuthMethod());
|
||||
|
||||
return new AssertionImpl(principal, authenticationAttributes);
|
||||
|
|
@ -138,7 +134,7 @@ public final class Saml11TicketValidator extends AbstractUrlBasedTicketValidator
|
|||
}
|
||||
|
||||
private SAMLAuthenticationStatement getSAMLAuthenticationStatement(final SAMLAssertion assertion) {
|
||||
for (final Iterator iter = assertion.getStatements(); iter.hasNext();) {
|
||||
for (final Iterator<?> iter = assertion.getStatements(); iter.hasNext();) {
|
||||
final SAMLStatement statement = (SAMLStatement) iter.next();
|
||||
|
||||
if (statement instanceof SAMLAuthenticationStatement) {
|
||||
|
|
@ -150,29 +146,28 @@ public final class Saml11TicketValidator extends AbstractUrlBasedTicketValidator
|
|||
}
|
||||
|
||||
private SAMLAttribute[] getAttributesFor(final SAMLAssertion assertion, final SAMLSubject subject) {
|
||||
final List attributes = new ArrayList();
|
||||
for (final Iterator iter = assertion.getStatements(); iter.hasNext();) {
|
||||
final List<SAMLAttribute> attributes = new ArrayList<SAMLAttribute>();
|
||||
for (final Iterator<?> iter = assertion.getStatements(); iter.hasNext();) {
|
||||
final SAMLStatement statement = (SAMLStatement) iter.next();
|
||||
|
||||
if (statement instanceof SAMLAttributeStatement) {
|
||||
final SAMLAttributeStatement attributeStatement = (SAMLAttributeStatement) statement;
|
||||
// used because SAMLSubject does not implement equals
|
||||
if (subject.getNameIdentifier().getName().equals(attributeStatement.getSubject().getNameIdentifier().getName())) {
|
||||
for (final Iterator iter2 = attributeStatement.getAttributes(); iter2.hasNext();)
|
||||
attributes.add(iter2.next());
|
||||
for (final Iterator<?> iter2 = attributeStatement.getAttributes(); iter2.hasNext();)
|
||||
attributes.add((SAMLAttribute) iter2.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (SAMLAttribute[]) attributes.toArray(new SAMLAttribute[attributes.size()]);
|
||||
return attributes.toArray(new SAMLAttribute[attributes.size()]);
|
||||
}
|
||||
|
||||
private List getValuesFrom(final SAMLAttribute attribute) {
|
||||
final List list = new ArrayList();
|
||||
for (final Iterator iter = attribute.getValues(); iter.hasNext();) {
|
||||
private List<?> getValuesFrom(final SAMLAttribute attribute) {
|
||||
final List<Object> list = new ArrayList<Object>();
|
||||
for (final Iterator<?> iter = attribute.getValues(); iter.hasNext();) {
|
||||
list.add(iter.next());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package org.jasig.cas.client.jaas;
|
|||
import java.security.Principal;
|
||||
import java.security.acl.Group;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -47,7 +46,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
|
||||
private Subject subject;
|
||||
|
||||
private Map options;
|
||||
private Map<String,String> options;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
protected void setUp() throws Exception {
|
||||
|
|
@ -55,7 +54,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
|
||||
module = new CasLoginModule();
|
||||
subject = new Subject();
|
||||
options = new HashMap();
|
||||
options = new HashMap<String,String>();
|
||||
options.put("service", "https://service.example.com/webapp");
|
||||
options.put("ticketValidatorClass", "org.jasig.cas.client.validation.Cas20ServiceTicketValidator");
|
||||
options.put("casServerUrlPrefix", CONST_CAS_SERVER_URL);
|
||||
|
|
@ -83,7 +82,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
module.initialize(
|
||||
subject,
|
||||
new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
|
||||
new HashMap(),
|
||||
new HashMap<String,Object>(),
|
||||
options);
|
||||
module.login();
|
||||
module.commit();
|
||||
|
|
@ -106,7 +105,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
module.initialize(
|
||||
subject,
|
||||
new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
|
||||
new HashMap(),
|
||||
new HashMap<String,Object>(),
|
||||
options);
|
||||
try {
|
||||
module.login();
|
||||
|
|
@ -150,7 +149,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
module.initialize(
|
||||
subject,
|
||||
new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
|
||||
new HashMap(),
|
||||
new HashMap<String,Object>(),
|
||||
options);
|
||||
module.login();
|
||||
module.commit();
|
||||
|
|
@ -165,7 +164,7 @@ public class CasLoginModuleTests extends TestCase {
|
|||
module.initialize(
|
||||
subject,
|
||||
new ServiceAndTicketCallbackHandler(SERVICE, TICKET),
|
||||
new HashMap(),
|
||||
new HashMap<String,Object>(),
|
||||
options);
|
||||
module.login();
|
||||
module.commit();
|
||||
|
|
@ -173,11 +172,9 @@ public class CasLoginModuleTests extends TestCase {
|
|||
assertEquals(TICKET, this.subject.getPrivateCredentials().iterator().next().toString());
|
||||
}
|
||||
|
||||
private boolean hasPrincipalName(final Subject subject, final Class principalClass, final String name) {
|
||||
final Set principals = subject.getPrincipals(principalClass);
|
||||
final Iterator iter = principals.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Principal p = (Principal) iter.next();
|
||||
private boolean hasPrincipalName(final Subject subject, final Class<? extends Principal> principalClass, final String name) {
|
||||
final Set<? extends Principal> principals = subject.getPrincipals(principalClass);
|
||||
for (Principal p : principals) {
|
||||
if (p.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ public final class CommonUtilsTests extends TestCase {
|
|||
|
||||
public void testAssertNotEmpty() {
|
||||
final String CONST_MESSAGE = "test";
|
||||
final Collection c = new ArrayList();
|
||||
final Collection<Object> c = new ArrayList<Object>();
|
||||
c.add(new Object());
|
||||
CommonUtils.assertNotEmpty(c, CONST_MESSAGE);
|
||||
try {
|
||||
CommonUtils.assertNotEmpty(new ArrayList(), CONST_MESSAGE);
|
||||
CommonUtils.assertNotEmpty(new ArrayList<Object>(), CONST_MESSAGE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals(CONST_MESSAGE, e.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public final class HttpServletRequestWrapperFilterTests extends TestCase {
|
|||
final HttpServletRequestWrapperFilter filter = new HttpServletRequestWrapperFilter();
|
||||
filter.init(config);
|
||||
|
||||
final Map attributes = new HashMap();
|
||||
final Map<String,Object> attributes = new HashMap<String,Object>();
|
||||
attributes.put("memberOf", "administrators");
|
||||
final AttributePrincipal principal = new AttributePrincipalImpl("alice", attributes);
|
||||
session.setAttribute(
|
||||
|
|
@ -106,7 +106,7 @@ public final class HttpServletRequestWrapperFilterTests extends TestCase {
|
|||
final HttpServletRequestWrapperFilter filter = new HttpServletRequestWrapperFilter();
|
||||
filter.init(config);
|
||||
|
||||
final Map attributes = new HashMap();
|
||||
final Map<String,Object> attributes = new HashMap<String,Object>();
|
||||
attributes.put("groupMembership", Arrays.asList(new Object[] {"animals", "ducks"}));
|
||||
final AttributePrincipal principal = new AttributePrincipalImpl("daffy", attributes);
|
||||
session.setAttribute(
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.jasig.cas.client.validation;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Base class for all TicketValidator tests to inherit from.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public final class AssertionImplTests extends TestCase {
|
|||
|
||||
private static final AttributePrincipal CONST_PRINCIPAL = new AttributePrincipalImpl("test");
|
||||
|
||||
private static final Map CONST_ATTRIBUTES = new HashMap();
|
||||
private static final Map<String,Object> CONST_ATTRIBUTES = new HashMap<String,Object>();
|
||||
|
||||
static {
|
||||
CONST_ATTRIBUTES.put("test", "test");
|
||||
|
|
|
|||
|
|
@ -117,7 +117,6 @@ public final class Cas20ProxyTicketValidatorTests extends
|
|||
UnsupportedEncodingException {
|
||||
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:cas20ProxyTicketValidator.xml");
|
||||
final Cas20ProxyTicketValidator v = (Cas20ProxyTicketValidator) context.getBean("proxyTicketValidator");
|
||||
final Cas20ProxyTicketValidator v2 = (Cas20ProxyTicketValidator) context.getBean("proxyTicketValidatorWithAllowAnyProxy");
|
||||
|
||||
final String USERNAME = "username";
|
||||
final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationSuccess><cas:user>username</cas:user><cas:proxyGrantingTicket>PGTIOU-84678-8a9d...</cas:proxyGrantingTicket><cas:proxies><cas:proxy>proxy1</cas:proxy><cas:proxy>proxy2</cas:proxy><cas:proxy>proxy3</cas:proxy></cas:proxies></cas:authenticationSuccess></cas:serviceResponse>";
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ public class AssertionCasRealmDelegate implements CasRealm {
|
|||
* @param p the principal to check.
|
||||
* @return the list of attribute values that matched this role, or an empty collection if they don't.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<String> getRoleCollection(final Principal p) {
|
||||
if (!(p instanceof AttributePrincipal)) {
|
||||
return Collections.emptyList();
|
||||
|
|
@ -93,7 +94,7 @@ public class AssertionCasRealmDelegate implements CasRealm {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (attributes instanceof Collection) {
|
||||
if (attributes instanceof Collection<?>) {
|
||||
return (Collection<String>) attributes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ public class PropertiesCasRealmDelegate implements CasRealm {
|
|||
throw new IllegalStateException("Error loading users/roles from " + file, e);
|
||||
}
|
||||
this.roleMap = new HashMap<String,Set<String>>(properties.size());
|
||||
final Set<String> keys = new HashSet(properties.keySet());
|
||||
|
||||
for (final String user : keys) {
|
||||
for (final Object key : properties.keySet()) {
|
||||
final String user = (String) key;
|
||||
// Use TreeSet to sort roles
|
||||
final Set<String> roleSet = new HashSet<String>();
|
||||
final String[] roles = properties.getProperty(user).split(",\\s*");
|
||||
|
|
@ -104,9 +104,7 @@ public class PropertiesCasRealmDelegate implements CasRealm {
|
|||
/** {@inheritDoc} */
|
||||
public String[] getRoles(final Principal p) {
|
||||
final Set<String> roleSet = this.roleMap.get(p.getName());
|
||||
final String[] roles = new String[roleSet.size()];
|
||||
roleSet.toArray(roles);
|
||||
return roles;
|
||||
return roleSet.toArray(new String[roleSet.size()]);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ package org.jasig.cas.client.tomcat;
|
|||
|
||||
import java.security.Principal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
|
@ -52,13 +51,12 @@ public class PropertiesCasRealmDelegateTests extends TestCase {
|
|||
|
||||
public void testGetRoles() {
|
||||
final Principal p = new AttributePrincipalImpl("rosencrantz");
|
||||
final List expected = Arrays.asList(new String[] {"admins", "users"});
|
||||
final List actual = Arrays.asList(realm.getRoles(p));
|
||||
final List<String> expected = Arrays.asList(new String[] {"admins", "users"});
|
||||
final List<String> actual = Arrays.asList(realm.getRoles(p));
|
||||
assertEquals(expected.size(), actual.size());
|
||||
|
||||
for (final Iterator iter = expected.iterator(); iter.hasNext();) {
|
||||
final Object value = iter.next();
|
||||
assertTrue(actual.contains(value));
|
||||
for (final String item : expected) {
|
||||
assertTrue(actual.contains(item));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.catalina.connector.Request;
|
|||
import org.apache.catalina.connector.Response;
|
||||
import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage;
|
||||
import org.jasig.cas.client.util.CommonUtils;
|
||||
import org.jasig.cas.client.util.ReflectUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
|
@ -68,8 +69,7 @@ public final class ProxyCallbackValve extends AbstractLifecycleValve {
|
|||
CommonUtils.assertNotNull(this.proxyCallbackUrl, "the proxy callback url cannot be null");
|
||||
CommonUtils.assertTrue(this.proxyCallbackUrl.startsWith("/"), "proxy callback url must start with \"/\"");
|
||||
|
||||
final Class proxyGrantingTicketStorage = Class.forName(proxyGrantingTicketStorageClass);
|
||||
PROXY_GRANTING_TICKET_STORAGE = (ProxyGrantingTicketStorage) proxyGrantingTicketStorage.newInstance();
|
||||
PROXY_GRANTING_TICKET_STORAGE = ReflectUtils.newInstance(proxyGrantingTicketStorageClass);
|
||||
} catch (final Exception e) {
|
||||
throw new LifecycleException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage;
|
||||
import org.jasig.cas.client.util.CommonUtils;
|
||||
import org.jasig.cas.client.util.ReflectUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
|
@ -72,8 +73,7 @@ public final class ProxyCallbackValve extends ValveBase {
|
|||
CommonUtils.assertNotNull(this.proxyCallbackUrl, "the proxy callback url cannot be null");
|
||||
CommonUtils.assertTrue(this.proxyCallbackUrl.startsWith("/"), "proxy callback url must start with \"/\"");
|
||||
|
||||
final Class proxyGrantingTicketStorage = Class.forName(proxyGrantingTicketStorageClass);
|
||||
PROXY_GRANTING_TICKET_STORAGE = (ProxyGrantingTicketStorage) proxyGrantingTicketStorage.newInstance();
|
||||
PROXY_GRANTING_TICKET_STORAGE = ReflectUtils.newInstance(proxyGrantingTicketStorageClass);
|
||||
} catch (final Exception e) {
|
||||
throw new LifecycleException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@
|
|||
package org.jasig.cas.client.tomcat.v7;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.tomcat.LogoutHandler;
|
||||
import org.jasig.cas.client.tomcat.RegexUriLogoutHandler;
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public final class MemcachedBackedProxyGrantingTicketStorageImpl implements Prox
|
|||
// we actually don't have anything to do here, yay!
|
||||
}
|
||||
|
||||
private void handleSynchronousRequest(final Future f) {
|
||||
private void handleSynchronousRequest(final Future<?> f) {
|
||||
try {
|
||||
f.get();
|
||||
} catch (final Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue