[英]Secure a web resource by roles using keycloak
我目前正在检查keycloak示例:servlet-authz。 并了解到它通过web.xml保护了一个Web资源:
<security-constraint>
<web-resource-collection>
<web-resource-name>All Resources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
<role-name>admin</role-name>
<role-name>user_premium</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>KEYCLOAK</auth-method>
<realm-name>servlet-authz</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
<security-role>
<role-name>user_premium</role-name>
</security-role>
我的问题是,它可以动态实现吗? 不使用web.xml? 例如,我有一个新角色role_guest,只能访问/ guest / * url。 如何配置? 我检查了所有的例子,但到目前为止都没有。
如果要动态加载所有角色,则必须在auth-constraint
和security-role
包含web.xml(不幸)和通配符(*)。
所有角色都允许使用web.xml片段:
...
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>KEYCLOAK</auth-method>
<realm-name>servlet-authz</realm-name>
</login-config>
<security-role>
<role-name>*</role-name>
</security-role>
...
我不知道是否有办法自动将每个角色附加到一个url-pattern
,其中包含角色名称。
使用Keycloak适配器版本4.4.0.Final在Wildfly 11上测试流量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.