java - Tomcat DataSourceRealm 未显示任何日志记录
问题描述
我正在使用 Jersey3 和 Tomcat10 在 Java 中实现 REST-API。为了为特定角色提供/限制对某些端点的访问,我想使用DataSourceRealm
.
我的配置context.xml
是这样的:
<Resource type="javax.sql.DataSource"
name="jdbc/myDB"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//localhost:1521/orcl"
username="xx"
password="xx"/>
<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
dataSourceName="jdbc/myDB" localDataSource="true"
userTable="USERS" userNameCol="USERNAME" userCredCol="PASSWORD"
userRoleTable="USER_ROLES" roleNameCol="ROLENAME"/>
也在我的dataSource
context.xml 中定义,可以使用 JNDI 访问。
在我的web.xml
我定义了以下安全约束:
<security-constraint>
<web-resource-collection>
<web-resource-name>Some name</web-resource-name>
<url-pattern>/api/data</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Administrator</role-name>
</auth-constraint>
</security-constraint>
所以每个GET
带有模式/api/data
的请求都需要角色Administrator
表USER_ROLES
有一个带有USERNAME=admin
和的条目ROLENAME=Administrator
。
另外,我添加了这些行:
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>Administrator</role-name>
</security-role>
为了做显而易见的事情。
相应的端点定义如下:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/data")
@RolesAllowed({"Administrator"})
public Response getData(...)
将这些行添加到我的日志配置中:
org.apache.catalina.realm.level = ALL
org.apache.catalina.realm.useParentHandlers = true
org.apache.catalina.authenticator.level = ALL
org.apache.catalina.authenticator.useParentHandlers = true
在带有身份验证标头的 GET 中调用 http://localhost:8080/myapp/api/data Basic YWRtaW46YWRtaW4=
--> admin:admin
到目前为止,限制访问是可行的,我的DataSourceRealm
似乎已被考虑在内。尽管没有人在进行身份验证时的日志。
为了查看来自 DataSourceRealm 的日志,我需要添加什么?任何帮助/输入将不胜感激。
解决方案
推荐阅读
- javascript - Javascript 变量 ESRI api
- javascript - 如何将 jQuery 翻译成 AngularJS
- php - 如何在 HTML 中的多个输入的多个值上使用一个值数组
- rxjs - 去抖和缓冲一个 rxjs 订阅
- c# - 满足应用程序范围的服务调用的任务扩展
- c++ - Visual Studio 调试源文件目录保存在哪里?
- outlook - 打印 Outlook 项目时隐藏 CustomProperty
- xml - 用 pyspark 中的值包装 rdd.saveAsTextFile 的输出
- xslt - 如何遍历多个 XML 输入文件并将相关的属性值复制到 HTML 输出表中的一行
- python - Python 和 OpenCV:在保持纵横比的同时将图像大小调整为正方形