Weblogic 消息驱动 Bean 从安全队列 @RunAs 读取不起作用

发布于 2024-10-16 06:03:42 字数 1052 浏览 8 评论 0原文

我有一个非常简单的 MDB,只要它读取消息的队列不安全,它就可以正常工作

。在我使用用户名保护队列后,它就不能再读取消息了,

@MessageDriven(mappedName = "DistributedQueueTest")

public class MdbReceiver implements MessageListener {
@Resource
private MessageDrivenContext mdc;

@Override
public void onMessage(Message inMessage) {
TextMessage msg = null;
try {
msg = (TextMessage) inMessage;
System.out.println("Test MdbReceiver Message received : " + msg.getText());
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
}
}

}

我尝试了所有类型的 @RunAs 注释 @weblogic.jws.security.RunAs(role="Joan",mapToPrincipal="ccc_user") 其中允许 ccc_user 从队列中读取消息

import javax.annotation.security.RunAs; @RunAs("SomeRole") 给我一个部署错误 无法部署 EJB:来自 mdbReceiver.jar 的 MdbReceiver:映射中的预期角色

知道如何使用注释来做到这一点吗?即使没有注释我也尝试过 ...weblogic控制台中的异常是

weblogic.jms.common.JMSSecurityException:拒绝访问资源:type=,application=UNIV_REC_Module,destinationType=queue,resource=DistributedQueueTest,action=receive

谢谢

I have a MDB very simple which works fine as long as the queue from where it reads messages is not secured

After I secure the Queue with a username it can;t read messages anymore

@MessageDriven(mappedName = "DistributedQueueTest")

public class MdbReceiver implements MessageListener {
@Resource
private MessageDrivenContext mdc;

@Override
public void onMessage(Message inMessage) {
TextMessage msg = null;
try {
msg = (TextMessage) inMessage;
System.out.println("Test MdbReceiver Message received : " + msg.getText());
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
}
}

}

I tried with all kind of @RunAs annotations
@weblogic.jws.security.RunAs(role="Joan",mapToPrincipal="ccc_user") where ccc_user is alowed to read messages from the queue

import javax.annotation.security.RunAs;
@RunAs("SomeRole") gives me an error on deployment
Unable to deploy EJB: MdbReceiver from mdbReceiver.jar: Expected role in mapping

Any idea how can i do this with annotations ? I tried even without annotations
...same the exeption in weblogic console is

weblogic.jms.common.JMSSecurityException: Access denied to resource: type=<jms>, application=UNIV_REC_Module, destinationType=queue, resource=DistributedQueueTest, action=receive

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤云独去闲 2024-10-23 06:03:42

我回答我的问题是因为我找到了解决方案:
问题是注释或在 weblogic 中存在错误,或者没有按照我的预期实现。

解决方案是在不使用旧样式注释的情况下执行此操作,

因此 MDB 是:

public class MdbReceiver implements MessageListener ,MessageDrivenBean{

    MessageDrivenContext mdc;

    @Override
    public void onMessage(Message inMessage) {
        TextMessage msg = null;
        try {
            msg = (TextMessage) inMessage;
            System.out.println("qwerty1");
            System.out.println("Test MdbReceiver Message received : " + msg.getText());
        } catch (JMSException e) {
            e.printStackTrace();
            mdc.setRollbackOnly();
        }
    }
    @Override
    public void ejbRemove() throws EJBException {
        // TODO Auto-generated method stub

    }
    @Override
    public void setMessageDrivenContext(MessageDrivenContext mdc) throws EJBException {
        this.mdc = mdc;

    }
}

