[英]Spring 4 Security Tiles 3 Custom Success Handler
I'm having a rough time figuring out how to redirect to a page defined in tiles configuration. 我花了点时间弄清楚如何重定向到tile配置中定义的页面。
Using Spring Security 4 with annotations and Tiles 3. 将Spring Security 4与注释和Tiles一起使用。
The CustomSuccessHandler
below works but it doesn't resolve the targetUrl
to the page defined in tiles configuration. 下面的CustomSuccessHandler
可以工作,但不能将targetUrl
解析为tile配置中定义的页面。
@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;
}
I figured out that my problem was self-inflicted, as usual. 我发现自己的问题像往常一样是自欺欺人的。 I had neglected to define "admin"or "user" above, in my views.xml (tiles configuration) file. 我忽略了在views.xml(文件配置)文件中定义“管理员”或“用户”。 Once I configured the pages in views.xml, it started working as expected. 一旦我在views.xml中配置了页面,它就会按预期开始工作。 Thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.