-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Password validation
PostPosted: Thu May 26, 2011 5:03 am 
Newbie

Joined: Sun May 01, 2011 2:23 pm
Posts: 10
Hi,

I am moving from springmodules validation to hibernate-validation with annotation.

All has gone smoothly apart from the administration input user-password field.

I am using @size(min=4,max=8).

The validation is failing on the max=8.

I think this is because I am also using 'spring security' to encode the password in the database.

So my question is what is the way forward here - can I restrict the validation to just the user input or is there a better way ?

Thanks for any help.


Top
 Profile  
 
 Post subject: Re: Password validation
PostPosted: Fri May 27, 2011 12:28 am 
Newbie

Joined: Sun Feb 27, 2011 11:40 am
Posts: 8
If the plain-text password is not stored in the domain model then obviously you cannot validate plain-text by annotating the domain model.

You could store the plain-text password temporarily in an @Transient field. Use @NotNull on the encrypted field and @Size on the transient plain-text field. Or annotate the UI model and do additional validation before encryption.


Top
 Profile  
 
 Post subject: Re: Password validation
PostPosted: Fri May 27, 2011 8:10 am 
Newbie

Joined: Sun May 01, 2011 2:23 pm
Posts: 10
Thanks I will give this a go


Top
 Profile  
 
 Post subject: Re: Password validation
PostPosted: Sun May 29, 2011 9:27 am 
Newbie

Joined: Sun May 01, 2011 2:23 pm
Posts: 10
I have had a go at this and got it to work but very slightly differently.

I have:

@Transient
@Size(min=4,max=8)
private String validationPassword;

and

private String password;

As you implied you cannot have @NotNull here on a @Transient field.

However I could not put @NotNull on the persisted / encoded 'password' field as it would fail initial validation.

Thanks


Top
 Profile  
 
 Post subject: Re: Password validation
PostPosted: Sun May 29, 2011 11:26 am 
Newbie

Joined: Sun Feb 27, 2011 11:40 am
Posts: 8
Use groups. For example:

Code:
@Size(min=4,max=8,groups=PasswordValidation.class)
@NotNull(groups=PasswordValidation.class)
@Transient
private String validationPassword;

@NotNull
private String password;


then

Code:
public interface PasswordValidation {} // empty interface for group


and

Code:
// initial validation of plain-text password ONLY:
validator.validate(myDomainObject, PasswordValidation.class);

// later, validate EVERYTHING ELSE (including @NotNull on 'password'):
validator.validate(myDomainObject); // default group


You can have @NotNull with @Transient as long as you control WHEN the field is validated (with groups). The transient field will be reset to null the next time you find the object from the database.


Top
 Profile  
 
 Post subject: Re: Password validation
PostPosted: Sun May 29, 2011 4:08 pm 
Newbie

Joined: Sun May 01, 2011 2:23 pm
Posts: 10
Thanks I had come across groups but I am using Spring MVC and from what I found I was not convinced I could get Spring to work with groups but I will check again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.