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

时间:2020-08-18 08:07:04

标签: java maven soap 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.agh.soa

artifactId:实验室

  1. 我在Hello.java中创建一个类lab/lab-ejb/src/main/java/pl/edu/agh/soa
@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. 我将user3添加到a​​dd-user.sh
  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. 我在users.properties中创建roles.propertieslab/lab-ejb/src文件

1 个答案:

答案 0 :(得分:0)

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

check the security documentation