SEC-195
created an AuthenticationHandler (CAS 3 API) that delegates to the Acegi AuthenticationManager for authentication purposes. Also added cas-server-3.0.4.jar to the classpath to provide the APIs to use.
This commit is contained in:
parent
6abceb7ab0
commit
b22f83560c
|
@ -81,5 +81,6 @@
|
|||
<classpathentry kind="var" path="MAVEN_REPO/antlr/jars/antlr-2.7.2.jar"/>
|
||||
<classpathentry kind="var" path="MAVEN_REPO/ldapsdk/jars/ldapsdk-4.1.jar"/>
|
||||
<classpathentry sourcepath="/MAVEN_REPO/springframework/src/spring-2.0-m2.zip" kind="var" path="MAVEN_REPO/springframework/jars/spring-hibernate3-2.0-m2.jar"/>
|
||||
<classpathentry kind="var" path="MAVEN_REPO/cas/jars/cas-server-3.0.4.jar"/>
|
||||
<classpathentry kind="output" path="target/eclipseclasses"/>
|
||||
</classpath>
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
<type>jar</type>
|
||||
<url>http://www.yale.edu/tp/cas</url>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cas</groupId>
|
||||
<artifactId>cas-server</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<type>jar</type>
|
||||
<url>http://www.ja-sig.org/products/cas/</url>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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.acegisecurity.adapters.cas3;
|
||||
|
||||
import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.AuthenticationManager;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.authentication.handler.AuthenticationException;
|
||||
import org.jasig.cas.authentication.handler.AuthenticationHandler;
|
||||
import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
|
||||
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Provides JA-SIG CAS 3 authentication by delegating to the Acegi
|
||||
* <code>AuthenticationManager</code>.
|
||||
* </p>
|
||||
* <p>
|
||||
* This class would be configured in the
|
||||
* <code>webapp/WEB-INF/deployerConfigContext.xml</code> file in the CAS
|
||||
* distribution.
|
||||
* </p>
|
||||
*
|
||||
* @author Scott Battaglia
|
||||
* @version $Id$
|
||||
*
|
||||
* @see AuthenticationHandler
|
||||
* @see AuthenticationManager
|
||||
*/
|
||||
public final class CasAuthenticationHandler extends
|
||||
AbstractUsernamePasswordAuthenticationHandler {
|
||||
|
||||
private Log log = LogFactory.getLog(this.getClass());
|
||||
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
protected boolean authenticateUsernamePasswordInternal(
|
||||
final UsernamePasswordCredentials credentials)
|
||||
throws AuthenticationException {
|
||||
|
||||
final Authentication authenticationRequest = new UsernamePasswordAuthenticationToken(
|
||||
credentials.getUsername(), credentials.getPassword());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Attempting to authenticate for user: "
|
||||
+ credentials.getUsername());
|
||||
}
|
||||
|
||||
try {
|
||||
this.authenticationManager.authenticate(authenticationRequest);
|
||||
} catch (final org.acegisecurity.AuthenticationException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log
|
||||
.debug("Authentication request for "
|
||||
+ credentials.getUsername() + "failed: "
|
||||
+ e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Authentication request for " + credentials.getUsername()
|
||||
+ " successful.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void afterPropertiesSetInternal() throws Exception {
|
||||
Assert.notNull(this.authenticationManager,
|
||||
"authenticationManager cannot be null.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the Acegi <code>AuthenticationManager</code> to delegate
|
||||
* to.
|
||||
*
|
||||
* @param authenticationManager
|
||||
* the Acegi AuthenticationManager that knows how to authenticate
|
||||
* users.
|
||||
*/
|
||||
public void setAuthenticationManager(
|
||||
final AuthenticationManager authenticationManager) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue