I'm using v2.0 and have decided to try and integrate things with Spring which is employed elsewhere in my webapp. Specifically I'd like to get the realm as a bean from the Spring WebApplicationContext. This way I could either set the realm from within the filter init method (ignoring the filter config file), or perhaps more generically, there's a Realm wrapper class built which accepts the spring bean name as a realm-param, and delegates to this on all methods. This latter approach would require these changes -
- Authenticator implementations have a field to hold the realm, but surely this isn't required, since the realm can be accessed from the SecurityRequestWrapper argument. As it is I'd have to hack Authenticator(s) to allow get/set on the realm field.
- Realm implementations could have an init method (as suggested on this list) to access servletContext (and hence the spring app context)
Or is there a simpler way I'm not seeing?
Tim
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using v2.0 and have decided to try and integrate things with Spring which is employed elsewhere in my webapp. Specifically I'd like to get the realm as a bean from the Spring WebApplicationContext. This way I could either set the realm from within the filter init method (ignoring the filter config file), or perhaps more generically, there's a Realm wrapper class built which accepts the spring bean name as a realm-param, and delegates to this on all methods. This latter approach would require these changes -
- Authenticator implementations have a field to hold the realm, but surely this isn't required, since the realm can be accessed from the SecurityRequestWrapper argument. As it is I'd have to hack Authenticator(s) to allow get/set on the realm field.
- Realm implementations could have an init method (as suggested on this list) to access servletContext (and hence the spring app context)
Or is there a simpler way I'm not seeing?
Tim
Create a new spring config file which JUST has your login definition declared.
Then in your realm implementation try something like this :
* @return Returns the loginDelegate.
*/
public synchronized LoginDelegate getLoginDelegate() {
if (loginDelegate == null) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("com/..../loginContext.xml");
loginDelegate = (LoginDelegate) ctx.getBean("loginDelegate");
}
return loginDelegate;
}
Now you can get the delegate from inside your REALM implementation and hand off the actual work of login to your delegate...