无法使用 Config Bean 和 @RunAs 填充 DB

Unable to populate BD whit ConfigBean and @RunAs

我正在使用 ConfigBean 来填充我的 BD,如下所示:

@Singleton
@Startup 
@RunAs("Administrator")
public class ConfigBean {

    @EJB
    private ClientBean clientBean;

    @EJB
    private AdministratorBean adminstratorBean;

    @PostConstruct
    public void populateDB() {
        try{
            clientBean.create(new ClientDTO("client1", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Av. José Maceda", "918 923 232"));
            clientBean.create(new ClientDTO("client2", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Av. Alberto Alves", "+00351 256 0033 12"));
            adminstratorBean.create(new AdministratorDTO("administrator1", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Director"));
        }catch(Exception ex){
            System.out.println(ex);
        }
    }

我的两个豆子都是这样的:

@POST
@RolesAllowed("Administrator")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response create(AdministratorDTO administratorDTO){...}

至于我的web.xml:

...
<login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>dae_project_realm</realm-name>
    </login-config>
    <security-role>
        <description/>
        <role-name>Client</role-name>
    </security-role>
    <security-role>
        <role-name>Administrator</role-name>
    </security-role>
</web-app>

一切似乎都很好。但是,当我 运行 调用应用程序和方法 populateDB 时,我不断收到错误消息:

javax.ejb.AccessLocalException: Client not authorized for this invocation

我看到了一些有趣的链接,但我仍然无法使用它:

为了使用@RunAs,我们需要创建该角色的用户。 为此,您需要执行以下步骤。

  1. 在管理控制台中打开 GlashFish
  2. 打开配置>服务器配置>安全>领域
  3. 点击文件
  4. 点击管理用户
  5. 点击新建
  6. 像这样创建用户:
  7. 更新@RunAs 以使用新创建的用户:

    @Singleton
    @Startup 
    @RunAs("BOB") //BOB belongs to the desired group 
    public class ConfigBean {
    
        @EJB
        private ClientBean clientBean;
    
        @EJB
        private AdministratorBean adminstratorBean;
    
        @PostConstruct
        public void populateDB() {
            try{
                clientBean.create(new ClientDTO("client1", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Av. José Maceda", "918 923 232"));
                clientBean.create(new ClientDTO("client2", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Av. Alberto Alves", "+00351 256 0033 12"));
                adminstratorBean.create(new AdministratorDTO("administrator1", "secret", "Manuel", "dae.ei.ipleiria@gmail.com", "Director"));
            }catch(Exception ex){
                System.out.println(ex);
            }
        }