2016-04-29 6 views
0

У меня возникли серьезные проблемы с тем, как перенаправить на страницу, определенную в конфигурации плиток.Spring 4 Security Tiles 3 Custom Success Handler

Использование Spring Security 4 с аннотациями и плитки 3.

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; 
} 

ответ

0

Я выяснил, что моя проблема была нанесена самим себе, как обычно. Я забыл определить «admin» или «user» выше, в файле views.xml (tiles configuration). Как только я настроил страницы в views.xml, он начал работать как ожидалось. Благодаря!