@Test public void testGetCredentials() { try { Response<AccountEntry> response = authenticationController.getCredentials(SAID_LOCAL, SAID_REMOTE); Collection<AccountEntry> col = response.getMessage().getData().getEntries(); AccountEntry account = col.iterator().next(); String tmpPassword = account.getPassword(); response = authenticationController.getCredentials(SAID_LOCAL, SAID_REMOTE); col = response.getMessage().getData().getEntries(); account = col.iterator().next(); Assert.assertFalse(!account.getPassword().equals(tmpPassword)); } catch (DimeException ex) { Logger.getLogger(AuthenticationControllerTest.class.getName()).log(Level.SEVERE, null, ex); } }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") public Response<AccountEntry> getCredentials( @PathParam("said") String saidLocal, @PathParam("contact-said") String saidRequester) throws DimeException { Data<AccountEntry> data = new Data<AccountEntry>(); boolean unlocked; try { unlocked = lock.tryLock(50L, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new DimeException("Password retrieval failed", e); } if (!unlocked) { logger.error("Could not aquire lock within 5 seconds. Returning."); throw new DimeException("Could not request credentials because the system is busy."); } try { User user = userManager.getUserForAccountAndTenant(saidRequester, saidLocal); if (user == null) { return Response.badRequest("Useraccount was null", null); } if (user.getPassword() == null || user.getPassword().equals("")) { user = userManager.generatePassword((user.getId())); } if (user != null) { AccountEntry jsonEntry = new AccountEntry(); jsonEntry.setUsername(user.getUsername()); jsonEntry.setPassword(user.getPassword()); jsonEntry.setRole(user.getRole().ordinal()); jsonEntry.setEnabled(user.isEnabled()); jsonEntry.setType("auth"); data.addEntry(jsonEntry); } else { return Response.badRequest("Useraccount was already activated!", null); } return Response.ok(data); } catch (Exception e) { return Response.serverError(); } finally { lock.unlock(); } }
AuthenticationController { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") public Response<AccountEntry> getCredentials( @PathParam("said") String saidLocal, @PathParam("contact-said") String saidRequester) throws DimeException { Data<AccountEntry> data = new Data<AccountEntry>(); boolean unlocked; try { unlocked = lock.tryLock(50L, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new DimeException("Password retrieval failed", e); } if (!unlocked) { logger.error("Could not aquire lock within 5 seconds. Returning."); throw new DimeException("Could not request credentials because the system is busy."); } try { User user = userManager.getUserForAccountAndTenant(saidRequester, saidLocal); if (user == null) { return Response.badRequest("Useraccount was null", null); } if (user.getPassword() == null || user.getPassword().equals("")) { user = userManager.generatePassword((user.getId())); } if (user != null) { AccountEntry jsonEntry = new AccountEntry(); jsonEntry.setUsername(user.getUsername()); jsonEntry.setPassword(user.getPassword()); jsonEntry.setRole(user.getRole().ordinal()); jsonEntry.setEnabled(user.isEnabled()); jsonEntry.setType("auth"); data.addEntry(jsonEntry); } else { return Response.badRequest("Useraccount was already activated!", null); } return Response.ok(data); } catch (Exception e) { return Response.serverError(); } finally { lock.unlock(); } } }
AuthenticationController { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") public Response<AccountEntry> getCredentials( @PathParam("said") String saidLocal, @PathParam("contact-said") String saidRequester) throws DimeException { Data<AccountEntry> data = new Data<AccountEntry>(); boolean unlocked; try { unlocked = lock.tryLock(50L, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new DimeException("Password retrieval failed", e); } if (!unlocked) { logger.error("Could not aquire lock within 5 seconds. Returning."); throw new DimeException("Could not request credentials because the system is busy."); } try { User user = userManager.getUserForAccountAndTenant(saidRequester, saidLocal); if (user == null) { return Response.badRequest("Useraccount was null", null); } if (user.getPassword() == null || user.getPassword().equals("")) { user = userManager.generatePassword((user.getId())); } if (user != null) { AccountEntry jsonEntry = new AccountEntry(); jsonEntry.setUsername(user.getUsername()); jsonEntry.setPassword(user.getPassword()); jsonEntry.setRole(user.getRole().ordinal()); jsonEntry.setEnabled(user.isEnabled()); jsonEntry.setType("auth"); data.addEntry(jsonEntry); } else { return Response.badRequest("Useraccount was already activated!", null); } return Response.ok(data); } catch (Exception e) { return Response.serverError(); } finally { lock.unlock(); } }  }
AuthenticationController { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") public Response<AccountEntry> getCredentials( @PathParam("said") String saidLocal, @PathParam("contact-said") String saidRequester) throws DimeException { Data<AccountEntry> data = new Data<AccountEntry>(); boolean unlocked; try { unlocked = lock.tryLock(50L, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new DimeException("Password retrieval failed", e); } if (!unlocked) { logger.error("Could not aquire lock within 5 seconds. Returning."); throw new DimeException("Could not request credentials because the system is busy."); } try { User user = userManager.getUserForAccountAndTenant(saidRequester, saidLocal); if (user == null) { return Response.badRequest("Useraccount was null", null); } if (user.getPassword() == null || user.getPassword().equals("")) { user = userManager.generatePassword((user.getId())); } if (user != null) { AccountEntry jsonEntry = new AccountEntry(); jsonEntry.setUsername(user.getUsername()); jsonEntry.setPassword(user.getPassword()); jsonEntry.setRole(user.getRole().ordinal()); jsonEntry.setEnabled(user.isEnabled()); jsonEntry.setType("auth"); data.addEntry(jsonEntry); } else { return Response.badRequest("Useraccount was already activated!", null); } return Response.ok(data); } catch (Exception e) { return Response.serverError(); } finally { lock.unlock(); } }  void setUserManager(UserManager userManager); void setAccessControlManager(AccessControlManager accessControlManager); @GET @Path("{userName}") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> getUser(
               @PathParam("userName") String userName); @POST @Path("{userName}")// can be @me - then updating the current user @Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> updateUser(
               @PathParam("said") String said,
               @PathParam("userName") String userName,
               Request<AccountEntry> request); @DELETE @Path("{userName}") @Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> deleteAccount(Request<AccountEntry> request,
            @PathParam("userName") String userName); @GET @Path("/username") String getCurrentUserName(); @GET @Path("/role") String getCurrentRole(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") Response<AccountEntry> getCredentials(
            @PathParam("said") String saidLocal,
            @PathParam("contact-said") String saidRequester); @POST @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") Response<?> confirmCredentials(
            @PathParam("said") String saidLocal,
            @PathParam("contact-said") String saidRequester); }
