使用 MetaDataKey 进行 Wicket 授权
我正在尝试为我的 Wicket 应用程序实施一个简单的授权策略。我实现了自己的 AuthorizationStrategy (扩展 IAuthorizationStrategy)。
http://old.nabble.com/Authorization-strategy-help-td18948597。 html 阅读上面的链接后,我认为使用元数据驱动的授权比使用注释更有意义。
所以我有一个简单的 RoleCheck 类,
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"));
在我的授权策略类中,我尝试获取与该组件关联的元数据:
public boolean isActionAuthorized(Component component, Action action) {
if (action.equals(Component.RENDER)) {
RoleCheck privCheck = (RoleCheck) component.getMetaData(EditControlToolBar.priv);
if (privCheck != null) {
...
}
}
但是 getMetaData 给出了错误
“绑定不匹配:通用方法
getMetaData(MetaDataKey
类型) Component
不适用于参数 (MetaDataKey
)。推断的类型RoleCheck
不是 有界参数的有效替代“
任何帮助将不胜感激。谢谢
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
typeComponent
is not applicable for the arguments
(MetaDataKey<RoleCheck>
). The inferred typeRoleCheck
is not a
valid substitute for the bounded parameter "
Any help would be appreciated. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 RoleCheck 类应该实现 Serialized。
您使用的是 Wicket 1.4 吗?在这种情况下,我建议按照以下方式继续:
将其添加到组件:
并执行授权:
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 :