EasyJWeb的验证系统的Bug及使用心得
2007-12-28 20:31
363 查看
今天使用EasyJWeb的“人性化”验证功能,发现了存在不少Bug,这里发出来并与大家分享。
我们系统中的User基类的内容如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@javax.persistence.Table(name = "UserInfo")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Inheritance(strategy = InheritanceType.JOINED)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@FormPO(inject = "name,email,password,problem,solution")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public abstract class User implements Principal, UserDetails ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private static final long serialVersionUID = 2915030721449148555L;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Id
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@GeneratedValue(strategy = GenerationType.TABLE)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Long id;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 30, unique = true)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Field(validator = @Validator(name = "string", value = "blank;trim;max:30", required = true))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String name;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 100)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Field(validator = @Validator(name = "email", required = true, value = "max:100"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String email;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 64)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Field(validator = @Validator(name = "string", value = "blank;trim;max:64", required = true))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String password;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Date registerTime;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer status = 1;// -1锁定、0未审核、1通过
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer loginTimes;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Date lastLoginTime = new Date();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String lastLoginIP;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String problem; // 密码提问
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String solution; // 答案
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Long imUin;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@ManyToMany(mappedBy = "users", cascade = CascadeType.ALL)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@JoinTable(name = "User_Roles")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private List
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@ManyToMany(cascade = CascadeType.ALL)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@JoinTable(name = "User_Permissions")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private List
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Transient
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private GrantedAuthority[] authorities;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
下面是一个User的子类,PersonalUser的内容如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@FormPO(label="个人用户信息",disInject="score,activeCode")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Entity
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class PersonalUser extends User ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 积分
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer score;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 真实姓名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
@Field(name="真实姓名", validators = ...{ @Validator(name = "string", value = "msg:请填写您的真实姓名。;blank;min:2;max:10", required = true) })
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 20)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String trueName;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 身份证号
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
@Field(name="身份证号", validators = ...{ @Validator(name="regex",value="msg:请填写有效的证件号码。;expression:/d{15}|/d{17}[/dXx]", required = true) })
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 20)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String identifyCard;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 电话
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
@Field(name="电话", validators = ...{ @Validator(name = "required", value = "msg:您填写的身份证号码有误,请检查后重新提交。;blank;min:7;max:15", required = true) })
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 20)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String tel;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 手机
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
@Field(name="手机", validators = ...{ @Validator(name = "regex", value = "expression:/d{11}", required = true) })
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
@Column(length = 25)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private String mobile;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
..
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
下面是个人用户注册保存时的源代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/** *//**
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* 保存个人注册信息
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @param form
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
* @return
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public Page savePersonal(WebForm form) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PersonalUser user = form.toPo(PersonalUser.class);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(hasErrors())return page("registerStep3Personal");//跳回注册页面
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//执行注册操作
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.userService.addPersonalUser(user);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return page("success");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
执行这个程序,针对name及password等属性的验证能正常工作。但PersonalUser中针对电话号码、身份证等属性无论如何都不能正常执行验证功能,真是郁闷啊。后来仔细发现,不但没有执行验证,尽然连值也没有传入到持久层中。因此,应该是不允许注入这些属性值的问题所允许的。于是跟踪了一下源代码,在com.easyjf.web.core.FormHandler中发现如下的内容:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public boolean checkFormPOWriteEnabled(Class clz,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
java.beans.PropertyDescriptor property) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean ret = true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FormPO formPO = (FormPO) clz.getAnnotation(FormPO.class);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean haveFound = false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (formPO != null) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String injectEnabled = formPO.inject();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (StringUtils.hasLength(injectEnabled)) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ret = ("," + injectEnabled + ",").indexOf(","
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ property.getName() + ",") >= 0;// 找不到,则不注入
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (ret)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
haveFound = true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String disInject = formPO.disInject();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (StringUtils.hasLength(disInject))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ret = ("," + disInject + ",").indexOf(","
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ property.getName() + ",") < 0;// 找到,则不注入
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!ret)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
haveFound = true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!haveFound && clz.getSuperclass() != Object.class)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ret = checkFormPOWriteEnabled(clz.getSuperclass(), property);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ret;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
这个方法写得比较有意思,几行代码转了几个弯,真考验人的逻辑思维啊。他是在检查@FormPO标签中的inject或disInject属性情况。在子类中若找不到标签属性,还会到父类中去找。感觉这里问题就出来了,如果父类跟子类使用的注入指标标签不一致的话,应该就会出现问题。也就是说如果父类中使用inject来标签注入的属性,而子类中使用disInject来指定不可以注入的属性。则先在子类中发现这个属性没找到,则haveFound就为false,则到父类中去找,由于父类使用inject标识,而一般他不会把子类的属性也标识进去,所以肯定得到的结果也是false。因此,就会给我们无法注入的结果。
这应该是跟子类中想要表达的意思不一致:“也即子类规定的是除了disInject中规定的属性以外(或者是所有属性,即inject及disInject都没有用的情况下)的所有属性都可以注入”这一功能无法实现。
这不知道算不算上是一个Bug。但想了一下,这个Bug也可以完全避免,只要把父类及子类的注入标识写一致就OK了。于是我把两者的注入标识都改成了使用disInject属性。如下:
正常的User基类
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@FormPO(disInject = "id,status,loginTimes,lastLoginTime,lastLoginIP,roles,permissions,authorities")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public abstract class User implements Principal, UserDetails ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
子类PersonalUser
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
@FormPO(label="个人用户信息",disInject="score")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class PersonalUser extends User ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
..
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
然后执行刚才的用户注册程序,验证系统终于“人性化”地按我要的出来了。呵呵,大功告成,立即走人。
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1821187
相关文章推荐
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- EasyJWeb的验证系统的Bug及使用心得
- Mac系统使用心得
- IOS开发笔记之十四——使用系统相册或相机导致状态栏隐藏的问题(bug总结四)
- 使用jQuery插件开发一个完整验证功能的超酷动态留言版系统
- 关于vsftpd同时使用系统用户和虚拟用户验证