You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by funnycoder <of...@hotmail.com> on 2014/07/03 09:04:33 UTC
Guice integration: configuration params injection does not work
Hi,
I need to extend standard FormAuthenticationFilter class and override
onLoginFailure() method.
The problem is that in this case I can't inject a shiro.{prop} configuration
params.
---------------------------------------------------------------
public class ExtendedFormAuthenticationFilter extends
FormAuthenticationFilter {
private final Logger logger = LoggerFactory.getLogger(getClass());
public ExtendedFormAuthenticationFilter() {
logger.info("ExtendedFormAuthenticationFilter instantiated");
logger.info("Login URL: " + getLoginUrl());
}
@Override
protected boolean onLoginFailure(AuthenticationToken token,
AuthenticationException e, ServletRequest request, ServletResponse response)
{
// some custom logic
}
}
---------------------------------------------------------------
class SecurityModule extends ShiroWebModule {
SecurityModule(ServletContext servletContext) {
super(servletContext);
}
@Override
protected void configureShiroWeb() {
// filters
Key<ExtendedFormAuthenticationFilter> EXTENDED_AUTHC =
Key.get(ExtendedFormAuthenticationFilter.class);
// realms
bindRealm().to(IniRealm.class);
addFilterChain("/login", EXTENDED_AUTHC);
addFilterChain("/myapp/**", EXTENDED_AUTHC);
// params
bindConstant().annotatedWith(Names.named("shiro.loginUrl")).to("/newlogin");
}
@Provides
@Singleton
IniRealm loadIniRealm(Ini ini) {
IniRealm realm = new IniRealm(ini);
return realm;
}
@Provides
@Singleton
Ini loadShiroIni() {
return Ini.fromResourcePath("classpath:shiro.ini");
}
}
---------------------------------------------------------------
10:51:01,383 INFO main
myapp.security.ExtendedFormAuthenticationFilter:<init>:29 -
ExtendedFormAuthenticationFilter instantiated
10:51:01,383 INFO main
myapp.security.ExtendedFormAuthenticationFilter:<init>:30 - Login URL:
/login.jsp
---------------------------------------------------------------
Is it possible to fix ?
Regards,
Alex
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Guice-integration-configuration-params-injection-does-not-work-tp7580060.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Guice integration: configuration params injection does not work
Posted by funnycoder <of...@hotmail.com>.
I've found solution for this issue.
---------------------------------------------------------------
class SecurityModule extends ShiroWebModule {
SecurityModule(ServletContext servletContext) {
super(servletContext);
}
@Override
protected void configureShiroWeb() {
bindConstant().annotatedWith(Names.named("loginUrl")).to("/newlogin");
bindRealm().to(IniRealm.class);
addFilterChain("/login",
Key.get(ExtendedFormAuthenticationFilter.class));
}
@Provides
@Singleton
IniRealm loadIniRealm(Ini ini) {
IniRealm realm = new IniRealm(ini);
return realm;
}
@Provides
@Singleton
Ini loadShiroIni() {
return Ini.fromResourcePath("classpath:shiro.ini");
}
}
---------------------------------------------------------------
public class ExtendedFormAuthenticationFilter extends
FormAuthenticationFilter {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Inject
@Override
public void setLoginUrl(@Named("loginUrl") String loginUrl) {
super.setLoginUrl(loginUrl);
}
@Override
protected boolean onLoginFailure(AuthenticationToken token,
AuthenticationException e, ServletRequest request, ServletResponse response)
{
// some custom logic
}
}
---------------------------------------------------------------
Regards,
Alex
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Guice-integration-configuration-params-injection-does-not-work-tp7580060p7580061.html
Sent from the Shiro User mailing list archive at Nabble.com.