Git Product home page Git Product logo

jboss-security-extended's Introduction

JBoss Security Extended

Propagate Security Context through JMS and WebSocket endpoint in JBoss/WildFly container.

  • Maven
<dependency>
    <groupId>com.github.panga</groupId>
    <artifactId>jboss-security-extended</artifactId>
    <version>1.0.0</version>
</dependency>
  • Usage for JMS
@Stateless
public class QueueSender {

    @Inject
    private JMSContext jmsContext;

    @Resource(mappedName = "java:/jms/Queue")
    private Queue destination;

    @Resource
    private EJBContext context;

    public void sendToQueue(final MyObject myObject) {
        final SecureObjectMessage message = new SecureObjectMessage(myObject, context.getCallerPrincipal());
        jmsContext.createProducer().send(destination, message);
    }
}
@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode",
            propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType",
            propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destinationLookup",
            propertyValue = "java:/jms/Queue")
})
@Interceptors(JmsSecurityInterceptor.class)
public class QueueConsumer implements MessageListener {

    @EJB
    private SecuredEJB securedEJB;

    @Override
    public void onMessage(Message message) {
        try {
            securedEJB.process(message.getBody(MyObject.class));
        } catch (JMSException ex) {
            ex.printStackTrace();
        }
    }

}
  • Usage for WebSocket (must have a Session parameter)
@Interceptors({WebsocketSecurityInterceptor.class})
@ServerEndpoint(value = "/echo", configurator = WebsocketSecurityConfigurator.class)
public class EchoEndpoint {

    @Inject
    private SecuredEJB securedEJB;

    @OnOpen
    public void open(Session session) {
        securedEJB.process(null);
    }

    @OnMessage
    public void message(String message, Session session) {
        securedEJB.process(null);
    }

    @OnClose
    public void close(Session session) {
        securedEJB.process(null);
    }

}
  • Secured EJB
@Stateless
@RolesAllowed("admin")
public class SecuredEJB {

    @Resource
    private EJBContext context;

    public void process(MyObject myObject) {
        System.out.println("User: " + context.getCallerPrincipal().getName());
    }
}

jboss-security-extended's People

Contributors

panga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jboss-security-extended's Issues

What to do when the existing SecurityContext is null in the JMS MDB

Hi,

We are using jboss 6.4.7 and a standard MessageListener with the following configuration using your JmsSecurityInterceptor:

@MessageDriven(name = "ExportMDB", activationConfig =
{ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/ExportRequestQ") })
@singleton
@startup
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@interceptors(JmsSecurityInterceptor.class)

While executing onMessage on the JMS MDB the SecurityActions class/setSubjectInfo method is called and the following line returns securityContext null and later we get NullPointerException error when the securityContext is referenced:

final SecurityContext securityContext = SecurityContextAssociation.getSecurityContext();

Can you recommend a solution to this issue?

Does it make sense to create a SecurityContext if non exists for the MDB? This the solution we are using and I can create a patch with that change and add it to the project if you agree to this solution.

Thanks.

Webscoket still working after logout

Hi. Big thanks for this WA.
I use it? but found some problem after logout. If i call

org.jboss.security.SecurityContextAssociation#clearSecurityContext

for thread with original Subject, webscoket still provide Principal and Roles about user that was already logout. In case with backgroud repetable tasks it not so good. I can't find any WA for it. May be have any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.