我试图变得更加熟悉Wildfly安全配置,并在理解服务器端配置(如standalone.xml)和应用程序端配置(如web.xml和jboss-web.xml)之间的选项之间存在一些问题。
关于基于Wildfly servlet安全示例的此配置,我有几个问题。我已经尝试过了,并且可以正常工作,但是对我来说有些事情还不清楚。
这是JBoss CLI配置脚本
?
web.xml
# 1. Add the JDBC security realm creation
/subsystem=elytron/jdbc-realm=servlet-security-jdbc-realm:add(\
principal-query=[\
{sql="SELECT PASSWORD FROM USERS WHERE USERNAME = ?", data-source="MySQLDS", clear-password-mapper={password-index=1}},\
{sql="SELECT R.NAME, 'Roles' FROM USERS_ROLES UR INNER JOIN ROLES R ON R.ID = UR.ROLE_ID INNER JOIN USERS U ON U.ID = UR.USER_ID WHERE U.USERNAME = ?", data-source="MySQLDS", attribute-mapping=[{index=1, to=roles}]}])
# 2. Add a simple role decoder for the "roles" attribute mapping
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=roles)
# 3. Configure the servlet-security-quickstart security domain
/subsystem=elytron/security-domain=servlet-security-quickstart-sd:add(\
default-realm=servlet-security-jdbc-realm, \
realms=[{realm=servlet-security-jdbc-realm, role-decoder=from-roles-attribute}], \
permission-mapper=default-permission-mapper)
# 4. Configure the HTTP Authentication Factory
/subsystem=elytron/http-authentication-factory=servlet-security-quickstart-http-auth:add(\
http-server-mechanism-factory=global,\
security-domain=servlet-security-quickstart-sd,\
mechanism-configurations=[{mechanism-name=BASIC,mechanism-realm-configurations=[{realm-name=RealmUsersRoles}]}])
# 5. Configure Undertow's application security domain
/subsystem=undertow/application-security-domain=servlet-security-quickstart:add(\
http-authentication-factory=servlet-security-quickstart-http-auth)
jboss-web.xml
<?xml version="1.0"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>RealmUsersRoles</realm-name>
</login-config>
</web-app>
这是我用作基础https://github.com/wildfly/quickstart/tree/master/servlet-security
的Wildfly示例的链接这是我所有基于此示例进行修改的代码https://github.com/usharik/GeekBrainsJavaEE/tree/master/lesson8-security
答案 0 :(得分:1)
web.xml
中配置401 Unauthorized
(WWW-Authenticate
标头)时,它仅显示在浏览器中。如果在web.xml
中配置了名称,则使用服务器名中的名称。