Hi all,

I try to insert my "AuthentificatedInterceptor" in the stack, but now 
nothing works.

First, I had a login page, with login/password fields, and the LoginAction 
getted well the parameters' value. 

Now, with my new Interceptor, the LoginAction gets empty values from my 
login and password fields.

What's wrong ? I tried a lot of order's combinations in the stack, but I 
did'nt find the good one. 

My login.jsp :
        <s:form action="login" validate="true">
            <table border="0" cellspacing="0" cellpadding="0" 
align="center" width="400"> 
                <s:hidden name="user.loginAttempt" value="%{'1'}" />
                <s:actionerror/>
                <s:textfield label="%{getText('login.login ')}" 
name="user.login" size="20" maxlength="20" tabindex="1"/>
                <s:password label="%{getText('login.pwd')}" 
name="user.pwd" size="20" maxlength="20" tabindex="2"/> 
                <s:submit label="%{getText('login.submit')}" 
method="login">
                    <s:param name="colspan" value="%{2}" />
                    <s:param name="align" value="%{'center'}" /> 
                </s:submit>
            </table>
        </s:form>

My LoginAction.java :
public class LoginAction extends ActionSupport implements 
ServletRequestAware {
    private Logger log = Logger.getLogger(LoginAction.class);
    private HttpServletRequest request;
    private UserVO user;
    private AuthentifyUserServiceInterface authentifyUserService;
    
    public String login () {
        String vTarget; 
        try {
            // Call the Service layer for authentification.
            if (authentifyUserService.authentifyUser(user)) {
                setSessionAttribute(request, Constants.USER, user.getLogin 
());
                vTarget = SUCCESS;
            } else {
                addActionError(getText("errors.loginko"));
                vTarget = INPUT;
            }
        }
        catch (TechnicalException e) { 
            addActionError(getText("error.message"));
            vTarget = ERROR;
        }
        return vTarget;
    }
    protected void setSessionAttribute(HttpServletRequest request, String 
key, Object o) { 
        if(o != null) {
            request.getSession().setAttribute(key, o);
        }
    }
    public void setUser(UserVO user) {
        this.user = user;
    }
    public void setAuthentifyUserService( 
            AuthentifyUserServiceInterface authentifyUserService) {
        this.authentifyUserService = authentifyUserService;
    }
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }
}

My LoginInterceptor.java :
public class LoginInterceptor extends AbstractInterceptor implements 
StrutsStatics {
    private static final String LOGIN_ATTEMPT = "user.loginAttempt ";

    public String intercept (ActionInvocation invocation) throws Exception 
{
        final ActionContext context = invocation.getInvocationContext ();
        HttpServletRequest request = (HttpServletRequest) 
context.get(HTTP_REQUEST);
        HttpSession session =  request.getSession (true);

        Object user = session.getAttribute(Constants.USER);
        if (user == null) {
            String loginAttempt = request.getParameter (LOGIN_ATTEMPT);
            if (! StringUtils.isBlank (loginAttempt) ) {
                return invocation.invoke ();
            }
            return "notLogged";
        } else { 
            return invocation.invoke();
        }
    }
}

My struts.xml :
<interceptors>
            <interceptor name="login" 
class="com.abw.util.LoginInterceptor" /> 

            <interceptor-stack name="crmStack">
                <interceptor-ref name="exception"/>
                <interceptor-ref name="alias"/>
                <interceptor-ref name="servlet-config" /> 
                <interceptor-ref name="login" />
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="prepare" />
                <interceptor-ref name="chain" /> 
                <interceptor-ref name="model-driven" />
                <interceptor-ref name="fileUpload" />
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="static-params" />
                <interceptor-ref name="params" />
                <interceptor-ref name="conversionError" />
                <interceptor-ref name="validation" />
                <interceptor-ref name="workflow" />
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="crmStack"/>

The fact is that first I would like to have the hidden parameter in the 
login.jsp being not an attribute in the userVO bean. But if I set 
<s:hidden name="somethingOther" value="%{'1'}" />, I have a 
ParametersInterceptor Exception saying "ParametersInterceptor - 
[setParameters]: Unexpected Exception catched". 

Then, How could I have my values in my LoginAction ? I would like to do 
the authentifyUserService.authentifyUser() in the Action, not in the 
Interceptor. And I suppose this will allow me to have my values in my 
others forms too. 

Thanks for your help.

Regards,

Michaƫl. 

Reply via email to