Struts 2 - Como gerenciar login?

Olá!

Eu já consegui pegar o nome do usuário e senha e validar no banco, agora a próxima página que vou chamar será uma área restrita do usuário que logou… como faço pra gerenciar esse login, de uma forma segura?!

valeu!

Utilize interceptors em suas ações para verificar, por exemplo, se a sessão está expirada…

Vai um exemplo…

package br.com.soppm.interceptor;

import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.beanutils.MethodUtils;
import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

//mais imports ...

public class AuthorizationInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -8107879777030309644L;

	private static final transient Logger LOG = Logger.getLogger(AuthorizationInterceptor.class);

	@SuppressWarnings("unchecked")
    public String intercept(ActionInvocation ai) throws Exception {

		String retorno = Action.LOGIN;

		Object action = ai.getAction();
		Map session = ai.getInvocationContext().getSession();

		UsuarioVO usuario = (UsuarioVO) session.get(UsuarioConstantes.USUARIO_SESSAO);

		if(usuario != null) {
			retorno = ai.invoke();
		}

		return retorno;
	}
}

No seu xml de config. da acao…

        <interceptors>
            <!-- SEUS INTERCEPTORS-->
            <interceptor name="authorizationInterceptor" class="br.com.soppm.interceptor.AuthorizationInterceptor" />

            <interceptor-stack name="newDefaultStack">
            	<interceptor-ref name="authorizationInterceptor" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>
	
	<default-interceptor-ref name="newDefaultStack" />

ESTUDE ISSO…

Espero ter ajudado!

flw!

valeu!! muito obrigado!

[quote=juloko666]Utilize interceptors em suas ações para verificar, por exemplo, se a sessão está expirada…

Vai um exemplo…

package br.com.soppm.interceptor;

import java.lang.reflect.Method;
import java.util.Map;

import org.apache.commons.beanutils.MethodUtils;
import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

//mais imports ...

public class AuthorizationInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -8107879777030309644L;

	private static final transient Logger LOG = Logger.getLogger(AuthorizationInterceptor.class);

	@SuppressWarnings("unchecked")
    public String intercept(ActionInvocation ai) throws Exception {

		String retorno = Action.LOGIN;

		Object action = ai.getAction();
		Map session = ai.getInvocationContext().getSession();

		UsuarioVO usuario = (UsuarioVO) session.get(UsuarioConstantes.USUARIO_SESSAO);

		if(usuario != null) {
			retorno = ai.invoke();
		}

		return retorno;
	}
}

No seu xml de config. da acao…

        &lt;interceptors&gt;
            &lt;!-- SEUS INTERCEPTORS--&gt;
            &lt;interceptor name="authorizationInterceptor" class="br.com.soppm.interceptor.AuthorizationInterceptor" /&gt;

            &lt;interceptor-stack name="newDefaultStack"&gt;
            	&lt;interceptor-ref name="authorizationInterceptor" /&gt;
                &lt;interceptor-ref name="defaultStack" /&gt;
            &lt;/interceptor-stack&gt;
        &lt;/interceptors&gt;
	
	&lt;default-interceptor-ref name="newDefaultStack" /&gt;

ESTUDE ISSO…

Espero ter ajudado!

flw![/quote]

Olá juloko666,

Li a sua sugestão e achei bem fácil (aparentemente). Só que eu nao tenho os .jar dessa implementação. Você tem como me passar o link para download??
Valeu.