【发布时间】:2015-02-02 22:27:12
【问题描述】:
我一直在尝试使用 WildFly 8.1.0、immutant 和friend 获得一个简单的基本身份验证示例。我愿意发布任何所需的代码,但我不确定此时需要什么。现在,我假设我的standalone.xml、web.xml 和 jboss-web.xml 都包含正确的数据——可能不是这样,但现在我只是深入研究这个问题。
我有一个带有简单 /test 资源的应用程序。我已经将它部署在 WildFly 上并使用基本身份验证来尝试访问它。另外,我检查了我的 application-roles.properties 和 application-users.properties 文件,它们看起来都很好。
当我尝试登录时,我看到来自 WildFly 的以下跟踪:
14:30:36,681 TRACE [org.jboss.security](默认任务 1)PBOX000210: defaultLogin,登录上下文: javax.security.auth.login.LoginContext@4c89fc2c,主题: Subject(1313538088).principals=org.jboss.security.SimplePrincipal@99148614(tester-na)org.jboss.security.SimpleGroup@83654093(Roles(members:elm-nss-admin))org.jboss.security.SimpleGroup@ 83654093(CallerPrincipal(members:tester-na))
用户是tester-na,可以看到是elm-nss-admin的成员。
当我使用错误的密码时,WildFly 会捕捉到它,而我的应用程序从不进行任何检查。但是,当我发送正确的密码时,会记录上述跟踪并调用我的身份验证处理程序。
问题是我的身份验证处理程序失败,因为对 getUserPrincipal() 的调用返回 NULL。资源受到保护,这是我的安全限制:
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Resources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
当我使用 LDAP 时,这不是问题。我认为这是因为 LDAP 提供了一个证书,而 WildFly 传递了 cookie。
但是使用基本身份验证,我没有得到 cookie,除非请求,否则我不会输出调试输出,它非常冗长,但相关位是::cookies {}, :context , :session nil
我猜 getUserPrincipal() 失败是因为我仍在进行身份验证?
那么,关于如何从 WildFly 获取用户数据/权限以便朋友可以传递适当的数据以进行身份验证/授权的任何想法?
#更新:我能够使用与生产应用程序相同的 XML 文件创建一个简单的应用程序,并且它没有失败。出于兴趣,以及像我一样使用 stackoverflow 来回答问题的人,以下是相关部分:
来自安全领域中的standalone.xml:
<security-realm name="ApplicationRealm">
<authentication>
<local default-user="$local" allowed-users="*"/>
<properties path="application-users.properties" relative-to="jboss.server.config.dir"/>
</authentication>
<authorization>
<properties path="application-roles.properties" relative-to="jboss.server.config.dir"/>
</authorization>
</security-realm>
在<subsystem xmlns="urn:jboss:domain:security:1.2"> 我有:
<security-domain name="other" cache-type="default">
<authentication>
<login-module code="Remoting" flag="optional">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
<login-module code="RealmDirect" flag="required">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
</authentication>
</security-domain>
<security-domain name="jboss-web-policy" cache-type="default">
<authorization>
<policy-module code="Delegating" flag="required"/>
</authorization>
</security-domain>
<security-domain name="jboss-ejb-policy" cache-type="default">
<authorization>
<policy-module code="Delegating" flag="required"/>
</authorization>
</security-domain>
在我的 web.xml 文件中(在 war-resources/WEB-INF 文件夹中):
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>ApplicationRealm</realm-name>
</login-config>
jboss.xml文件,在同一目录下是:
<jboss-web>
<context-root></context-root>
<security-domain>other</security-domain>
</jboss-web>
由于这些设置适用于我的简单应用程序,我将开始寻找特定项目的内容,以了解为什么 WildFly 没有在我的生产代码中为我提供用户。
任何有用的建议将不胜感激。甚至只是关于从哪里开始寻找的建议。
#问题解决了。事实证明,在我尝试授权访问特定资源之前,用户已被注销。 :P
【问题讨论】:
-
如果您将解决方案作为答案发布,我将删除我的副本
标签: authentication cookies jboss wildfly