我很难弄清楚如何重定向到瓷砖配置中定义的页面。
使用带有注释和 Tiles 3 的 Spring Security 4。
下面的CustomSuccessHandler
工作,但它不能解析targetUrl
到瓷砖配置中定义的页面。
@Component
public class CustomSuccessHandler extends SimpleUrlAuthenticationSuccessHandler{
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Override
protected void handle(HttpServletRequest request,
HttpServletResponse response, Authentication authentication) throws IOException {
String targetUrl = determineTargetUrl(authentication);
if (response.isCommitted()) {
System.out.println("Can't redirect");
return;
}
test();
redirectStrategy.sendRedirect(request, response, targetUrl);
}
static void test() {
}
protected String determineTargetUrl(Authentication authentication) {
String url="";
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
List<String> roles = new ArrayList<String>();
for (GrantedAuthority a : authorities) {
roles.add(a.getAuthority());
}
if (isAdmin(roles)) {
url = "/admin";
} else if (isUser(roles)) {
url = "/user";
} else {
url="accessDenied";
}
return url;
}