rsanchez
2014-12-12 4c13c7324a920f5cca9601154e5224e5d7484fa9
securis/src/main/java/net/curisit/securis/services/UserResource.java
....@@ -76,6 +76,7 @@
7676 LOG.info("Getting users list ");
7777
7878 EntityManager em = emProvider.get();
79
+ em.clear();
7980 TypedQuery<User> q = em.createNamedQuery("list-users", User.class);
8081
8182 List<User> list = q.getResultList();
....@@ -102,6 +103,7 @@
102103 }
103104
104105 EntityManager em = emProvider.get();
106
+ em.clear();
105107 User lt = em.find(User.class, uid);
106108 if (lt == null) {
107109 LOG.error("User with id {} not found in DB", uid);
....@@ -136,7 +138,8 @@
136138 if (user.getPassword() != null && !"".equals(user.getPassword())) {
137139 user.setPassword(Utils.sha256(user.getPassword()));
138140 } else {
139
- return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
141
+ return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE)
142
+ .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
140143 }
141144 user.setModificationTimestamp(new Date());
142145 user.setLastLogin(null);
....@@ -197,7 +200,9 @@
197200 currentUser.setPassword(Utils.sha256(user.getPassword()));
198201 } else {
199202 // Password has not been modified
200
- //return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
203
+ // return
204
+ // Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
205
+ // "User password is mandatory").build();
201206 }
202207
203208 currentUser.setLastLogin(user.getLastLogin());
....@@ -238,7 +243,7 @@
238243 LOG.info("user: {}, pass: {}", username, password);
239244 LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
240245 LOG.info("is user in role: {} == {} ? ", "admin", request.isUserInRole("admin"));
241
-
246
+
242247 EntityManager em = emProvider.get();
243248 User user = em.find(User.class, username);
244249 if (user == null) {
....@@ -246,7 +251,7 @@
246251 return Response.status(Status.UNAUTHORIZED).build();
247252 }
248253 String securedPassword = Utils.sha256(password);
249
-
254
+
250255 if (securedPassword == null || !securedPassword.equals(user.getPassword())) {
251256 // TODO: Code to test exception handling
252257 return Response.status(Status.UNAUTHORIZED).build();
....@@ -256,7 +261,7 @@
256261 try {
257262 em.persist(user);
258263 em.getTransaction().commit();
259
- } catch(PersistenceException ex) {
264
+ } catch (PersistenceException ex) {
260265 LOG.error("Error updating last login date for user: {}", username);
261266 LOG.error(ex);
262267 em.getTransaction().rollback();