野飞:服务器重启后授权失败

huangapple go评论111阅读模式
英文:

Wildfly: authorization fails after server restart

问题

  1. 我首先进行所需的设置(如下所述)。一切工作正常,但当我重新启动 `standalone.sh` 并执行一个SOAP请求时,我只收到以下响应:
  2. <html>
  3. <head>
  4. <title>错误</title>
  5. </head>
  6. <body>未经授权</body>
  7. </html>
  8. 在带有 `standalone.sh` 的终端中,我收到以下消息:
  9. ERROR [org.jboss.security](default task-1PBOX00261:无法加载用户/密码/角色文件:java.io.IOExceptionPBOX00072:找不到属性文件 users.properties/defaultUsers.properties
  10. 我应该怎么做才能使授权工作?
  11. # 设置 #
  12. 这是我为设置一切所做的:
  13. 1. 我运行 `mvn archetype:generate` 并从 `org.wildfly.archetype:wildfly-javaee7-webapp-ear-blank-archetype` 原型创建项目
  14. groupIdpl.edu.agh.soa
  15. artifactIdlab
  16. 2. 我在 `lab/lab-ejb/src/main/java/pl/edu/agh/soa` 中创建一个名为 `Hello.java` 的类:
  17. ```java
  18. @Stateless
  19. @WebService
  20. @SecurityDomain("domain1")
  21. @DeclareRoles({"developer"})
  22. @WebContext(
  23. authMethod="BASIC",
  24. transportGuarantee="NONE")
  25. public class Hello {
  26. private List<String> subjects = new ArrayList<>();
  27. private String name;
  28. private String surname;
  29. @WebMethod
  30. @RolesAllowed("developer")
  31. @XmlElementWrapper(name="subjects")
  32. @XmlElement(name="subject")
  33. public List<String>
  34. listSubjects(@WebParam(name="filter") String filter) {
  35. List<String> filtered = new ArrayList<>();
  36. for(String elem : this.subjects) {
  37. if(elem.contains(filter)) {
  38. filtered.add(elem);
  39. }
  40. }
  41. return filtered;
  42. }
  43. @WebMethod
  44. @RolesAllowed("developer")
  45. @WebResult
  46. public String
  47. addSubject(@WebParam(name="subj") String subj) {
  48. this.subjects.add(subj);
  49. return "After add: " + this.subjects.toString();
  50. }
  51. @WebMethod
  52. @RolesAllowed("developer")
  53. @WebResult
  54. public String
  55. editName(String name) {
  56. String before = this.name;
  57. this.name = name;
  58. return "Before: " + before;
  59. }
  60. @WebMethod
  61. @RolesAllowed("developer")
  62. @WebResult
  63. public String
  64. editSurname(String surname) {
  65. String before = this.surname;
  66. this.surname = surname;
  67. return "Before: " + before;
  68. }
  69. }
  1. 我使用 add-user.sh 添加了 user3
  2. 使用 jboss-cli.sh 创建一个新的安全域,我在其中粘贴了以下内容:

/subsystem=security/security-domain=domain1/:add(cache-type=default)

/subsystem=security/security-domain=domain1/authentication=classic:add(login-modules=[{"code"=>"UsersRoles","flag"=>"required","module-options"=>[("usersProperties"=>"users.properties"),("rolesProperties"=>"roles.properties")]}])

  1. 我在 lab/lab-ejb/src 中创建了 users.propertiesroles.properties 文件
  1. <details>
  2. <summary>英文:</summary>
  3. I first do the setup needed (described below). Everything works, but when I restart `standalone.sh` and do a SOAP request I only get this response:
  4. &lt;html&gt;
  5. &lt;head&gt;
  6. &lt;title&gt;Error&lt;/title&gt;
  7. &lt;/head&gt;
  8. &lt;body&gt;Unauthorized&lt;/body&gt;
  9. &lt;/html&gt;
  10. And in the terminal with `standalone.sh` I get:
  11. ERROR [org.jboss.security] (default task-1) PBOX00261: Failed to load users/passwords/roles files: java.io.IOException: PBOX00072: Properties file users.properties/defaultUsers.properties not found
  12. What should I do to make the authorization work?
  13. # Setup #
  14. This is what I do to setup everything:
  15. 1. I run `mvn archetype:generate` and create the project from `org.wildfly.archetype:wildfly-javaee7-webapp-ear-blank-archetype` archetype
  16. groupId: pl.edu.agh.soa
  17. artifactId: lab
  18. 2. I create a class `Hello.java` in `lab/lab-ejb/src/main/java/pl/edu/agh/soa`:

@Stateless
@WebService
@SecurityDomain("domain1")
@DeclareRoles({"developer"})
@WebContext(
authMethod="BASIC",
transportGuarantee="NONE")
public class Hello {

  1. private List&lt;String&gt; subjects = new ArrayList&lt;&gt;();
  2. private String name;
  3. private String surname;
  4. @WebMethod
  5. @RolesAllowed(&quot;developer&quot;)
  6. @XmlElementWrapper(name=&quot;subjects&quot;)
  7. @XmlElement(name=&quot;subject&quot;)
  8. public List&lt;String&gt;
  9. listSubjects(@WebParam(name=&quot;filter&quot;) String filter) {
  10. List&lt;String&gt; filtered = new ArrayList&lt;&gt;();
  11. for(String elem : this.subjects) {
  12. if(elem.contains(filter)) {
  13. filtered.add(elem);
  14. }
  15. }
  16. return filtered;
  17. }
  18. @WebMethod
  19. @RolesAllowed(&quot;developer&quot;)
  20. @WebResult
  21. public String
  22. addSubject(@WebParam(name=&quot;subj&quot;) String subj) {
  23. this.subjects.add(subj);
  24. return &quot;After add: &quot; + this.subjects.toString();
  25. }
  26. @WebMethod
  27. @RolesAllowed(&quot;developer&quot;)
  28. @WebResult
  29. public String
  30. editName(String name) {
  31. String before = this.name;
  32. this.name = name;
  33. return &quot;Before: &quot; + before;
  34. }
  35. @WebMethod
  36. @RolesAllowed(&quot;developer&quot;)
  37. @WebResult
  38. public String
  39. editSurname(String surname) {
  40. String before = this.surname;
  41. this.surname = surname;
  42. return &quot;Before: &quot; + before;
  43. }

}

  1. 3. I add `user3` with add-user.sh
  2. 4. Create a new security domain with `jboss-cli.sh`, there I paste:
  3. `/subsystem=security/security-domain=domain1/:add(cache-type=default)`
  4. `/subsystem=security/security-domain=domain1/authentication=classic:add(login-modules=[{&quot;code&quot;=&gt;&quot;UsersRoles&quot;,&quot;flag&quot;=&gt;&quot;required&quot;,&quot;module-options&quot;=&gt;[(&quot;usersProperties&quot;=&gt;&quot;users.properties&quot;),(&quot;rolesProperties&quot;=&gt;&quot;roles.properties&quot;)]}])`
  5. 5. I create `users.properties` and `roles.properties` files in `lab/lab-ejb/src`
  6. </details>
  7. # 答案1
  8. **得分**: 0
  9. 你可以尝试将 `roles.properties` `users.properties` 放在另一个目录中,例如:`\wildfly-20.0.1.Final\standalone\configuration` 或者 `src/main/resources`
  10. [查阅安全文档][1]
  11. [1]: https://docs.wildfly.org/20/Admin_Guide.html#Security_Realms
  12. <details>
  13. <summary>英文:</summary>
  14. You can try to put the `roles.properties` and `users.properties` in another directory e.g. : `\wildfly-20.0.1.Final\standalone\configuration` or `src/main/resources`
  15. [check the security documentation][1]
  16. [1]: https://docs.wildfly.org/20/Admin_Guide.html#Security_Realms
  17. </details>

huangapple
  • 本文由 发表于 2020年8月18日 16:07:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63464372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定