diff --git a/.classpath b/.classpath index 28746b6663..addc33f1d5 100644 --- a/.classpath +++ b/.classpath @@ -81,5 +81,6 @@ + diff --git a/adapters/cas/project.xml b/adapters/cas/project.xml index d93d1c34d2..9bba7816ef 100644 --- a/adapters/cas/project.xml +++ b/adapters/cas/project.xml @@ -18,6 +18,14 @@ jar http://www.yale.edu/tp/cas + + + cas + cas-server + 3.0.4 + jar + http://www.ja-sig.org/products/cas/ + diff --git a/adapters/cas/src/main/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandler.java b/adapters/cas/src/main/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandler.java new file mode 100644 index 0000000000..6a51e3e022 --- /dev/null +++ b/adapters/cas/src/main/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandler.java @@ -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; + +/** + *

+ * Provides JA-SIG CAS 3 authentication by delegating to the Acegi + * AuthenticationManager. + *

+ *

+ * This class would be configured in the + * webapp/WEB-INF/deployerConfigContext.xml file in the CAS + * distribution. + *

+ * + * @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 AuthenticationManager to delegate + * to. + * + * @param authenticationManager + * the Acegi AuthenticationManager that knows how to authenticate + * users. + */ + public void setAuthenticationManager( + final AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } +}