I am trying to implement a simple authorization strategy for my Wicket application. I am implemented my own AuthorizationStrategy (extending IAuthorizationStrategy).
http://old.nabble.com/Authorization-strategy-help-td18948597.html
After reading the above link, I figured it makes more sense to use metadata-driven authorization than one using Annotations.
So I have a simple RoleCheck class
public class RoleCheck {
private String privilege;
public RoleCheck(String priv) {
this.privilege = priv;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
public String getPrivilege() {
return privilege;
}
}
I add it a component:
public static MetaDataKey<RoleCheck> priv = new MetaDataKey<RoleCheck>() {};
editLink.setMetaData(priv, new RoleCheck("Update"));
And in my Authorization Strategy class, I try to get the metadata associated with the component:
public boolean isActionAuthorized(Component component, Action action) {
if (action.equals(Component.RENDER)) {
RoleCheck privCheck = (RoleCheck) component.getMetaData(EditControlToolBar.priv);
if (privCheck != null) {
...
}
}
However the getMetaData gives an error
“Bound mismatch: The generic method
getMetaData(MetaDataKey<M>)of
typeComponentis not applicable for the arguments
(MetaDataKey<RoleCheck>). The inferred typeRoleCheckis not a
valid substitute for the bounded parameter “
Any help would be appreciated. Thank you
Your RoleCheck class should implement Serializable.
And are you using Wicket 1.4 ? In which case I’d suggest proceeding this way :
To add it to a componenet :
And to perform the authorization :