1 6 7 package com.nightlabs.ipanema.security; 8 import java.rmi.RemoteException ; 9 import java.util.Collection ; 10 import java.util.HashSet ; 11 import java.util.Iterator ; 12 13 import javax.ejb.CreateException ; 14 import javax.ejb.EJBException ; 15 import javax.ejb.SessionBean ; 16 import javax.ejb.SessionContext ; 17 import javax.jdo.Extent; 18 import javax.jdo.FetchPlan; 19 import javax.jdo.JDODetachedFieldAccessException; 20 import javax.jdo.JDOHelper; 21 import javax.jdo.JDOObjectNotFoundException; 22 import javax.jdo.PersistenceManager; 23 import javax.jdo.Query; 24 25 import org.apache.log4j.Logger; 26 27 import com.nightlabs.ModuleException; 28 import com.nightlabs.ipanema.base.BaseSessionBeanImpl; 29 import com.nightlabs.ipanema.person.Person; 30 import com.nightlabs.ipanema.person.id.PersonID; 31 import com.nightlabs.ipanema.security.id.AuthorityID; 32 import com.nightlabs.ipanema.security.id.RoleGroupID; 33 import com.nightlabs.ipanema.security.id.UserID; 34 import com.nightlabs.ipanema.security.id.UserRefID; 35 import com.nightlabs.jdo.NLJDOHelper; 36 import com.nightlabs.jdo.ObjectIDException; 37 38 43 44 51 public abstract class UserManagerBean 52 extends BaseSessionBeanImpl 53 implements SessionBean 54 { 55 public static final Logger LOGGER = Logger.getLogger(UserManagerBean.class); 56 57 60 public void setSessionContext(SessionContext sessionContext) 61 throws EJBException , RemoteException 62 { 63 super.setSessionContext(sessionContext); 64 } 65 68 public void unsetSessionContext() { 69 super.unsetSessionContext(); 70 } 71 72 77 public void ejbCreate() throws CreateException 78 { 79 } 80 81 86 public void ejbRemove() throws EJBException , RemoteException { } 87 88 99 public User saveDetachedUser(User user, String [] fetchGroups) 100 throws ModuleException 101 { 102 PersistenceManager pm = this.getPersistenceManager(); 103 try 104 { 105 User result = (User)NLJDOHelper.storeJDO(pm, user, true, fetchGroups); 106 return result; 107 } 108 finally 109 { 110 pm.close(); 111 } 112 } 113 114 121 public void saveUser(User user) 122 throws SecurityException 123 { 124 try 125 { 126 if (user.getOrganisationID() != null && !user.getOrganisationID().equals(getOrganisationID())) 127 throw new IllegalArgumentException ("user.organisationID must be null or equal to your organisationID!!!"); 128 129 if (user.getOrganisationID() == null) 130 user.setOrganisationID(getOrganisationID()); 131 132 PersistenceManager pm = this.getPersistenceManager(); 133 if (JDOHelper.isDetached(user)) 134 { 135 if(user.passwdChanged) 136 { 137 String password = user.getPassword(); 138 if(user instanceof UserGroup) 139 throw new IllegalArgumentException ("You cannot set a password for a UserGroup! userGroup.password must be null!"); 140 if(user.passwdChanged) 141 user.setPassword(User.encryptPassword(user.getPassword())); 142 } 143 pm.attachCopy(user, false); 144 } 145 else 146 { 147 user.setPassword(User.encryptPassword(user.getPassword())); 148 pm.makePersistent(user); 149 } 150 pm.close(); 151 } 152 catch (ModuleException e) 153 { 154 throw new SecurityException (e); 155 } 156 } 157 158 165 public UserSearchResult searchUsers ( 166 String userType, 167 String searchStr, boolean exact, int itemsPerPage, int pageIndex, int userIncludeMask) 168 throws SecurityException 169 { 170 try { 171 PersistenceManager pm = getPersistenceManager(); 172 try { 173 UserSearchResult result = User.searchUsers( 174 pm, userType, searchStr, exact, itemsPerPage, pageIndex, userIncludeMask); 175 176 result.makeTransient(userIncludeMask); 177 return result; 178 } finally { 179 if (AuthorityManagerBean.CLOSE_PM) pm.close(); 180 } 181 } catch (Exception x) { 182 throw new SecurityException (x); 183 } 184 } 185 186 196 public Collection getUsersByType(String userType) 197 throws ModuleException 198 { 199 return getUsersByType(userType,null); 200 } 201 202 210 public Collection getUsersByType(String userType, String [] fetchGroups) 211 throws ModuleException 212 { 213 PersistenceManager pm = getPersistenceManager(); 214 try 215 { 216 if (fetchGroups != null) 217 pm.getFetchPlan().setGroups(fetchGroups); 218 else 219 pm.getFetchPlan().clearGroups(); 220 221 Query query = pm.newQuery(pm.getExtent(User.class, true)); 222 query.declareImports("import java.lang.String"); 223 query.declareParameters("String userType, String systemUserID, String otherUserID"); 224 query.setFilter("this.userType == userType && this.userID != systemUserID && this.userID != otherUserID"); 225 query.setOrdering("this.userID ascending"); 226 Collection c = (Collection )query.execute(userType, User.SYSTEM_USERID, User.OTHER_USERID); 227 return pm.detachCopyAll(c); 228 } 229 finally 230 { 231 pm.close(); 232 } 233 } 234 235 241 public Collection getAllUsers() 242 throws ModuleException 243 { 244 return getAllUsers(null); 245 } 246 247 253 public Collection getAllUsers(String [] fetchGroups) 254 throws ModuleException 255 { 256 PersistenceManager pm = getPersistenceManager(); 257 try 258 { 259 if (fetchGroups != null) 260 pm.getFetchPlan().setGroups(fetchGroups); 261 else 262 pm.getFetchPlan().clearGroups(); 263 264 Query query = pm.newQuery(pm.getExtent(User.class, true)); 265 query.declareImports("import java.lang.String"); 266 query.declareParameters("String systemUserID"); 267 query.setFilter("this.userID != systemUserID"); 268 query.setOrdering("this.userID ascending"); 269 Collection c = (Collection )query.execute(User.SYSTEM_USERID); 270 return pm.detachCopyAll(c); 271 } 272 finally 273 { 274 pm.close(); 275 } 276 } 277 278 284 public Collection getUsersInUserGroup(String userGroupID) 285 throws ModuleException 286 { 287 return getUsersInUserGroup(userGroupID, null); 288 } 289 290 296 public Collection getUsersInUserGroup(String userGroupID, String [] fetchGroups) 297 throws ModuleException 298 { 299 PersistenceManager pm = getPersistenceManager(); 300 try 301 { 302 if (fetchGroups != null) 303 pm.getFetchPlan().setGroups(fetchGroups); 304 else 305 pm.getFetchPlan().clearGroups(); 306 307 UserGroup ug = (UserGroup)pm.getObjectById(UserID.create(getOrganisationID(), userGroupID)); 308 return (Collection )pm.detachCopyAll(ug.getUsers()); 309 } 310 finally 311 { 312 pm.close(); 313 } 314 } 315 316 322 public Collection getUsersNotInUserGroup(String userGroupID) 323 throws ModuleException 324 { 325 return getUsersNotInUserGroup(userGroupID, null); 326 } 327 328 334 public Collection getUsersNotInUserGroup(String userGroupID, String [] fetchGroups) 335 throws ModuleException 336 { 337 PersistenceManager pm = getPersistenceManager(); 338 try 339 { 340 if (fetchGroups != null) 341 pm.getFetchPlan().setGroups(fetchGroups); 342 else 343 pm.getFetchPlan().clearGroups(); 344 345 Extent ext = pm.getExtent(User.class, true); 346 347 363 UserGroup ug = (UserGroup)pm.getObjectById(UserID.create(getOrganisationID(), userGroupID)); 365 366 Query query = pm.newQuery("SELECT FROM com.nightlabs.ipanema.security.User " + 367 "WHERE " + 368 " (userType == \"" + User.USERTYPE_USER + "\" ||" + 369 " userType == \"" + User.USERTYPE_ORGANISATION + "\") && " + 370 " this.userID != \"" + User.SYSTEM_USERID + "\" && " + 371 " this.userID != \"" + User.OTHER_USERID + "\""); 372 Collection c = (Collection )query.execute(); 373 374 Iterator i = c.iterator(); 375 Collection c2 = new HashSet (); 376 while(i.hasNext()) 377 { 378 Object o = i.next(); 379 if(!ug.getUsers().contains(o)) 380 c2.add(o); 381 } 382 return pm.detachCopyAll(c2); 383 385 } 386 finally 387 { 388 pm.close(); 389 } 390 } 391 392 398 public RoleGroupListCarrier getRoleGroups(String userID, String authorityID) 399 throws ModuleException 400 { 401 return getRoleGroups(userID, authorityID, null); 402 } 403 404 410 public RoleGroupListCarrier getRoleGroups(String userID, String authorityID, String [] fetchGroups) 411 throws ModuleException 412 { 413 PersistenceManager pm = getPersistenceManager(); 414 try 415 { 416 if (fetchGroups != null) 417 pm.getFetchPlan().setGroups(fetchGroups); 418 else 419 pm.getFetchPlan().clearGroups(); 420 421 Extent ext = pm.getExtent(RoleGroup.class, false); 422 423 Query query = pm.newQuery( 425 "SELECT FROM com.nightlabs.ipanema.security.RoleGroup " + 426 "WHERE " + 427 " this == roleGroupRef.roleGroup &&" + 428 " roleGroupRef.userRefs.containsValue(userRef) &&" + 429 " userRef.authorityID == paramAuthorityID &&" + 430 " userRef.user == user &&" + 431 " user.organisationID == paramOrganisationID &&" + 432 " user.userID == paramUserID " + 433 "VARIABLES RoleGroupRef roleGroupRef; UserRef userRef; User user " + 434 "PARAMETERS String paramOrganisationID, String paramUserID, String paramAuthorityID " + 435 "IMPORTS import com.nightlabs.ipanema.security.RoleGroupRef; import com.nightlabs.ipanema.security.UserRef; import com.nightlabs.ipanema.security.User; import java.lang.String"); 436 Collection roleGroupsUser = (Collection )query.execute(getOrganisationID(), userID, authorityID); 437 438 query = pm.newQuery( 440 "SELECT FROM com.nightlabs.ipanema.security.RoleGroup " + 441 "WHERE " + 442 " this == roleGroupRef.roleGroup &&" + 443 " roleGroupRef.userRefs.containsValue(userGroupRef) &&" + 444 " userGroupRef.user == userGroup &&" + 445 " userGroupRef.authorityID == paramAuthorityID &&" + 446 " userGroup.users.containsValue(user) &&" + 447 " user.organisationID == paramOrganisationID &&" + 448 " user.userID == paramUserID " + 449 "VARIABLES RoleGroupRef roleGroupRef; UserGroupRef userGroupRef; UserGroup userGroup; User user " + 450 "PARAMETERS String paramOrganisationID, String paramUserID, String paramAuthorityID " + 451 "IMPORTS import com.nightlabs.ipanema.security.RoleGroupRef; import com.nightlabs.ipanema.security.UserRef; import java.lang.String"); 452 Collection roleGroupsUserGroups = (Collection )query.execute(getOrganisationID(), userID, authorityID); 453 454 RoleGroupListCarrier rglc = new RoleGroupListCarrier(); 455 rglc.assignedToUser = pm.detachCopyAll(roleGroupsUser); 456 rglc.assignedToUserGroups = pm.detachCopyAll(roleGroupsUserGroups); 457 458 return rglc; 459 } 460 finally 461 { 462 pm.close(); 463 } 464 } 465 466 473 public Collection getExcludedRoleGroups(String userID, String authorityID) 474 throws ModuleException 475 { 476 return getExcludedRoleGroups(userID, authorityID, null); 477 } 478 484 public Collection getExcludedRoleGroups(String userID, String authorityID, String [] fetchGroups) 485 throws ModuleException 486 { 487 PersistenceManager pm = getPersistenceManager(); 488 try 489 { 490 if (fetchGroups != null) 491 pm.getFetchPlan().setGroups(fetchGroups); 492 else 493 pm.getFetchPlan().clearGroups(); 494 495 Extent ext = pm.getExtent(RoleGroup.class, false); 496 497 512 528 Query query = pm.newQuery("SELECT FROM com.nightlabs.ipanema.security.RoleGroup"); 530 Collection c = (Collection )query.execute(); 531 query = pm.newQuery( 532 "SELECT FROM com.nightlabs.ipanema.security.RoleGroup " + 533 "WHERE " + 534 " this == roleGroupRef.roleGroup &&" + 535 " roleGroupRef.userRefs.containsValue(userRef) &&" + 536 " userRef.authorityID == paramAuthorityID &&" + 537 " userRef.user == user &&" + 538 " user.organisationID == paramOrganisationID &&" + 539 " user.userID == paramUserID " + 540 "VARIABLES RoleGroupRef roleGroupRef; UserRef userRef; User user " + 541 "PARAMETERS String paramOrganisationID, String paramUserID, String paramAuthorityID " + 542 "IMPORTS import com.nightlabs.ipanema.security.RoleGroupRef; import com.nightlabs.ipanema.security.UserRef; import com.nightlabs.ipanema.security.User; import java.lang.String"); 543 Collection roleGroupsUser = (Collection )query.execute(getOrganisationID(), userID, authorityID); 544 query = pm.newQuery( 545 "SELECT FROM com.nightlabs.ipanema.security.RoleGroup " + 546 "WHERE " + 547 " this == roleGroupRef.roleGroup &&" + 548 " roleGroupRef.userRefs.containsValue(userGroupRef) &&" + 549 " userGroupRef.user == userGroup &&" + 550 " userGroupRef.authorityID == paramAuthorityID &&" + 551 " userGroup.users.containsValue(user) &&" + 552 " user.organisationID == paramOrganisationID &&" + 553 " user.userID == paramUserID " + 554 "VARIABLES RoleGroupRef roleGroupRef; UserGroupRef userGroupRef; UserGroup userGroup; User user " + 555 "PARAMETERS String paramOrganisationID, String paramUserID, String paramAuthorityID " + 556 "IMPORTS import com.nightlabs.ipanema.security.RoleGroupRef; import com.nightlabs.ipanema.security.UserRef; import java.lang.String"); 557 Collection roleGroupsUserGroups = (Collection )query.execute(getOrganisationID(), userID, authorityID); 558 559 Iterator i = c.iterator(); 560 Collection c2 = new HashSet (); 561 while(i.hasNext()) 562 { 563 Object o = i.next(); 564 if((!roleGroupsUser.contains(o)) && (!roleGroupsUserGroups.contains(o))) 565 c2.add(o); 566 } 567 return pm.detachCopyAll(c2); 568 570 } 571 finally 572 { 573 pm.close(); 574 } 575 } 576 577 583 public Collection getUserGroups(String userID) 584 throws ModuleException 585 { 586 return getUserGroups(userID, null); 587 } 588 589 595 public Collection getUserGroups(String userID, String [] fetchGroups) 596 throws ModuleException 597 { 598 PersistenceManager pm = getPersistenceManager(); 599 try 600 { 601 if (fetchGroups != null) 602 pm.getFetchPlan().setGroups(fetchGroups); 603 else 604 pm.getFetchPlan().clearGroups(); 605 606 Extent ext = pm.getExtent(UserGroup.class, false); 607 Query query = pm.newQuery( 608 "SELECT FROM com.nightlabs.ipanema.security.UserGroup " + 609 "WHERE " + 610 " users.containsKey(paramUserID) " + 611 "PARAMETERS String paramUserID " + 612 "IMPORTS import java.lang.String"); 613 614 Collection c = (Collection )query.execute(userID); 615 return pm.detachCopyAll(c); 616 } 617 finally 618 { 619 pm.close(); 620 } 621 } 622 623 624 630 public Collection getExcludedUserGroups(String userID) 631 throws ModuleException 632 { 633 return getExcludedUserGroups(userID, null); 634 } 635 636 642 public Collection getExcludedUserGroups(String userID, String [] fetchGroups) 643 throws ModuleException 644 { 645 PersistenceManager pm = getPersistenceManager(); 646 try 647 { 648 if (fetchGroups != null) 649 pm.getFetchPlan().setGroups(fetchGroups); 650 else 651 pm.getFetchPlan().clearGroups(); 652 653 Extent ext = pm.getExtent(UserGroup.class, false); 654 664 665 Query query = pm.newQuery("SELECT FROM com.nightlabs.ipanema.security.UserGroup"); 667 Collection c = (Collection )query.execute(); 668 query = pm.newQuery( 669 "SELECT FROM com.nightlabs.ipanema.security.UserGroup " + 670 "WHERE " + 671 " users.containsKey(paramUserID) " + 672 "PARAMETERS String paramUserID " + 673 "IMPORTS import java.lang.String"); 674 675 Collection includedUsers = (Collection )query.execute(userID); 676 Iterator i = c.iterator(); 677 Collection c2 = new HashSet (); 678 while(i.hasNext()) 679 { 680 Object o = i.next(); 681 if(!includedUsers.contains(o)) 682 c2.add(o); 683 } 684 return pm.detachCopyAll(c2); 685 687 689 } 690 finally 691 { 692 pm.close(); 693 } 694 } 695 696 697 705 public boolean userIDAlreadyRegistered(UserID userID) 706 throws ModuleException, ObjectIDException 707 { 708 PersistenceManager pm = getPersistenceManager(); 709 try 710 { 711 Object test = pm.getObjectById(userID, true); 712 LOGGER.debug("userIDAlreadyRegistered(\"" + userID + "\") = " + (test != null)); 713 return (test != null); 714 } 715 catch(JDOObjectNotFoundException e) 716 { 717 LOGGER.debug("userIDAlreadyRegistered(\"" + userID + "\") = false"); 718 return false; 719 } 720 finally 721 { 722 pm.close(); 723 } 724 } 725 726 735 public User getUser(UserID userID, String [] fetchGroups) 736 throws ModuleException 737 { 738 PersistenceManager pm = this.getPersistenceManager(); 739 try 740 { 741 if (fetchGroups != null) 742 pm.getFetchPlan().setGroups(fetchGroups); 743 else 744 pm.getFetchPlan().clearGroups(); 745 746 751 pm.getExtent(User.class, true); 752 Object o = pm.getObjectById(userID,true); 753 User usr = (User)pm.detachCopy(o); 754 755 775 return usr; 776 } 777 catch(JDOObjectNotFoundException e) 778 { 779 throw new ModuleException(e); 780 } 781 finally 782 { 783 pm.close(); 784 } 785 } 786 787 797 public User getUser(String userID, int includeMask) 798 throws SecurityException 799 { 800 try { 801 PersistenceManager pm = getPersistenceManager(); 802 try { 803 pm.getExtent(User.class, true); 804 try { 805 User user = (User) pm.getObjectById(UserID.create(getOrganisationID(), userID), true); 806 user.makeTransient(includeMask); 808 user.setPassword(null); 809 return user; 810 } catch (JDOObjectNotFoundException x) { 811 throw new UserNotFoundException("User \""+userID+"\" not found at organisation \""+getOrganisationID()+"\"!"); 812 } 813 } finally { 814 if (AuthorityManagerBean.CLOSE_PM) pm.close(); 815 } 816 } catch (SecurityException x) { 817 throw x; 818 } catch (Exception x) { 819 throw new SecurityException (x); 820 } 821 } 822 823 824 834 public void addUserToRoleGroups(String userID, String authorityID, Collection roleGroupIDs) 835 throws ModuleException 836 { 837 Iterator i = roleGroupIDs.iterator(); 838 while(i.hasNext()) 839 { 840 Object o = i.next(); 841 if(o instanceof String ) 842 addUserToRoleGroup(userID, authorityID, (String )o); 843 } 844 } 845 846 856 public void addUserToRoleGroup(String userID, String authorityID, String roleGroupID) 857 throws ModuleException 858 { 859 PersistenceManager pm = getPersistenceManager(); 860 try 861 { 862 pm.getExtent(Authority.class, true); 863 Authority auth = (Authority)pm.getObjectById(AuthorityID.create(authorityID), true); 864 pm.getExtent(User.class, true); 865 User usr = (User)pm.getObjectById(UserID.create(getOrganisationID(), userID), true); 866 pm.getExtent(RoleGroup.class, true); 867 RoleGroup rg = (RoleGroup)pm.getObjectById(RoleGroupID.create(roleGroupID), true); 868 869 RoleGroupRef rgf = auth.createRoleGroupRef(rg); 870 UserRef ur = auth.createUserRef(usr); 871 ur.addRoleGroupRef(rgf); 872 } 873 catch(JDOObjectNotFoundException e) 874 { 875 throw new ModuleException(e); 876 } 877 finally 878 { 879 pm.close(); 880 } 881 } 882 883 892 public void addUsersToUserGroup(String userGroupID, Collection userIDs) 893 throws SecurityException 894 { 895 Iterator i = userIDs.iterator(); 896 while(i.hasNext()) 897 { 898 Object o = i.next(); 899 if(o instanceof String ) 900 addUserToUserGroup((String )o, userGroupID); 901 } 902 } 903 904 905 914 public void addUserToUserGroups(String userID, Collection userGroupIDs) 915 throws SecurityException 916 { 917 Iterator i = userGroupIDs.iterator(); 918 while(i.hasNext()) 919 { 920 Object o = i.next(); 921 if(o instanceof String ) 922 addUserToUserGroup(userID, (String )o); 923 } 924 } 925 926 927 936 public void addUserToUserGroup(String userID, String userGroupID) 937 throws SecurityException 938 { 939 try { 940 PersistenceManager pm = getPersistenceManager(); 941 try { 942 pm.getExtent(User.class, true); 943 pm.getExtent(UserGroup.class, true); 944 945 User user; 946 try { 947 user = (User) pm.getObjectById(UserID.create(getOrganisationID(), userID), true); 948 } catch (JDOObjectNotFoundException x) { 949 throw new UserNotFoundException("User \""+userID+"\" not found at organisation \""+getOrganisationID()+"\"!"); 950 } 951 952 UserGroup userGroup; 953 try { 954 User tmpUser = (User) pm.getObjectById(UserID.create(getOrganisationID(), userGroupID), true); 955 956 if (!(tmpUser instanceof UserGroup)) 957 throw new ClassCastException ("userGroupID \""+userGroupID+"\" does not represent an object of type UserGroup, but of "+tmpUser.getClass().getName()); 958 959 userGroup = (UserGroup) tmpUser; 960 } catch (JDOObjectNotFoundException x) { 961 throw new UserNotFoundException("UserGroup \""+userGroupID+"\" not found at organisation \""+getOrganisationID()+"\"!"); 962 } 963 964 userGroup.addUser(user); 965 966 } finally { 967 if (AuthorityManagerBean.CLOSE_PM) pm.close(); 968 } 969 } catch (SecurityException x) { 970 throw x; 971 } catch (Exception x) { 972 throw new SecurityException (x); 973 } 974 } 975 976 986 public void removeUserFromRoleGroups(String userID, String authorityID, Collection roleGroupIDs) 987 throws ModuleException 988 { 989 Iterator i = roleGroupIDs.iterator(); 990 while(i.hasNext()) 991 { 992 Object o = i.next(); 993 if(o instanceof String ) 994 removeUserFromRoleGroup(userID, authorityID, (String )o); 995 } 996 } 997 998 1008 public void removeUserFromRoleGroup(String userID, String authorityID, String roleGroupID) 1009 throws ModuleException 1010 { 1011 PersistenceManager pm = getPersistenceManager(); 1012 try 1013 { 1014 UserRef uref = (UserRef)pm.getObjectById(UserRefID.create(authorityID, getOrganisationID(), userID), true); 1015 uref.removeRoleGroupRef(roleGroupID); 1016 } 1017 catch(JDOObjectNotFoundException e) 1018 { 1019 throw new ModuleException(e); 1020 } 1021 finally 1022 { 1023 pm.close(); 1024 } 1025 } 1026 1027 1028 1037 public void removeUsersFromUserGroup(String userGroupID, Collection userIDs) 1038 throws ModuleException 1039 { 1040 Iterator i = userIDs.iterator(); 1041 while(i.hasNext()) 1042 { 1043 Object o = i.next(); 1044 if(o instanceof String ) 1045 removeUserFromUserGroup((String )o, userGroupID); 1046 } 1047 } 1048 1049 1058 public void removeUserFromUserGroups(String userID, Collection userGroupIDs) 1059 throws ModuleException 1060 { 1061 Iterator i = userGroupIDs.iterator(); 1062 while(i.hasNext()) 1063 { 1064 Object o = i.next(); 1065 if(o instanceof String ) 1066 removeUserFromUserGroup(userID, (String )o); 1067 } 1068 } 1069 1070 1071 1080 1081 public void removeUserFromUserGroup(String userID, String userGroupID) 1082 throws ModuleException 1083 { 1084 PersistenceManager pm = getPersistenceManager(); 1085 try 1086 { 1087 pm.getExtent(UserGroup.class, true); 1090 UserGroup userGroup = (UserGroup) pm.getObjectById(UserID.create(getOrganisationID(), userGroupID), true); 1091 1092 1093 userGroup.removeUser(userID); 1094 } 1095 catch(JDOObjectNotFoundException e) 1096 { 1097 throw new ModuleException(e); 1098 } 1099 finally 1100 { 1101 pm.close(); 1102 } 1103 } 1104 1105 1106 1115 1116 public void assignPersonToUser(String userID, long personID) 1117 throws ModuleException 1118 { 1119 PersistenceManager pm = getPersistenceManager(); 1120 try 1121 { 1122 pm.getExtent(User.class, true); 1123 User usr = (User) pm.getObjectById(UserID.create(getOrganisationID(), userID), true); 1124 1125 pm.getExtent(Person.class, true); 1126 Person ps = (Person) pm.getObjectById(PersonID.create(getOrganisationID(), personID), true); 1127 1128 usr.setPerson(ps); 1129 } 1130 catch(JDOObjectNotFoundException e) 1131 { 1132 throw new ModuleException(e); 1133 } 1134 finally 1135 { 1136 pm.close(); 1137 } 1138 } 1139 1140 1141 1145 public void whoami() 1146 throws ModuleException 1147 { 1148 LOGGER.info("******** WHOAMI: "+getPrincipalString()); 1149 } 1150 1151 1182} | Popular Tags |