然后我们需要另外两个文件:
ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
        <message-driven>
            <ejb-name>MdbReceiver</ejb-name>
            <ejb-class>mdb.receiver.MdbReceiver</ejb-class>
            <transaction-type>Container</transaction-type>
            <message-destination-type>javax.jms.Queue</message-destination-type>
            <security-identity>
                <run-as>
                    <role-name>Loan</role-name>
                </run-as>
            </security-identity>
        </message-driven>
    </enterprise-beans>
    <assembly-descriptor>       
         <security-role>
          <role-name>Loan</role-name>
         </security-role>       
        <container-transaction>
            <method>
                <ejb-name>MdbReceiver</ejb-name>
                <method-name>onMessage()</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    </assembly-descriptor>

</ejb-jar>

weblogic-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar version="wls_10.3"
    xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar" xmlns:j2ee="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <weblogic-enterprise-bean>
        <ejb-name>MdbReceiver</ejb-name>
        <message-driven-descriptor>
            <destination-jndi-name>DistributedQueueTest</destination-jndi-name>
        </message-driven-descriptor>
    </weblogic-enterprise-bean>
    <security-role-assignment>
        <role-name>Loan</role-name>     
        <principal-name>test1234</principal-name>
    </security-role-assignment>

</weblogic-ejb-jar>

角色名称并不重要,因为我可以看到主体名称很重要。
它需要有权从安全队列中读取

I answer to my question cause i found a solution :
The problem is that annotations or are buggy in weblogic or are not implemented as I expected.

Solution is to do this without annotations in old style

so MDB is:

public class MdbReceiver implements MessageListener ,MessageDrivenBean{

    MessageDrivenContext mdc;

    @Override
    public void onMessage(Message inMessage) {
        TextMessage msg = null;
        try {
            msg = (TextMessage) inMessage;
            System.out.println("qwerty1");
            System.out.println("Test MdbReceiver Message received : " + msg.getText());
        } catch (JMSException e) {
            e.printStackTrace();
            mdc.setRollbackOnly();
        }
    }
    @Override
    public void ejbRemove() throws EJBException {
        // TODO Auto-generated method stub

    }
    @Override
    public void setMessageDrivenContext(MessageDrivenContext mdc) throws EJBException {
        this.mdc = mdc;

    }
}

Then we need two other files:
ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
        <message-driven>
            <ejb-name>MdbReceiver</ejb-name>
            <ejb-class>mdb.receiver.MdbReceiver</ejb-class>
            <transaction-type>Container</transaction-type>
            <message-destination-type>javax.jms.Queue</message-destination-type>
            <security-identity>
                <run-as>
                    <role-name>Loan</role-name>
                </run-as>
            </security-identity>
        </message-driven>
    </enterprise-beans>
    <assembly-descriptor>       
         <security-role>
          <role-name>Loan</role-name>
         </security-role>       
        <container-transaction>
            <method>
                <ejb-name>MdbReceiver</ejb-name>
                <method-name>onMessage()</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    </assembly-descriptor>

</ejb-jar>

and

weblogic-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar version="wls_10.3"
    xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar" xmlns:j2ee="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <weblogic-enterprise-bean>
        <ejb-name>MdbReceiver</ejb-name>
        <message-driven-descriptor>
            <destination-jndi-name>DistributedQueueTest</destination-jndi-name>
        </message-driven-descriptor>
    </weblogic-enterprise-bean>
    <security-role-assignment>
        <role-name>Loan</role-name>     
        <principal-name>test1234</principal-name>
    </security-role-assignment>

</weblogic-ejb-jar>

The role name does not matter as i can see the principal name is important.
It needs to have the rights to read from the secured queue

飘然心甜 2024-10-23 06:03:42

如果您按如下方式注释 MDB,它应该可以工作:

@MessageDriven(name = "MdbReceiver", mappedName = "DistributedQueueTest")
@DeclareRoles({"Loan"})
@RolesAllowed("Loan")
public class MdbReceiver implements MessageListener {
...
}

If you annotate your MDB as follows it should work:

@MessageDriven(name = "MdbReceiver", mappedName = "DistributedQueueTest")
@DeclareRoles({"Loan"})
@RolesAllowed("Loan")
public class MdbReceiver implements MessageListener {
...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文