使用 wicket auth-role 对 wicket 组件进行授权
我正在使用 wicket 1.4.9 并实现了 spring + wicket auth-role 并基于页面上的角色使用 @AuthorizeInstantiation 。我有多个自定义角色。
我已按照此链接来实现基础知识: https://cwiki.apache.org/WICKET/spring -security-and-wicket-auth-roles.html
之后,我实现了自己的 UserDetailsService 以从数据库中拥有自己的角色/用户。
现在,如何通过组件(例如链接、按钮)对角色进行控制?喜欢 链接 A 只能由 SUPER_USER、DR_MANAGER 访问。 (角色来自数据库)。
我已经这样做了,它似乎有效,但这是这样做的好方法吗? OrbitWebSession 的类型为 AuthenticatedWebSession。
@Override
public boolean isVisible() {
if(OrbitWebSession.get().getRoles().hasRole("SUPER_USER")){
return true;
}
return false;
}
谢谢。
I am using wicket 1.4.9 and implemented spring + wicket auth-role and using @AuthorizeInstantiation based on roles on pages. I have multiple custom roles.
I have followed this link to implement the basics:
https://cwiki.apache.org/WICKET/spring-security-and-wicket-auth-roles.html
After that I have implemented my own UserDetailsService to have my own roles/users from database.
Now, How can I impose controls on roles with components eg, Links,Buttons ? like
link A can be accessed only by SUPER_USER, DR_MANAGER. (roles comes from database).
I have done like this and it seems to work, but is that the good way to do this? OrbitWebSession is of type AuthenticatedWebSession.
@Override
public boolean isVisible() {
if(OrbitWebSession.get().getRoles().hasRole("SUPER_USER")){
return true;
}
return false;
}
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
覆盖始终是可见的,这是一个很大的痛苦。请查看
MetaDataRoleAuthorizationStrategy
。您可以使用Action RENDER
以及您想要允许的角色来调用authorize(Component component, Action action, String Roles)
。这样,只要在您的 Web 应用程序中注册了授权策略,该组件(无论它是什么)都会自动对其他角色隐藏。基本上它的作用与 Holms 的回答相同,只是您不必对任何内容进行子类化。Overriding isVisible all the time is a major pain. Take a look at
MetaDataRoleAuthorizationStrategy
instead. You callauthorize(Component component, Action action, String roles)
withAction RENDER
, and the roles you want to allow. This way the component, whatever it is, is automatically hidden for other roles provided that the authorization strategy is registered in your webapplication. Basically it does the same thing as Holms answer, except you don't have to subclass anything.你走在正确的轨道上,我要做的唯一改变是:
这样你就不会意外地覆盖它的默认可见行为,例如,如果父组件不可见。
You are in the right track, the only change I would do is:
That way you don't accidentally override its default visible behavior for example if the parent component is not visible.
使用 @AuthorizeAction 注释,您可以控制是否根据角色呈现组件。它非常容易使用,但是您必须对要授权的组件进行子类化。
查看Wicket 示例 - 授权以获取一些工作代码。
Using the @AuthorizeAction annotation you can control wether the component is rendered or not based on roles. It's quite easy to use, but you have to subclass the component that you want to authorize.
Check out Wicket Examples - Authorization for some working code.