我试图对WildFly安全配置更加熟悉,并且在理解服务器端选项(如standalone.xml )和应用程序端信任(如web.xml和jboss-web.xml )之间的关系方面存在一些问题。
关于这个配置,我有几个问题,这是基于Wildfly安全示例的。我已经试过了,但是有几件事情对我来说并不清楚。
下面是JBoss CLI配置脚本
# 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)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>jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>servlet-security-quickstart</security-domain>
</jboss-web>下面是一个指向Wildfly示例的链接,我使用它作为基本https://github.com/wildfly/quickstart/tree/master/servlet-security
下面是基于这个示例的所有代码,并对https://github.com/usharik/GeekBrainsJavaEE/tree/master/lesson8-security做了一些修改
发布于 2019-04-03 20:27:44
web.xml中配置。401 Unauthorized ( WWW-Authenticate头)时,它就会显示在浏览器中。如果在web.xml中配置了ream名称,则使用服务器配置中的ream名称。https://stackoverflow.com/questions/55298178
复制相似问题