首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Jboss 6中使用@SecurityDomain?

如何在Jboss 6中使用@SecurityDomain?
EN

Stack Overflow用户
提问于 2018-01-11 05:02:56
回答 1查看 338关注 0票数 0

在我的standalone-full.xml中,我得到了这个安全域:

代码语言:javascript
复制
<security-domain name="my-security-domain" cache-type="default">  
   <authentication>  
        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required" >  
             <module-option name="usersProperties" value="/path/to/users.properties"/>  
             <module-option name="rolesProperties" value="/path/to/roles.properties"/>  
        </login-module>  
   </authentication>  
</security-domain>

...but它似乎不是从我的代码中提取的,在我得到的MDB中:

代码语言:javascript
复制
@MessageDriven(name = "MessageMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/DLQ"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@SecurityDomain("my-security-domain")
@RunAsPrincipal("123")
//@RunAs("abc")

@PermitAll
public class MessageMDB implements MessageListener 
{

    @EJB
    BeanLocal beanLocal;

    @Override
    public void onMessage(Message inMessage) 
    {

        String messageString = beanLocal.returnAString( "yada" );

在我的SLSB中,我得到了...and:

代码语言:javascript
复制
@Stateless(name="aStatelessBean")
@SecurityDomain("my-security-domain")
@RolesAllowed("abc")
public class Bean implements BeanRemote, BeanLocal {

    @Resource
    protected SessionContext sessionContext;

    public Bean() 
    {
    }


    @Override
    public String returnAString(String parameter) 
    {

对我来说,这意味着MDB应该以用户"123“的身份调用SLSB。由于user 123在user.properties中是这样配置的:

代码语言:javascript
复制
123=qwe

roles.properties中的...and

代码语言:javascript
复制
123=abc,def

应该允许...he调用SLSB,但我得到的是:

调用者事务失败。语法: javax.ejb.EJBAccessException: JBAS014502:调用bean: aStatelessBean的公共抽象java.lang.String my.BeanLocal.returnAString(java.lang.String)是不允许的

只有当我将以下代码添加到MDB中时,它才有效:

代码语言:javascript
复制
@RunAs("abc")

但我当然希望它被"my-security-domain“中的配置拾取。

你们看到我错过什么了吗?

向Fredrik致以最好的问候

EN

回答 1

Stack Overflow用户

发布于 2018-05-16 12:54:35

要登录到MDB中的上下文并检查角色等,我需要在我的JBoss中这样做。我只是没能用其他方式做到这一点。

代码语言:javascript
复制
public static String ROLE = "abc";

@Resource  
MessageDrivenContext sessionContext;

private static SecurityClient getClientLogin() throws Exception
{
       final SecurityClient client = SecurityClientFactory.getSecurityClient();
        client.setSimple("123", "qwe");
        return client;
}

...

SecurityClient client = getClientLogin();
client.login();

...

System.out.println( sessionContext.getCallerPrincipal() );
System.out.println( sessionContext.isCallerInRole( ROLE ) );

我想就是这样了。如果您看到任何错误或改进,请通知我,我将尝试更正它/添加它。向Fredrik致以最好的问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48196029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档