Changed appContextLocation to use a String (to enable unit testing), fixed logger outputs, improved handling of nulls and empty Strings.

This commit is contained in:
Ben Alex 2004-03-30 04:45:39 +00:00
parent 65314d99e3
commit c224728d79
1 changed files with 11 additions and 20 deletions

View File

@ -17,8 +17,6 @@ package net.sf.acegisecurity.adapters.resin;
import com.caucho.http.security.AbstractAuthenticator; import com.caucho.http.security.AbstractAuthenticator;
import com.caucho.vfs.Path;
import net.sf.acegisecurity.Authentication; import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.AuthenticationException; import net.sf.acegisecurity.AuthenticationException;
import net.sf.acegisecurity.AuthenticationManager; import net.sf.acegisecurity.AuthenticationManager;
@ -28,9 +26,7 @@ import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.File;
import java.security.Principal; import java.security.Principal;
@ -63,16 +59,16 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
//~ Instance fields ======================================================== //~ Instance fields ========================================================
private AuthenticationManager authenticationManager; private AuthenticationManager authenticationManager;
private Path appContextLocation; private String appContextLocation;
private String key; private String key;
//~ Methods ================================================================ //~ Methods ================================================================
public void setAppContextLocation(Path appContextLocation) { public void setAppContextLocation(String appContextLocation) {
this.appContextLocation = appContextLocation; this.appContextLocation = appContextLocation;
} }
public Path getAppContextLocation() { public String getAppContextLocation() {
return appContextLocation; return appContextLocation;
} }
@ -90,8 +86,7 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
if (!(principal instanceof PrincipalAcegiUserToken)) { if (!(principal instanceof PrincipalAcegiUserToken)) {
if (logger.isWarnEnabled()) { if (logger.isWarnEnabled()) {
logger.warn( logger.warn(
"Expected passed principal to be of type PrincipalSpringUserToken but was " "Expected passed principal to be of type PrincipalAcegiUserToken");
+ principal.getClass().getName());
} }
return false; return false;
@ -105,23 +100,19 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
public void init() throws ServletException { public void init() throws ServletException {
super.init(); super.init();
if (appContextLocation == null) { if ((appContextLocation == null) || "".equals(appContextLocation)) {
throw new ServletException("appContextLocation must be defined"); throw new ServletException("appContextLocation must be defined");
} }
if (key == null) { if ((key == null) || "".equals(key)) {
throw new ServletException("key must be defined"); throw new ServletException("key must be defined");
} }
File xml = new File(appContextLocation.getPath()); if (Thread.currentThread().getContextClassLoader().getResource(appContextLocation) == null) {
throw new ServletException("Cannot locate " + appContextLocation);
if (!xml.exists()) {
throw new ServletException(
"appContextLocation does not seem to exist - try specifying WEB-INF/resin-springsecurity.xml");
} }
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(xml ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(appContextLocation);
.getAbsolutePath());
Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true); Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
if (beans.size() == 0) { if (beans.size() == 0) {
@ -131,7 +122,7 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
String beanName = (String) beans.keySet().iterator().next(); String beanName = (String) beans.keySet().iterator().next();
authenticationManager = (AuthenticationManager) beans.get(beanName); authenticationManager = (AuthenticationManager) beans.get(beanName);
logger.info("ResinSpringAuthenticator Started"); logger.info("ResinAcegiAuthenticator Started");
} }
protected Principal loginImpl(String username, String credentials) { protected Principal loginImpl(String username, String credentials) {