extremely minor formatting fixes
This commit is contained in:
Scott Battaglia 2010-10-06 03:27:37 +00:00
parent a947490c04
commit ac08968c30
28 changed files with 69 additions and 51 deletions

View File

@ -350,4 +350,19 @@ public final class CommonUtils {
editor.setAsText(proxies);
return (ProxyList) editor.getValue();
}
/**
* Sends the redirect message and captures the exceptions that we can't possibly do anything with.
*
* @param response the HttpServletResponse. CANNOT be NULL.
* @param url the url to redirect to.
*/
public static void sendRedirect(final HttpServletResponse response, final String url) {
try {
response.sendRedirect(url);
} catch (final Exception e) {
LOG.warn(e.getMessage(), e);
}
}
}

View File

@ -12,6 +12,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.util.CommonUtils;
import org.jasig.cas.client.validation.Assertion;
/**
@ -22,6 +23,7 @@ import org.jasig.cas.client.validation.Assertion;
*
*/
public abstract class AbstractLogoutHandler implements LogoutHandler {
protected final Log log = LogFactory.getLog(getClass());
protected String redirectUrl;
@ -34,16 +36,10 @@ public abstract class AbstractLogoutHandler implements LogoutHandler {
public void logout(final HttpServletRequest request, final HttpServletResponse response) {
this.log.debug("Processing logout request from CAS server.");
Assertion assertion = null;
final Assertion assertion;
final HttpSession httpSession = request.getSession(false);
if (httpSession != null) {
assertion = (Assertion) httpSession.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
if (assertion != null) {
httpSession.removeAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
}
}
if (assertion != null) {
if (httpSession != null && (assertion = (Assertion) httpSession.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION)) != null) {
httpSession.removeAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
this.log.info("Successfully logged out " + assertion.getPrincipal());
} else {
this.log.info("Session already ended.");
@ -51,12 +47,8 @@ public abstract class AbstractLogoutHandler implements LogoutHandler {
final String redirectUrl = constructRedirectUrl(request);
if (redirectUrl != null) {
try {
this.log.debug("Redirecting to " + redirectUrl);
response.sendRedirect(redirectUrl);
} catch (Exception e) {
this.log.error("Error redirecting to " + redirectUrl, e);
}
this.log.debug("Redirecting to " + redirectUrl);
CommonUtils.sendRedirect(response, redirectUrl);
}
}

View File

@ -77,11 +77,7 @@ public class AuthenticatorDelegate {
if (CommonUtils.isBlank(token)) {
final String redirectUrl = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, this.serviceParameterName, service, false, false);
log.debug("Redirecting to " + redirectUrl);
try {
response.sendRedirect(redirectUrl);
} catch (IOException e) {
throw new IllegalStateException("Cannot redirect to " + redirectUrl, e);
}
CommonUtils.sendRedirect(response, redirectUrl);
return null;
}
try {

View File

@ -10,12 +10,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.Principal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.HashSet;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -37,6 +32,7 @@ import org.jasig.cas.client.util.CommonUtils;
*
*/
public class PropertiesCasRealmDelegate implements CasRealm {
/** Log instance */
private final Log log = LogFactory.getLog(getClass());
@ -76,16 +72,14 @@ public class PropertiesCasRealmDelegate implements CasRealm {
// Use TreeSet to sort roles
final Set roleSet = new HashSet();
final String[] roles = properties.getProperty(user).split(",\\s*");
for (int i = 0; i < roles.length; i++) {
roleSet.add(roles[i]);
}
roleMap.put(user, roleSet);
roleSet.addAll(Arrays.asList(roles));
roleMap.put(user, roleSet);
}
}
/** {@inheritDoc} */
public Principal authenticate(final Principal p) {
if (roleMap.get(p.getName()) != null) {
if (roleMap.containsKey(p.getName())) {
return p;
} else {
return null;
@ -103,10 +97,7 @@ public class PropertiesCasRealmDelegate implements CasRealm {
/** {@inheritDoc} */
public boolean hasRole(final Principal principal, final String role) {
final Set roles = (Set) roleMap.get(principal.getName());
if (roles != null) {
return roles.contains(role);
} else {
return false;
}
return roles != null && roles.contains(role);
}
}

View File

@ -16,9 +16,11 @@ import org.jasig.cas.client.util.CommonUtils;
*
* @author Marvin S. Addison
* @version $Revision$
* @since 3.1.12
*
*/
public class RegexUriLogoutHandler extends AbstractLogoutHandler {
public final class RegexUriLogoutHandler extends AbstractLogoutHandler {
private String logoutUriRegex;
private Pattern logoutUriPattern;
@ -31,7 +33,7 @@ public class RegexUriLogoutHandler extends AbstractLogoutHandler {
}
/**
* Initalializes the component for use.
* Initializes the component for use.
*/
public void init() {
CommonUtils.assertNotNull(this.logoutUriRegex, "A logout URI regular expression is required.");

View File

@ -15,9 +15,11 @@ import org.jasig.cas.client.util.CommonUtils;
*
* @author Marvin S. Addison
* @version $Revision$
* @since 3.1.12
*
*/
public class StaticUriLogoutHandler extends AbstractLogoutHandler {
public final class StaticUriLogoutHandler extends AbstractLogoutHandler {
private String logoutUri;
/**

View File

@ -20,6 +20,7 @@ import org.jasig.cas.client.tomcat.CasRealm;
*
*/
public abstract class AbstractCasRealm extends RealmBase implements CasRealm {
/** Logger instance */
protected final Log log = LogFactory.getLog(getClass());
@ -60,7 +61,7 @@ public abstract class AbstractCasRealm extends RealmBase implements CasRealm {
}
/** {@inheritDoc} */
protected Principal getPrincipal(String username) {
protected Principal getPrincipal(final String username) {
throw new UnsupportedOperationException();
}

View File

@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory;
*
*/
public abstract class AbstractLifecycleValve extends ValveBase implements Lifecycle {
/** Logger instance */
protected final Log log = LogFactory.getLog(getClass());

View File

@ -27,12 +27,11 @@ public abstract class AbstractLogoutValve extends AbstractLifecycleValve {
getLogoutHandler().logout(request, response);
// Do not proceed up valve chain
return;
} else {
this.log.debug("URI is not a logout request: " + request.getRequestURI());
getNext().invoke(request, response);
}
this.log.debug("URI is not a logout request: " + request.getRequestURI());
getNext().invoke(request, response);
}
protected abstract LogoutHandler getLogoutHandler();
}

View File

@ -11,7 +11,7 @@ import org.jasig.cas.client.tomcat.CasRealm;
/**
* Tomcat <code>Realm</code> that implements {@link CasRealm} for principal and
* role data backed by the CAS {@link Assertion}.
* role data backed by the CAS {@link org.jasig.cas.client.validation.Assertion}.
* <p>
* Authentication always succeeds and simply returns the given principal.
*
@ -20,12 +20,13 @@ import org.jasig.cas.client.tomcat.CasRealm;
*
*/
public class AssertionCasRealm extends AbstractCasRealm {
private final AssertionCasRealmDelegate delegate = new AssertionCasRealmDelegate();
/** {@inheritDoc} */
public void start() throws LifecycleException {
super.start();
this.log.info("Startup completed.");
log.info("Startup completed.");
}
/**

View File

@ -17,6 +17,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public class Cas10CasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS10";
private static final String NAME = Cas10CasAuthenticator.class.getName();

View File

@ -17,6 +17,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public final class Cas20CasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS20";
private static final String NAME = Cas20CasAuthenticator.class.getName();

View File

@ -18,6 +18,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public final class Cas20ProxyCasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS20-PROXY";
private static final String NAME = Cas20ProxyCasAuthenticator.class.getName();

View File

@ -25,6 +25,7 @@ import org.jasig.cas.client.tomcat.PropertiesCasRealmDelegate;
*
*/
public class PropertiesCasRealm extends AbstractCasRealm {
private final PropertiesCasRealmDelegate delegate = new PropertiesCasRealmDelegate();
/**

View File

@ -26,6 +26,7 @@ import java.io.IOException;
* @since 3.1.12
*/
public final class ProxyCallbackValve extends AbstractLifecycleValve {
private static final String NAME = ProxyCallbackValve.class.getName();
private static ProxyGrantingTicketStorage PROXY_GRANTING_TICKET_STORAGE;

View File

@ -18,6 +18,7 @@ import org.jasig.cas.client.tomcat.RegexUriLogoutHandler;
* @since 3.1.12
*/
public final class RegexUriLogoutValve extends AbstractLogoutValve {
private static final String NAME = RegexUriLogoutValve.class.getName();
private RegexUriLogoutHandler logoutHandler = new RegexUriLogoutHandler();

View File

@ -17,6 +17,7 @@ import org.jasig.cas.client.validation.TicketValidator;
*
*/
public class Saml11Authenticator extends AbstractAuthenticator {
public static final String AUTH_METHOD = "SAML11";
private static final String NAME = Saml11Authenticator.class.getName();

View File

@ -28,6 +28,7 @@ import org.jasig.cas.client.session.SingleSignOutHandler;
*
*/
public class SingleSignOutValve extends AbstractLifecycleValve implements SessionListener {
private static final String NAME = SingleSignOutValve.class.getName();
private final SingleSignOutHandler handler = new SingleSignOutHandler();
@ -48,7 +49,7 @@ public class SingleSignOutValve extends AbstractLifecycleValve implements Sessio
public void start() throws LifecycleException {
super.start();
handler.init();
this.log.info("Startup completed.");
log.info("Startup completed.");
}
/** {@inheritDoc} */
@ -62,7 +63,7 @@ public class SingleSignOutValve extends AbstractLifecycleValve implements Sessio
// Do not proceed up valve chain
return;
} else {
this.log.debug("Ignoring URI " + request.getRequestURI());
log.debug("Ignoring URI " + request.getRequestURI());
}
getNext().invoke(request, response);
}

View File

@ -18,6 +18,7 @@ import org.jasig.cas.client.tomcat.StaticUriLogoutHandler;
* @since 3.1.12
*/
public final class StaticUriLogoutValve extends AbstractLogoutValve {
private static final String NAME = StaticUriLogoutValve.class.getName();
private StaticUriLogoutHandler logoutHandler = new StaticUriLogoutHandler();

View File

@ -25,6 +25,7 @@ import java.io.IOException;
* @since 3.1.12
*/
public abstract class AbstractLogoutValve extends ValveBase {
protected final Log log = LogFactory.getLog(getClass());
public final void invoke(final Request request, final Response response) throws IOException, ServletException {
@ -32,10 +33,10 @@ public abstract class AbstractLogoutValve extends ValveBase {
getLogoutHandler().logout(request, response);
// Do not proceed up valve chain
return;
} else {
this.log.debug("URI is not a logout request: " + request.getRequestURI());
getNext().invoke(request, response);
}
this.log.debug("URI is not a logout request: " + request.getRequestURI());
getNext().invoke(request, response);
}
protected abstract LogoutHandler getLogoutHandler();

View File

@ -19,6 +19,7 @@ import org.jasig.cas.client.tomcat.CasRealm;
*
*/
public class AssertionCasRealm extends AbstractCasRealm {
private final AssertionCasRealmDelegate delegate = new AssertionCasRealmDelegate();
/**

View File

@ -17,6 +17,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public final class Cas10CasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS10";
private static final String NAME = Cas10CasAuthenticator.class.getName();

View File

@ -17,6 +17,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public final class Cas20CasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS20";
private static final String NAME = Cas20CasAuthenticator.class.getName();

View File

@ -18,6 +18,7 @@ import org.jasig.cas.client.validation.TicketValidator;
* @since 3.1.12
*/
public final class Cas20ProxyCasAuthenticator extends AbstractCasAuthenticator {
public static final String AUTH_METHOD = "CAS20-PROXY";
private static final String NAME = Cas20ProxyCasAuthenticator.class.getName();

View File

@ -25,6 +25,7 @@ import org.jasig.cas.client.tomcat.PropertiesCasRealmDelegate;
*
*/
public class PropertiesCasRealm extends AbstractCasRealm {
private final PropertiesCasRealmDelegate delegate = new PropertiesCasRealmDelegate();
/**

View File

@ -20,6 +20,7 @@ import org.jasig.cas.client.tomcat.RegexUriLogoutHandler;
* @since 3.1.12
*/
public final class RegexUriLogoutValve extends AbstractLogoutValve {
/** Logger instance */
private final Log log = LogFactory.getLog(getClass());

View File

@ -31,6 +31,7 @@ import org.jasig.cas.client.session.SingleSignOutHandler;
*
*/
public class SingleSignOutValve extends ValveBase implements SessionListener {
/** Logger instance */
private final Log log = LogFactory.getLog(getClass());

View File

@ -20,6 +20,7 @@ import org.jasig.cas.client.tomcat.StaticUriLogoutHandler;
* @since 3.1.12
*/
public final class StaticUriLogoutValve extends AbstractLogoutValve {
/** Logger instance */
private final Log log = LogFactory.getLog(getClass());