在我的standalone-full.xml中,我得到了这个安全域:
<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中:
@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:
@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中是这样配置的:
123=qweroles.properties中的...and
123=abc,def应该允许...he调用SLSB,但我得到的是:
调用者事务失败。语法: javax.ejb.EJBAccessException: JBAS014502:调用bean: aStatelessBean的公共抽象java.lang.String my.BeanLocal.returnAString(java.lang.String)是不允许的
只有当我将以下代码添加到MDB中时,它才有效:
@RunAs("abc")但我当然希望它被"my-security-domain“中的配置拾取。
你们看到我错过什么了吗?
向Fredrik致以最好的问候
发布于 2018-05-16 12:54:35
要登录到MDB中的上下文并检查角色等,我需要在我的JBoss中这样做。我只是没能用其他方式做到这一点。
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致以最好的问候
https://stackoverflow.com/questions/48196029
复制相似问题