Skip to content
Lance edited this page Jan 5, 2014 · 6 revisions

You can add security to your application by contributing one or mode TopicAuthorizers via Tapestry IOC. Each TopicAuthorizer can deny a subscription attempt by returning false from isAuthorized(AtmosphereResource resource, String topic).

eg:

/**
 * This authorizer only allows logged in users to subscribe
 */
public class ChatTopicAuthorizer implements TopicAuthorizer {
   @Override
   public boolean isAuthorized(AtmosphereResource resource, String topic) {
      HttpSession session = resource.getRequest().getSession(false);
      if (session != null) {
         String chatUser = (String) session.getAttribute("CHAT_USER");
         return chatUser != null;
      }
      return false;
   }
}
public class AppModule {
   public static void contributeTopicAuthorizer(OrderedConfiguration<TopicAuthorizer> config) {
      config.addInstance("chat", ChatTopicAuthorizer.class);
   }
}
Clone this wiki locally