initial Tomcat support started.
This commit is contained in:
Scott Battaglia 2010-07-20 03:55:54 +00:00
parent 649b39b1c8
commit 2449a7a61b
4 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cas-client</artifactId>
<groupId>org.jasig.cas.client</groupId>
<version>3.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-integration-tomcat</artifactId>
<packaging>jar</packaging>
<name>JA-SIG CAS Client for Java - Tomcat Integration</name>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,67 @@
package org.jasig.cas.client.tomcat;
import org.apache.catalina.authenticator.AuthenticatorBase;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.LoginConfig;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.util.CommonUtils;
import org.jasig.cas.client.validation.Assertion;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Principal;
/**
* @author Scott Battaglia
* @version $Revision$ $Date$
* @since 3.1.12
*/
public abstract class CasAuthenticator extends AuthenticatorBase {
private static final String INFO = "org.jasig.cas.client.tomcat.CasAuthenticator/1.0";
private String serverName;
private String serviceUrl;
private String casServerLoginUrl;
private boolean encode;
private boolean renew;
protected abstract String getArtifactParameterName();
protected abstract String getServiceParameterName();
public String getInfo() {
return INFO;
}
public boolean authenticate(final Request request, final HttpServletResponse httpServletResponse, final LoginConfig loginConfig) throws IOException {
final Assertion assertion = (Assertion) request.getSession(true).getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
if (assertion != null) {
return true;
}
final String ticket = CommonUtils.safeGetParameter(request, getArtifactParameterName());
if (CommonUtils.isBlank(ticket)) {
final String serviceUrl = CommonUtils.constructServiceUrl(request, httpServletResponse, this.serviceUrl, this.serverName, getArtifactParameterName(), this.encode);
final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), serviceUrl, this.renew, false);
httpServletResponse.sendRedirect(urlToRedirectTo);
return false;
}
final Principal principal = this.context.getRealm().authenticate(null, ticket);
return false; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -0,0 +1,81 @@
package org.jasig.cas.client.tomcat;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Realm;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.deploy.SecurityConstraint;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.security.Principal;
import java.security.cert.X509Certificate;
/**
* Created by IntelliJ IDEA.
* User: scottbattaglia
* Date: Jul 19, 2010
* Time: 11:11:28 PM
* To change this template use File | Settings | File Templates.
*/
public class CasRealm implements Realm {
// &lt;description&gt;/&lt;version&gt;
private static final String INFO = "org.jasig.cas.client.tomcat.CasRealm/1.0";
private Container container;
public Container getContainer() {
return this.container;
}
public void setContainer(final Container container) {
this.container = container;
}
public String getInfo() {
return INFO;
}
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
//To change body of implemented methods use File | Settings | File Templates.
}
public Principal authenticate(String s, String s1) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Principal authenticate(String s, String s1, String s2, String s3, String s4, String s5, String s6, String s7) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Principal authenticate(X509Certificate[] x509Certificates) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void backgroundProcess() {
//To change body of implemented methods use File | Settings | File Templates.
}
public SecurityConstraint[] findSecurityConstraints(Request request, Context context) {
return new SecurityConstraint[0]; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean hasResourcePermission(Request request, Response response, SecurityConstraint[] securityConstraints, Context context) throws IOException {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean hasRole(Principal principal, String s) {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean hasUserDataPermission(Request request, Response response, SecurityConstraint[] securityConstraints) throws IOException {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
//To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -139,6 +139,7 @@
<module>cas-client-integration-jboss</module>
<module>cas-client-support-distributed-ehcache</module>
<module>cas-client-support-distributed-memcached</module>
<module>cas-client-integration-tomcat</module>
</modules>
<properties>