Here is what I use in my embedded server app. Hope this helps.
public class ShiroEnvironmentListener implements ServletContextListener {
private final RosserApplicationConfiguration configuration;
private final EnvironmentLoaderListener environmentLoaderListener;
private final Realm rosserRealm;
private final SystemAudit systemAudit;
private final CustomerFolderDAO customerFolderDAO;
public ShiroEnvironmentListener(RosserApplicationConfiguration
configuration, EnvironmentLoaderListener environmentLoaderListener, Realm
rosserRealm, SystemAudit systemAudit, CustomerFolderDAO customerFolderDAO) {
this.configuration = configuration;
this.environmentLoaderListener = environmentLoaderListener;
this.rosserRealm = rosserRealm;
this.systemAudit = systemAudit;
this.customerFolderDAO = customerFolderDAO;
}
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext servletContext = sce.getServletContext();
servletContext.setInitParameter("shiroConfigLocations",
configuration.getShiroConfigLocations());
environmentLoaderListener.contextInitialized(sce);
WebEnvironment webEnvironment =
WebUtils.getWebEnvironment(servletContext);
WebSecurityManager webSecurityManager =
webEnvironment.getWebSecurityManager();
((RealmSecurityManager) webSecurityManager).setRealm(rosserRealm);
ModularRealmAuthenticator authenticator =
(ModularRealmAuthenticator) ((DefaultWebSecurityManager)
webSecurityManager).getAuthenticator();
authenticator.setAuthenticationListeners(Lists.<AuthenticationListener>newArrayList(new
SystemAuditAuthenticationListener(systemAudit, customerFolderDAO)));
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
environmentLoaderListener.contextDestroyed(sce);
}
}
shan wrote
> Stephen, thanks for the code snippet - one question though, where in this
> mechanism are you inserting your custom Realm into the Security Manager?
--
View this message in context:
http://shiro-user.582556.n2.nabble.com/Embedded-web-server-startup-and-static-SecurityManager-tp7579754p7580089.html
Sent from the Shiro User mailing list archive at Nabble.com.