views:

760

answers:

3

Hello All...

I am developing app using Spring Web MVC, Hibernate..

Now, i have my login page configuration like :

<bean name="/uservalidate.htm" class="UserValidateFormController">
        <property name="sessionForm" value="true"/>
        <property name="commandName" value="User"/>
        <property name="commandClass" value="User"/>
        <property name="formView" value="login"/>
        <property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
         <property name="validator">
            <bean class="LoginValidator"/>
        </property>
        <property name="successView" value="layout.jsp"/>

Now, after submitting from login page control goes to Validator Class i.e. LoginValidator..

But, at that class i am not getting reference of my userSecurityProcessor which gives me server side data..

Can anybody please suggest, how can i check Username and Password in my Validator class..?

Thanks in advance..

A: 

Hi,

public void validate(Object target, Errors errors) {
 User user = (User) target;
 String username = user.getUsername();
 String password = user.getPassword();
 ..........
}
novice
The question implies that UserSecurityProcessor is needed to validate username and password (which seems like a good approach to me).
JacobM
Maniganda Prakash : That's not i have mentioned in my question.. I have clearly specify that how can i get ref of userSecurityProcessor bean in my Validator class.... Both the ans of bpapa and of Rakesh Juyal are perfect..
Nirmal
Yes, my mistake.
novice
+1  A: 

You can' get userSecurityProcessor in Validator. The only object you will get is, the commandObject. In your case it is User

But in case you need that, then you will have to bind it in Validator

<bean id="myValidator" class="LoginValidator">
    <property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
</bean>

Now, bind this validator with your Form.

Rakesh Juyal
+2  A: 

Create an instance of LoginValidator as a separate bean. In your LoginValidator, add a userSecurityProcessor property. Then in your config file inject a reference to an instance of a IUserSecurityProcessor just as you do above. So something like this:

<bean name="loginValidator" class="LoginValidator">
<property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
</bean>

Then change

<bean name="/uservalidate.htm" class="UserValidateFormController">
    <property name="sessionForm" value="true"/>
    <property name="commandName" value="User"/>
    <property name="commandClass" value="User"/>
    <property name="formView" value="login"/>
    <property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
     <property name="validator">
        <bean class="LoginValidator"/>
    </property>
    <property name="successView" value="layout.jsp"/>

to

<bean name="/uservalidate.htm" class="UserValidateFormController">
    <property name="sessionForm" value="true"/>
    <property name="commandName" value="User"/>
    <property name="commandClass" value="User"/>
    <property name="formView" value="login"/>
    <property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
     <property name="validator" ref = "loginValidator"/>
    <property name="successView" value="layout.jsp"/>
bpapa
wow! isn't this what i have already said :)
Rakesh Juyal