rsanchez
2015-01-28 da889d489da5d7fa8c71d9f21f24b1dc2e29d8e1
securis/src/main/java/net/curisit/securis/security/SecurityInterceptor.java
....@@ -31,27 +31,27 @@
3131 import org.jboss.resteasy.spi.ResteasyProviderFactory;
3232
3333 @Provider
34
-// @PreMatching
3534 @Priority(Priorities.AUTHENTICATION)
3635 public class SecurityInterceptor implements javax.ws.rs.container.ContainerRequestFilter {
3736 private static final Logger LOG = LogManager.getLogger(SecurityInterceptor.class);
38
-
39
- @Inject
40
- private TokenHelper tokenHelper;
4137
4238 @Context
4339 private HttpServletRequest servletRequest;
4440
4541 @Inject
46
- CacheTTL cache;
47
-
48
- @Context
49
- Dispatcher dispatcher;
42
+ private CacheTTL cache;
5043
5144 @Inject
52
- com.google.inject.Provider<EntityManager> emProvider;
45
+ private TokenHelper tokenHelper;
46
+
47
+ @Context
48
+ private Dispatcher dispatcher;
49
+
50
+ @Inject
51
+ private EntityManager em;
5352
5453 public void filter(ContainerRequestContext containerRequestContext) throws IOException {
54
+
5555 ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) containerRequestContext
5656 .getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
5757 Method method = methodInvoker.getMethod();
....@@ -76,6 +76,7 @@
7676 containerRequestContext.setSecurityContext(scw);
7777 // Next line provide injection in resource methods
7878 ResteasyProviderFactory.pushContext(BasicSecurityContext.class, scw);
79
+ ResteasyProviderFactory.pushContext(EntityManager.class, em);
7980 LOG.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs);
8081 }
8182 }
....@@ -85,7 +86,6 @@
8586 Set<Integer> userOrgs = cache.get("orgs_" + username, Set.class);
8687 if (userOrgs == null) {
8788 // Theorically this shouldn't be never null, but just in case...
88
- EntityManager em = emProvider.get();
8989 User user = em.find(User.class, username);
9090 if (user != null) {
9191 userOrgs = user.getAllOrgsIds();
....@@ -103,7 +103,6 @@
103103 }
104104 Integer userRoles = cache.get("roles_" + username, Integer.class);
105105 if (userRoles == null) {
106
- EntityManager em = emProvider.get();
107106 User user = em.find(User.class, username);
108107 if (user != null) {
109108 userRoles = 0;