AuthenticationController { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") public Response<AccountEntry> getCredentials( @PathParam("said") String saidLocal, @PathParam("contact-said") String saidRequester) throws DimeException { Data<AccountEntry> data = new Data<AccountEntry>(); boolean unlocked; try { unlocked = lock.tryLock(50L, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new DimeException("Password retrieval failed", e); } if (!unlocked) { logger.error("Could not aquire lock within 5 seconds. Returning."); throw new DimeException("Could not request credentials because the system is busy."); } try { User user = userManager.getUserForAccountAndTenant(saidRequester, saidLocal); if (user == null) { return Response.badRequest("Useraccount was null", null); } if (user.getPassword() == null || user.getPassword().equals("")) { user = userManager.generatePassword((user.getId())); } if (user != null) { AccountEntry jsonEntry = new AccountEntry(); jsonEntry.setUsername(user.getUsername()); jsonEntry.setPassword(user.getPassword()); jsonEntry.setRole(user.getRole().ordinal()); jsonEntry.setEnabled(user.isEnabled()); jsonEntry.setType("auth"); data.addEntry(jsonEntry); } else { return Response.badRequest("Useraccount was already activated!", null); } return Response.ok(data); } catch (Exception e) { return Response.serverError(); } finally { lock.unlock(); } }  void setUserManager(UserManager userManager); void setAccessControlManager(AccessControlManager accessControlManager); @GET @Path("{userName}") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> getUser(
               @PathParam("userName") String userName); @POST @Path("{userName}")// can be @me - then updating the current user @Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> updateUser(
               @PathParam("said") String said,
               @PathParam("userName") String userName,
               Request<AccountEntry> request); @DELETE @Path("{userName}") @Consumes(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") Response<AccountEntry> deleteAccount(Request<AccountEntry> request,
            @PathParam("userName") String userName); @GET @Path("/username") String getCurrentUserName(); @GET @Path("/role") String getCurrentRole(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") Response<AccountEntry> getCredentials(
            @PathParam("said") String saidLocal,
            @PathParam("contact-said") String saidRequester); @POST @Produces(MediaType.APPLICATION_JSON) @Path("/credentials/{contact-said}") Response<?> confirmCredentials(
            @PathParam("said") String saidLocal,
            @PathParam("contact-said") String saidRequester);  }