检票授权使用MetaDataKey [英] Wicket Authorization Using MetaDataKey
问题描述
我想实现我的Wicket应用程序一个简单的授权策略。我实现我自己的AuthorizationStrategy(扩大IAuthorizationStrategy)。
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
看完上面的链接后,我想这更有意义,使用元数据驱动的授权,与使用注解。
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.
所以我有一个简单的RoleCheck类
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;
}
}
我添加组件:
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) {
...
}
}
但可用getMetaData给出了一个错误
However the getMetaData gives an error
三寸不匹配:通用方法的getMetaData(MetaDataKey&LT; M&GT;)
的
键入组件
不适用于参数
( MetaDataKey&LT; RoleCheck&GT;
)。该推断的类型 RoleCheck
不是
为界参数有效替代品
"Bound mismatch: The generic method
getMetaData(MetaDataKey<M>)
of typeComponent
is not applicable for the arguments (MetaDataKey<RoleCheck>
). The inferred typeRoleCheck
is not a valid substitute for the bounded parameter "
任何帮助将是AP preciated。谢谢
Any help would be appreciated. Thank you
推荐答案
您RoleCheck类应该实现Serializable接口。
Your RoleCheck class should implement Serializable.
和您使用的检票1.4吗?在这种情况下,我会建议在进行这样的:
And are you using Wicket 1.4 ? In which case I'd suggest proceeding this way :
public class RolePermissionKey extends MetaDataKey<RoleCheck> {
public static final RolePermissionKey KEY = new RolePermissionKey();
}
要它添加到componenet:
To add it to a componenet :
editLink.setMetaData(RolePermissionKey.KEY, new RoleCheck("Update"));
和执行权限:
RoleCheck privCheck = component.getMetaData(RolePermissionKey.KEY)
这篇关于检票授权使用MetaDataKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!