Changeset 348:d91f6bd7d381 for kraken-dom/src/main/java/org/krakenapps/dom/api/impl/AdminApiImpl.java
- Timestamp:
- 09/20/11 03:16:11 (8 months ago)
- Branch:
- default
- Convert:
- svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2782
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kraken-dom/src/main/java/org/krakenapps/dom/api/impl/AdminApiImpl.java
r340 r348 49 49 import org.krakenapps.dom.model.Organization; 50 50 import org.krakenapps.dom.model.Admin; 51 import org.krakenapps.dom.model.OrganizationParameter;52 51 import org.krakenapps.dom.model.Role; 53 52 import org.krakenapps.jpa.ThreadLocalEntityManagerService; … … 92 91 93 92 if (hash.equals(Sha1.hash(password + session.getString("nonce")))) { 94 OrganizationParameter param= orgParamApi.getOrganizationParameter(admin.getUser().getOrganization().getId(),93 String maxSession = orgParamApi.getOrganizationParameter(admin.getUser().getOrganization().getId(), 95 94 "max_sessions"); 96 if ( param!= null) {95 if (maxSession != null) { 97 96 try { 98 int maxSessions = Integer.parseInt( param.getValue());97 int maxSessions = Integer.parseInt(maxSession); 99 98 if (maxSessions > 0) { 100 99 if (force) { … … 116 115 for (LoginCallback callback : callbacks) 117 116 callback.onLoginSuccess(admin, session); 118 loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser().getLoginName())); 117 loggedIn.add(new LoggedInAdmin(admin.getRole().getLevel(), new Date(), session, admin.getUser() 118 .getLoginName())); 119 119 return admin; 120 120 } else { … … 269 269 270 270 @Override 271 public void createAdmin(int organizationId, Integer requestAdminId, Admin admin) { 272 createAdminInternal(organizationId, requestAdminId, admin); 273 fireEntityAdded(admin); 274 } 275 276 @Transactional 277 private void createAdminInternal(int organizationId, Integer requestAdminId, Admin admin) { 271 public Admin createAdmin(int organizationId, Integer requestAdminId, Admin admin) { 272 Admin a = createAdminInternal(organizationId, requestAdminId, admin); 273 fireEntityAdded(a); 274 return a; 275 } 276 277 @Transactional 278 private Admin createAdminInternal(int organizationId, Integer requestAdminId, Admin admin) { 278 279 EntityManager em = entityManagerService.getEntityManager(); 279 280 Organization organization = em.find(Organization.class, organizationId); … … 300 301 em.persist(host); 301 302 } 303 304 return admin; 302 305 } 303 306 … … 323 326 Admin admin = (Admin) em.createQuery("SELECT a FROM Admin a LEFT JOIN a.user u WHERE u.loginName = ?") 324 327 .setParameter(1, loginName).getSingleResult(); 325 328 326 329 admin.getRole().getPermissions().size(); 327 330 admin.getTrustHosts().size(); 328 331 329 332 return admin; 330 333 } … … 379 382 380 383 @Override 381 public void removeAdmin(int organizationId, Integer requestAdminId, int adminId) { 382 Admin admin = removeAdminInternal(organizationId, requestAdminId, adminId); 383 fireEntityRemoved(admin); 384 } 385 386 @Transactional 387 private Admin removeAdminInternal(int organizationId, Integer requestAdminId, int adminId) { 388 EntityManager em = entityManagerService.getEntityManager(); 389 390 Admin admin = (Admin) em.find(Admin.class, adminId); 391 if (admin.getUser().getOrganization().getId() != organizationId) 392 throw new AdminNotFoundException(adminId); 393 394 if (requestAdminId != null) { 395 Admin requestAdmin = em.find(Admin.class, requestAdminId); 396 if (requestAdmin == null) 397 throw new AdminNotFoundException(requestAdminId); 398 399 if (requestAdmin.getRole().getLevel() < admin.getRole().getLevel()) 400 throw new SecurityException("remove admin"); 401 402 if (requestAdminId == adminId) { 403 throw new CannotRemoveRequestingAdminException(requestAdminId); 404 } 405 } 406 407 em.remove(admin); 408 409 return admin; 410 } 411 412 @Override 413 public void updateAdmin(int organizationId, Integer requestAdminId, Admin targetAdmin) { 384 public Admin updateAdmin(int organizationId, Integer requestAdminId, Admin targetAdmin) { 414 385 Admin admin = updateAdminInternal(organizationId, requestAdminId, targetAdmin); 415 386 fireEntityUpdated(admin); 387 return admin; 416 388 } 417 389 … … 477 449 } 478 450 451 @Override 452 public Admin removeAdmin(int organizationId, Integer requestAdminId, int adminId) { 453 Admin admin = removeAdminInternal(organizationId, requestAdminId, adminId); 454 fireEntityRemoved(admin); 455 return admin; 456 } 457 458 @Transactional 459 private Admin removeAdminInternal(int organizationId, Integer requestAdminId, int adminId) { 460 EntityManager em = entityManagerService.getEntityManager(); 461 462 Admin admin = (Admin) em.find(Admin.class, adminId); 463 if (admin.getUser().getOrganization().getId() != organizationId) 464 throw new AdminNotFoundException(adminId); 465 466 if (requestAdminId != null) { 467 Admin requestAdmin = em.find(Admin.class, requestAdminId); 468 if (requestAdmin == null) 469 throw new AdminNotFoundException(requestAdminId); 470 471 if (requestAdmin.getRole().getLevel() < admin.getRole().getLevel()) 472 throw new SecurityException("remove admin"); 473 474 if (requestAdminId == adminId) { 475 throw new CannotRemoveRequestingAdminException(requestAdminId); 476 } 477 } 478 479 em.remove(admin); 480 481 return admin; 482 } 483 479 484 private static final char[] chars = new char[62]; 480 485 static {
Note: See TracChangeset
for help on using the changeset viewer.
