mit Spring-Boot einzuloggen ich die folgenden Filter an KonfigurationShiro nicht nach gescheiterten Versuchen, loginUrl Umleitung in
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilter() {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
Map<String, String> filterChainDefinitionMapping = new HashMap<>();
/*
* URL path expressions are evaluated against an incoming request in the order they are defined and the FIRST MATCH WINS. For example, let's asume that there are the following chain definitions:
/account/** = ssl, authc
/account/signup = anon
If an incoming request is intended to reach /account/signup/index.html (accessible by all 'anon'ymous users), it will never be handled!. The reason is that the /account/** pattern matched the incoming request first and 'short-circuited' all remaining definitions.
Always remember to define your filter chains based on a FIRST MATCH WINS policy!
* */
filterChainDefinitionMapping.put("/login.html", "authc");
filterChainDefinitionMapping.put("/logout", "logout");
filterChainDefinitionMapping.put("/css/**", "anon");
filterChainDefinitionMapping.put("/register/**", "anon");
filterChainDefinitionMapping.put("/**", "authc");
shiroFilter.setFilterChainDefinitionMap(filterChainDefinitionMapping);
shiroFilter.setSecurityManager(securityManager());
shiroFilter.setLoginUrl("/login.html");
shiroFilter.setSuccessUrl("/");
shiroFilter.setUnauthorizedUrl("/unauthorized.html");
Map<String, Filter> filters = new HashMap<>();
filters.put("anon", new AnonymousFilter());
filters.put("authc", new FormAuthenticationFilter());
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setRedirectUrl("/login.html?logout");
filters.put("logout", logoutFilter);
filters.put("roles", new RolesAuthorizationFilter());
filters.put("user", new UserFilter());
shiroFilter.setFilters(filters);
return shiroFilter;
}
Jedes Mal, wenn ich versuche, mit falschen Anmeldeinformationen anmelden, um die Umleitung nie passiert. Ich bekomme das "shiroLoginFailure" -Attribut mit der UnknownUserException.
(Logging mit den richtigen Anmeldeinformationen in funktioniert gut)
Irgendwelche Ideen?
'FormAuthenticationFilter' des' onLoginFailure() 'method führt keine Umleitung durch, so dass die Filterkette des Servlet in den Spring-Framework-Code eingeht. Da Sie kein RequestMapping für "loginUrl" implementieren, wird der 404-Fehler zurückgegeben. Eine Lösung besteht darin, 'FormAuthenticationFilter' abzuleiten, um 'onLoginFailure()' neu zu definieren, so dass es Umleitungen durchführen kann. – Hong