有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Wildfly:服务器重新启动后授权失败

我首先进行必要的设置(如下所述)。一切正常,但当我重新启动standalone.sh并执行SOAP请求时,我只得到以下响应:

<html>
   <head>
      <title>Error</title>
   </head>
   <body>Unauthorized</body>
</html>

在带有standalone.sh的终端中,我得到:

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

我应该怎么做才能使授权生效

设置

这是我设置所有内容所做的:

  1. 我运行mvn archetype:generate并从org.wildfly.archetype:wildfly-javaee7-webapp-ear-blank-archetype原型创建项目

groupId:pl.edu。啊。soa

人工智能:实验室

  1. 我在lab/lab-ejb/src/main/java/pl/edu/agh/soa中创建了一个类Hello.java
@Stateless
@WebService
@SecurityDomain("domain1")
@DeclareRoles({"developer"})
@WebContext(
   authMethod="BASIC",
   transportGuarantee="NONE")
public class Hello {

    private List<String> subjects = new ArrayList<>();
    private String name;
    private String surname;

    @WebMethod
    @RolesAllowed("developer")
    @XmlElementWrapper(name="subjects")
    @XmlElement(name="subject")
    public List<String>
    listSubjects(@WebParam(name="filter") String filter) {
        List<String> filtered = new ArrayList<>();
        for(String elem : this.subjects) {
            if(elem.contains(filter)) {
                filtered.add(elem);
            }
        }
        return filtered;
    }

    @WebMethod
    @RolesAllowed("developer")
    @WebResult
    public String
    addSubject(@WebParam(name="subj") String subj) {
        this.subjects.add(subj);
        return "After add: " + this.subjects.toString();
    }

    @WebMethod
    @RolesAllowed("developer")
    @WebResult
    public String
    editName(String name) {
        String before = this.name;
        this.name = name;
        
        return "Before: " + before;
    }

    @WebMethod
    @RolesAllowed("developer")
    @WebResult
    public String
    editSurname(String surname) {
        String before = this.surname;
        this.surname = surname;
        
        return "Before: " + before;
    }
}
  1. 我用adduser添加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) 个答案

  1. # 1 楼答案

    您可以尝试将roles.propertiesusers.properties放在另一个目录中,例如:\wildfly-20.0.1.Final\standalone\configurationsrc/main/resources

    check the security documentation