Changes to support testing, and enhanced error detection at startup time.
This commit is contained in:
parent
3fa1534c94
commit
2e1b4b4ffc
|
@ -148,13 +148,15 @@ public class CatalinaAcegiUserRealm extends RealmBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRole(Principal principal, String role) {
|
public boolean hasRole(Principal principal, String role) {
|
||||||
if (!(principal instanceof PrincipalAcegiUserToken)) {
|
if ((principal == null) || (role == null)) {
|
||||||
if (logger.isWarnEnabled()) {
|
return false;
|
||||||
logger.warn(
|
|
||||||
"Expected passed principal to be of type PrincipalSpringUserToken but was "
|
|
||||||
+ principal.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(principal instanceof PrincipalAcegiUserToken)) {
|
||||||
|
logger.warn(
|
||||||
|
"Expected passed principal to be of type PrincipalAcegiUserToken but was "
|
||||||
|
+ principal.getClass().getName());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,37 +165,13 @@ public class CatalinaAcegiUserRealm extends RealmBase {
|
||||||
return test.isUserInRole(role);
|
return test.isUserInRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the method that Catalina will use to start the container.
|
||||||
|
*
|
||||||
|
* @throws LifecycleException if a problem is detected
|
||||||
|
*/
|
||||||
public void start() throws LifecycleException {
|
public void start() throws LifecycleException {
|
||||||
super.start();
|
this.start(true);
|
||||||
|
|
||||||
if (appContextLocation == null) {
|
|
||||||
throw new LifecycleException("appContextLocation must be defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == null) {
|
|
||||||
throw new LifecycleException("key must be defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
File xml = new File(System.getProperty("catalina.base"),
|
|
||||||
appContextLocation);
|
|
||||||
|
|
||||||
if (!xml.exists()) {
|
|
||||||
throw new LifecycleException(
|
|
||||||
"appContextLocation does not seem to exist - try specifying conf/springsecurity.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(xml
|
|
||||||
.getAbsolutePath());
|
|
||||||
Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
|
|
||||||
|
|
||||||
if (beans.size() == 0) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Bean context must contain at least one bean of type AuthenticationManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
String beanName = (String) beans.keySet().iterator().next();
|
|
||||||
authenticationManager = (AuthenticationManager) beans.get(beanName);
|
|
||||||
logger.info("CatalinaSpringUserRealm Started");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getName() {
|
protected String getName() {
|
||||||
|
@ -221,4 +199,50 @@ public class CatalinaAcegiUserRealm extends RealmBase {
|
||||||
protected Principal getPrincipal(String arg0) {
|
protected Principal getPrincipal(String arg0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a method to load the container adapter without delegating to
|
||||||
|
* the superclass, which cannot operate outside the Catalina container.
|
||||||
|
*
|
||||||
|
* @throws LifecycleException if a problem is detected
|
||||||
|
*/
|
||||||
|
protected void startForTest() throws LifecycleException {
|
||||||
|
this.start(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void start(boolean startParent) throws LifecycleException {
|
||||||
|
if (startParent) {
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((appContextLocation == null) || "".equals(appContextLocation)) {
|
||||||
|
throw new LifecycleException("appContextLocation must be defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((key == null) || "".equals(key)) {
|
||||||
|
throw new LifecycleException("key must be defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
File xml = new File(System.getProperty("catalina.base"),
|
||||||
|
appContextLocation);
|
||||||
|
|
||||||
|
if (!xml.exists()) {
|
||||||
|
throw new LifecycleException(
|
||||||
|
"appContextLocation does not seem to exist in "
|
||||||
|
+ xml.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(xml
|
||||||
|
.getAbsolutePath());
|
||||||
|
Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
|
||||||
|
|
||||||
|
if (beans.size() == 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Bean context must contain at least one bean of type AuthenticationManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
String beanName = (String) beans.keySet().iterator().next();
|
||||||
|
authenticationManager = (AuthenticationManager) beans.get(beanName);
|
||||||
|
logger.info("CatalinaSpringUserRealm Started");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue