I am trying to implement custom annotation in spring as follows:- Test annotation is as follows
@Documented
@Target( { ElementType.METHOD, ElementType.FIELD })
@Constraint(validatedBy=CheckUser.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Test {
String user();
}
And for validation I have written CheckUser class as follows::-
private String xyz;
@Override
public void initialize(Test user) {
xyz=user.toString();
}
@Override
public boolean isValid(Principal principal, ConstraintValidatorContext context) {
if(principal.getName().equalsIgnoreCase(xyz))
return true;
else
return false;
}
But its not working. Can some one tell me what is wrong here??
In security as well as application context I have written
<Secured:global-method-security secured-annotations="enabled" pre-post-annotations="enabled" jsr250-annotations="enabled"/>