首页 > 解决方案 > 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用 add-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.propertiesroles.properties归档lab/lab-ejb/src

标签: javamavensoapwildfly

解决方案


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

检查安全文档


推荐阅读