Redirecionar Login para diferentes URLs dependendo da ROLE!

2 respostas
silvars

Dear all!

Uma outra ajuda em SPRING SECURITY!

Gostaria de saber como direcionar para diferentes paginas o login dos usuários de acordo com as ROLES.

Exemplo:

ROLES_ADMIN
ROLE_USER
ROLE_XXX

ROLER_ADMIN > index.xhtml
ROLE_USER> login.xhtml
ROLE_XXX> xxx.xhtml

É possível?

Agradeço a ajuda!

Rodrigo

2 Respostas

silvars

Resolvido galera!

xml de config, implementar uma classe que extenda SimpleUrlAuthenticationFailureHandler (erro no login) / SimpleUrlAuthenticationSuccessHandler (sucesso no login)

<bean id="customAuthenticationFailureHandler"
	class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"/>

<bean id="customAuthenticationSuccessHandler"
	class="com.volkswagen.vwte.security.authentication.CustomRedirectSuccessAuthenticationVWTE"/>

E a classe

public class CustomRedirectSuccessAuthenticationVWTE extends SimpleUrlAuthenticationSuccessHandler {

private static ResourceBundle redirectsProperties;
private static String REDIRECT_VISITOR_SUCCESS = "redirect.visitor.success";

static {
    redirectsProperties = ResourceBundle.getBundle("redirects");
}

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    // as visitor, send to catalog

    handle(request, response, authentication);
    clearAuthenticationAttributes(request);

    this.setAlwaysUseDefaultTargetUrl(Boolean.TRUE);
    this.setDefaultTargetUrl(redirectsProperties.getString(REDIRECT_VISITOR_SUCCESS));

    this.setTargetUrlParameter(redirectsProperties.getString(REDIRECT_VISITOR_SUCCESS));

}

@Override
protected String determineTargetUrl(HttpServletRequest arg0, HttpServletResponse arg1) {
    return redirectsProperties.getString(REDIRECT_VISITOR_SUCCESS);
}

}

Qualquer problema ou erro só mandar!

Obrigado!

M

Tenhu o mesmo problema que o seu, tenhu 3 roles diferentes e quero que apos o usuario logar no sistema ele seja redicerionado para a index da sua role

ex:

Diretorios

/admin
/aluno
/professor

Roles:

ROLE_GER
ROLE_ALUNO
ROLE_PROFESSOR

Ao logar no sistema o usuario seja redirecionado da seguinte forma

ROLE_GER => /admin/index.xhtml
ROLE_ALUNO => /aluno/index.xhtml
ROLE_PROFESSOR => /professor/index.xhtml.

silvars, Tentei seguir seu exemplo porem da erro ao instaciar a classe que extende a SimpleUrlAuthenticationSuccessHandler

Aguem pode me ajudar.

Criado 31 de janeiro de 2011
Ultima resposta 21 de set. de 2012
Respostas 2
Participantes 2