1 package org.apache.fulcrum.security.impl.db; 2 3 56 57 import java.math.BigDecimal ; 58 import java.util.ArrayList ; 59 import java.util.Hashtable ; 60 import java.util.Iterator ; 61 import java.util.List ; 62 63 import org.apache.fulcrum.security.BaseSecurityService; 64 import org.apache.fulcrum.security.TurbineSecurity; 65 import org.apache.fulcrum.security.entity.Group; 66 import org.apache.fulcrum.security.entity.Permission; 67 import org.apache.fulcrum.security.entity.Role; 68 import org.apache.fulcrum.security.entity.SecurityEntity; 69 import org.apache.fulcrum.security.entity.User; 70 import org.apache.fulcrum.security.impl.db.entity.TurbineGroup; 71 import org.apache.fulcrum.security.impl.db.entity.TurbineGroupPeer; 72 import org.apache.fulcrum.security.impl.db.entity.TurbinePermission; 73 import org.apache.fulcrum.security.impl.db.entity.TurbinePermissionPeer; 74 import org.apache.fulcrum.security.impl.db.entity.TurbineRole; 75 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePeer; 76 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePermissionPeer; 77 import org.apache.fulcrum.security.impl.db.entity.TurbineUserGroupRolePeer; 78 import org.apache.fulcrum.security.impl.db.entity.UserPeer; 79 import org.apache.fulcrum.security.util.AccessControlList; 80 import org.apache.fulcrum.security.util.DataBackendException; 81 import org.apache.fulcrum.security.util.EntityExistsException; 82 import org.apache.fulcrum.security.util.GroupSet; 83 import org.apache.fulcrum.security.util.PermissionSet; 84 import org.apache.fulcrum.security.util.RoleSet; 85 import org.apache.fulcrum.security.util.UnknownEntityException; 86 import org.apache.log4j.Category; 87 import org.apache.torque.om.BaseObject; 88 import org.apache.torque.om.ObjectKey; 89 import org.apache.torque.util.Criteria; 90 91 99 public class DBSecurityService 100 extends BaseSecurityService 101 { 102 106 public static final String USER_PEER_CLASS_KEY = "userPeer.class"; 107 108 112 public static final String USER_PEER_CLASS_DEFAULT = 113 "org.apache.fulcrum.security.impl.db.entity.TurbineUserPeer"; 114 115 118 Category category = Category.getInstance(getClass().getName()); 119 120 123 124 136 public AccessControlList getACL( User user ) 137 throws DataBackendException, UnknownEntityException 138 { 139 if (!TurbineSecurity.accountExists(user)) 140 { 141 throw new UnknownEntityException("The account '" + 142 user.getUserName() + "' does not exist"); 143 } 144 try 145 { 146 Hashtable roles = new Hashtable (); 147 Hashtable permissions = new Hashtable (); 148 lockShared(); 151 152 154 Iterator groupsIterator = getAllGroups().elements(); 156 while(groupsIterator.hasNext()) 157 { 158 Group group = (Group)groupsIterator.next(); 159 RoleSet groupRoles = TurbineRolePeer.retrieveSet(user, group); 161 roles.put(group, groupRoles); 163 PermissionSet groupPermissions = new PermissionSet(); 165 Iterator rolesIterator = groupRoles.elements(); 167 while(rolesIterator.hasNext()) 168 { 169 Role role = (Role)rolesIterator.next(); 170 PermissionSet rolePermissions = 172 TurbinePermissionPeer.retrieveSet(role); 173 groupPermissions.add(rolePermissions); 174 } 175 permissions.put(group, groupPermissions); 177 } 178 return getAclInstance(roles, permissions); 179 } 180 catch(Exception e) 181 { 182 throw new DataBackendException("Failed to build ACL for user '" + 183 user.getUserName() + "'" , e); 184 } 185 finally 186 { 187 unlockShared(); 189 } 190 } 191 192 195 196 207 public synchronized void grant( User user, Group group, Role role ) 208 throws DataBackendException, UnknownEntityException 209 { 210 boolean userExists = false; 211 boolean groupExists = false; 212 boolean roleExists = false; 213 try 214 { 215 lockExclusive(); 216 userExists=TurbineSecurity.accountExists(user); 217 groupExists=checkExists(group); 218 roleExists=checkExists(role); 219 if (userExists && groupExists && roleExists) 220 { 221 Criteria criteria = new Criteria(); 222 criteria.add(TurbineUserGroupRolePeer.USER_ID, 223 ((BaseObject)user).getPrimaryKey()); 224 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, 225 ((BaseObject)group).getPrimaryKey()); 226 criteria.add(TurbineUserGroupRolePeer.ROLE_ID, 227 ((TurbineRole)role).getPrimaryKey()); 228 TurbineUserGroupRolePeer.doInsert(criteria); 229 return; 230 } 231 } 232 catch(Exception e) 233 { 234 throw new DataBackendException("grant(User,Group,Role) failed", e); 235 } 236 finally 237 { 238 unlockExclusive(); 239 } 240 if (!userExists) 241 { 242 throw new UnknownEntityException("Unknown user '" + 243 user.getUserName() + "'"); 244 } 245 if (!groupExists) 246 { 247 throw new UnknownEntityException("Unknown group '" + 248 ((SecurityEntity)group).getName() + "'"); 249 } 250 if (!roleExists) 251 { 252 throw new UnknownEntityException("Unknown role '" + 253 role.getName() + "'"); 254 } 255 } 256 257 268 public synchronized void revoke( User user, Group group, Role role ) 269 throws DataBackendException, UnknownEntityException 270 { 271 boolean userExists = false; 272 boolean groupExists = false; 273 boolean roleExists = false; 274 try 275 { 276 lockExclusive(); 277 userExists=TurbineSecurity.accountExists(user); 278 groupExists=checkExists(group); 279 roleExists=checkExists(role); 280 if (userExists && groupExists && roleExists) 281 { 282 Criteria criteria = new Criteria(); 283 criteria.add(TurbineUserGroupRolePeer.USER_ID, 284 ((BaseObject)user).getPrimaryKey()); 285 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, 286 ((BaseObject)group).getPrimaryKey()); 287 criteria.add(TurbineUserGroupRolePeer.ROLE_ID, 288 ((TurbineRole)role).getPrimaryKey()); 289 TurbineUserGroupRolePeer.doDelete(criteria); 290 return; 291 } 292 } 293 catch(Exception e) 294 { 295 throw new DataBackendException("revoke(User,Role,Group) failed", e); 296 } 297 finally 298 { 299 unlockExclusive(); 300 } 301 if (!userExists) 302 { 303 throw new UnknownEntityException("Unknown user '" + 304 user.getUserName() + "'"); 305 } 306 if (!groupExists) 307 { 308 throw new UnknownEntityException("Unknown group '" + 309 ((SecurityEntity)group).getName() + "'"); 310 } 311 if (!roleExists) 312 { 313 throw new UnknownEntityException("Unknown role '" + 314 role.getName() + "'"); 315 } 316 } 317 318 328 public synchronized void revokeAll( User user ) 329 throws DataBackendException, UnknownEntityException 330 { 331 boolean userExists = false; 332 try 333 { 334 lockExclusive(); 335 userExists=TurbineSecurity.accountExists(user); 336 if (userExists) 337 { 338 343 ObjectKey key = ((BaseObject) user).getPrimaryKey(); 348 TurbineUserGroupRolePeer.deleteAll( 349 TurbineUserGroupRolePeer.TABLE_NAME, 350 TurbineUserGroupRolePeer.USER_ID, 351 ((BigDecimal ) key.getValue()).intValue()); 352 return; 353 } 354 } 355 catch(Exception e) 356 { 357 throw new DataBackendException("revokeAll(User) failed", e); 358 } 359 finally 360 { 361 unlockExclusive(); 362 } 363 throw new UnknownEntityException("Unknown user '" + 364 user.getUserName() + '\''); 365 } 366 367 376 public synchronized void grant( Role role, Permission permission ) 377 throws DataBackendException, UnknownEntityException 378 { 379 boolean roleExists = false; 380 boolean permissionExists = false; 381 try 382 { 383 lockExclusive(); 384 roleExists=checkExists(role); 385 permissionExists=checkExists(permission); 386 if (roleExists && permissionExists) 387 { 388 Criteria criteria = new Criteria(); 389 criteria.add(TurbineRolePermissionPeer.ROLE_ID, 390 ((TurbineRole)role).getPrimaryKey()); 391 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, 392 ((BaseObject)permission).getPrimaryKey()); 393 TurbineUserGroupRolePeer.doInsert(criteria); 394 return; 395 } 396 } 397 catch(Exception e) 398 { 399 throw new DataBackendException("grant(Role,Permission) failed", e); 400 } 401 finally 402 { 403 unlockExclusive(); 404 } 405 if (!roleExists) 406 { 407 throw new UnknownEntityException("Unknown role '" + 408 role.getName() + "'"); 409 } 410 if (!permissionExists) 411 { 412 throw new UnknownEntityException("Unknown permission '" + 413 ((SecurityEntity)permission).getName() + "'"); 414 } 415 } 416 417 426 public synchronized void revoke( Role role, Permission permission ) 427 throws DataBackendException, UnknownEntityException 428 { 429 boolean roleExists = false; 430 boolean permissionExists = false; 431 try 432 { 433 lockExclusive(); 434 roleExists=checkExists(role); 435 permissionExists=checkExists(permission); 436 if (roleExists && permissionExists) 437 { 438 Criteria criteria = new Criteria(); 439 criteria.add(TurbineRolePermissionPeer.ROLE_ID, 440 ((TurbineRole)role).getPrimaryKey()); 441 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, 442 ((BaseObject)permission).getPrimaryKey()); 443 TurbineRolePermissionPeer.doDelete(criteria); 444 return; 445 } 446 } 447 catch(Exception e) 448 { 449 throw new DataBackendException("revoke(Role,Permission) failed", e); 450 } 451 finally 452 { 453 unlockExclusive(); 454 } 455 if (!roleExists) 456 { 457 throw new UnknownEntityException("Unknown role '" + 458 role.getName() + "'"); 459 } 460 if (!permissionExists) 461 { 462 throw new UnknownEntityException("Unknown permission '" + 463 ((SecurityEntity)permission).getName() + "'"); 464 } 465 } 466 467 477 public synchronized void revokeAll( Role role ) 478 throws DataBackendException, UnknownEntityException 479 { 480 boolean roleExists = false; 481 try 482 { 483 lockExclusive(); 484 roleExists=checkExists(role); 485 if (roleExists) 486 { 487 491 495 ObjectKey key = ((TurbineRole)role).getPrimaryKey(); 496 TurbineRolePermissionPeer.deleteAll( 497 TurbineRolePermissionPeer.TABLE_NAME, 498 TurbineRolePermissionPeer.ROLE_ID, 499 ((BigDecimal ) key.getValue()).intValue()); 500 return; 501 } 502 } 503 catch(Exception e) 504 { 505 throw new DataBackendException("revokeAll(Role) failed", e); 506 } 507 finally 508 { 509 unlockExclusive(); 510 } 511 throw new UnknownEntityException("Unknown role '" + 512 role.getName() + "'"); 513 } 514 515 518 519 525 public GroupSet getGroups( Criteria criteria ) 526 throws DataBackendException 527 { 528 Criteria dbCriteria = new Criteria(); 529 Iterator keys = criteria.keySet().iterator(); 530 while(keys.hasNext()) 531 { 532 String key = (String )keys.next(); 533 dbCriteria.put(TurbineGroupPeer.getColumnName(key), 534 criteria.get(key)); 535 } 536 List groups = new ArrayList (0); 537 try 538 { 539 groups = TurbineGroupPeer.doSelect(criteria); 540 } 541 catch(Exception e) 542 { 543 throw new DataBackendException("getGroups(Criteria) failed", e); 544 } 545 return new GroupSet(groups); 546 } 547 548 554 public RoleSet getRoles( Criteria criteria ) 555 throws DataBackendException 556 { 557 Criteria dbCriteria = new Criteria(); 558 Iterator keys = criteria.keySet().iterator(); 559 while(keys.hasNext()) 560 { 561 String key = (String )keys.next(); 562 dbCriteria.put(TurbineRolePeer.getColumnName(key), 563 criteria.get(key)); 564 } 565 List roles = new ArrayList (0); 566 try 567 { 568 roles = TurbineRolePeer.doSelect(criteria); 569 } 570 catch(Exception e) 571 { 572 throw new DataBackendException("getRoles(Criteria) failed", e); 573 } 574 return new RoleSet(roles); 575 } 576 577 583 public PermissionSet getPermissions( Criteria criteria ) 584 throws DataBackendException 585 { 586 Criteria dbCriteria = new Criteria(); 587 Iterator keys = criteria.keySet().iterator(); 588 while(keys.hasNext()) 589 { 590 String key = (String )keys.next(); 591 dbCriteria.put(TurbinePermissionPeer.getColumnName(key), 592 criteria.get(key)); 593 } 594 List permissions = new ArrayList (0); 595 try 596 { 597 permissions = TurbinePermissionPeer.doSelect(criteria); 598 } 599 catch(Exception e) 600 { 601 throw new DataBackendException("getPermissions(Criteria) failed", e); 602 } 603 return new PermissionSet(permissions); 604 } 605 606 614 public PermissionSet getPermissions( Role role ) 615 throws DataBackendException, UnknownEntityException 616 { 617 boolean roleExists = false; 618 try 619 { 620 lockShared(); 621 roleExists = checkExists(role); 622 if (roleExists) 623 { 624 return TurbinePermissionPeer.retrieveSet(role); 625 } 626 } 627 catch(Exception e) 628 { 629 throw new DataBackendException("getPermissions(Role) failed", e); 630 } 631 finally 632 { 633 unlockShared(); 634 } 635 throw new UnknownEntityException("Unknown role '" + 636 role.getName() + "'"); 637 } 638 639 647 public void saveGroup( Group group ) 648 throws DataBackendException, UnknownEntityException 649 { 650 boolean groupExists = false; 651 try 652 { 653 groupExists = checkExists(group); 654 if (groupExists) 655 { 656 Criteria criteria = TurbineGroupPeer 657 .buildCriteria((TurbineGroup)group); 658 TurbineGroupPeer.doUpdate(criteria); 659 return; 660 } 661 } 662 catch(Exception e) 663 { 664 throw new DataBackendException("saveGroup(Group) failed" ,e); 665 } 666 throw new UnknownEntityException("Unknown group '" + group + "'"); 667 } 668 669 677 public void saveRole( Role role ) 678 throws DataBackendException, UnknownEntityException 679 { 680 boolean roleExists = false; 681 try 682 { 683 roleExists = checkExists(role); 684 if (roleExists) 685 { 686 Criteria criteria = TurbineRolePeer 687 .buildCriteria((TurbineRole)role); 688 TurbineRolePeer.doUpdate(criteria); 689 return; 690 } 691 } 692 catch(Exception e) 693 { 694 throw new DataBackendException("saveRole(Role) failed", e); 695 } 696 throw new UnknownEntityException("Unknown role '" + role + "'"); 697 } 698 699 708 public void savePermission( Permission permission ) 709 throws DataBackendException, UnknownEntityException 710 { 711 boolean permissionExists = false; 712 try 713 { 714 permissionExists = checkExists(permission); 715 if (permissionExists) 716 { 717 Criteria criteria = TurbinePermissionPeer 718 .buildCriteria((TurbinePermission)permission); 719 TurbinePermissionPeer.doUpdate(criteria); 720 return; 721 } 722 } 723 catch(Exception e) 724 { 725 throw new DataBackendException("savePermission(Permission) failed", e); 726 } 727 throw new UnknownEntityException("Unknown permission '" + permission + "'"); 728 } 729 730 733 public Group getNewGroup( String groupName ) 734 { 735 try 736 { 737 return getGroupInstance(groupName); 738 } 739 catch(UnknownEntityException uee) 740 { 741 return null; 742 } 743 } 744 745 748 public Role getNewRole( String roleName ) 749 { 750 try 751 { 752 return getRoleInstance(roleName); 753 } 754 catch(UnknownEntityException uee) 755 { 756 return null; 757 } 758 } 759 760 763 public Permission getNewPermission( String permissionName ) 764 { 765 try 766 { 767 return getPermissionInstance(permissionName); 768 } 769 catch(UnknownEntityException uee) 770 { 771 return null; 772 } 773 } 774 775 784 public synchronized Group addGroup( Group group ) 785 throws DataBackendException, EntityExistsException 786 { 787 boolean groupExists = false; 788 try 789 { 790 lockExclusive(); 791 groupExists = checkExists(group); 792 if (!groupExists) 793 { 794 Criteria criteria = TurbineGroupPeer 796 .buildCriteria((TurbineGroup)group); 797 TurbineGroupPeer.doInsert(criteria); 798 criteria = new Criteria(); 800 criteria.add(TurbineGroupPeer.NAME, 801 ((SecurityEntity)group).getName()); 802 List results = TurbineGroupPeer.doSelect(criteria); 803 if (results.size() != 1) 804 { 805 throw new DataBackendException( 806 "Internal error - query returned " + 807 results.size() + " rows"); 808 } 809 Group newGroup = (Group)results.get(0); 810 getAllGroups().add(newGroup); 812 return newGroup; 814 } 815 } 816 catch(Exception e) 817 { 818 throw new DataBackendException("addGroup(Group) failed", e); 819 } 820 finally 821 { 822 unlockExclusive(); 823 } 824 throw new EntityExistsException("Group '" + group + 827 "' already exists"); 828 } 829 830 839 public synchronized Role addRole( Role role ) 840 throws DataBackendException, EntityExistsException 841 { 842 boolean roleExists = false; 843 try 844 { 845 lockExclusive(); 846 roleExists = checkExists(role); 847 if (!roleExists) 848 { 849 Criteria criteria = TurbineRolePeer 851 .buildCriteria((TurbineRole)role); 852 TurbineRolePeer.doInsert(criteria); 853 criteria = new Criteria(); 855 criteria.add(TurbineRolePeer.NAME, role.getName()); 856 List results = TurbineRolePeer.doSelect(criteria); 857 if (results.size() != 1) 858 { 859 throw new DataBackendException( 860 "Internal error - query returned " + 861 results.size() + " rows"); 862 } 863 Role newRole = (Role)results.get(0); 864 getAllRoles().add(newRole); 866 return newRole; 868 } 869 } 870 catch(Exception e) 871 { 872 throw new DataBackendException("addRole(Role) failed", e); 873 } 874 finally 875 { 876 unlockExclusive(); 877 } 878 throw new EntityExistsException("Role '" + role + "' already exists"); 881 } 882 883 892 public synchronized Permission addPermission( Permission permission ) 893 throws DataBackendException, EntityExistsException 894 { 895 boolean permissionExists = false; 896 try 897 { 898 lockExclusive(); 899 permissionExists = checkExists(permission); 900 if (!permissionExists) 901 { 902 Criteria criteria = TurbinePermissionPeer 904 .buildCriteria((TurbinePermission)permission); 905 TurbinePermissionPeer.doInsert(criteria); 906 criteria = new Criteria(); 908 criteria.add(TurbinePermissionPeer.NAME, 909 ((SecurityEntity)permission).getName()); 910 List results = TurbinePermissionPeer.doSelect(criteria); 911 if (results.size() != 1) 912 { 913 throw new DataBackendException( 914 "Internal error - query returned " + 915 results.size() + " rows"); 916 } 917 Permission newPermission = (Permission)results.get(0); 918 getAllPermissions().add(newPermission); 920 return newPermission; 922 } 923 } 924 catch(Exception e) 925 { 926 throw new DataBackendException("addPermission(Permission) failed", e); 927 } 928 finally 929 { 930 unlockExclusive(); 931 } 932 throw new EntityExistsException("Permission '" + permission + 935 "' already exists"); 936 } 937 938 946 public synchronized void removeGroup( Group group ) 947 throws DataBackendException, UnknownEntityException 948 { 949 boolean groupExists = false; 950 try 951 { 952 lockExclusive(); 953 groupExists = checkExists(group); 954 if (groupExists) 955 { 956 Criteria criteria = TurbineGroupPeer 957 .buildCriteria((TurbineGroup)group); 958 TurbineGroupPeer.doDelete(criteria); 959 getAllGroups().remove(group); 960 return; 961 } 962 } 963 catch(Exception e) 964 { 965 category.error("Failed to delete a Group"); 966 category.error(e); 967 throw new DataBackendException("removeGroup(Group) failed", e); 968 } 969 finally 970 { 971 unlockExclusive(); 972 } 973 throw new UnknownEntityException("Unknown group '" + group + "'"); 974 } 975 976 984 public synchronized void removeRole( Role role ) 985 throws DataBackendException, UnknownEntityException 986 { 987 boolean roleExists = false; 988 try 989 { 990 lockExclusive(); 991 roleExists = checkExists(role); 992 if (roleExists) 993 { 994 revokeAll(role); 996 Criteria criteria = TurbineRolePeer 997 .buildCriteria((TurbineRole)role); 998 TurbineRolePeer.doDelete(criteria); 999 getAllRoles().remove(role); 1000 return; 1001 } 1002 } 1003 catch(Exception e) 1004 { 1005 throw new DataBackendException("removeRole(Role)" ,e); 1006 } 1007 finally 1008 { 1009 unlockExclusive(); 1010 } 1011 throw new UnknownEntityException("Unknown role '" + role + "'"); 1012 } 1013 1014 1022 public synchronized void removePermission( Permission permission ) 1023 throws DataBackendException, UnknownEntityException 1024 { 1025 boolean permissionExists = false; 1026 try 1027 { 1028 lockExclusive(); 1029 permissionExists = checkExists(permission); 1030 if (permissionExists) 1031 { 1032 Criteria criteria = TurbinePermissionPeer 1033 .buildCriteria((TurbinePermission)permission); 1034 TurbinePermissionPeer.doDelete(criteria); 1035 getAllPermissions().remove(permission); 1036 return; 1037 } 1038 } 1039 catch(Exception e) 1040 { 1041 throw new DataBackendException("removePermission(Permission)" ,e); 1042 } 1043 finally 1044 { 1045 unlockExclusive(); 1046 } 1047 throw new UnknownEntityException("Unknown permission '" + 1048 permission + "'"); 1049 } 1050 1051 1060 public synchronized void renameGroup( Group group, String name ) 1061 throws DataBackendException, UnknownEntityException 1062 { 1063 boolean groupExists = false; 1064 try 1065 { 1066 lockExclusive(); 1067 groupExists = checkExists(group); 1068 if (groupExists) 1069 { 1070 ((SecurityEntity)group).setName(name); 1071 Criteria criteria = TurbineGroupPeer 1072 .buildCriteria((TurbineGroup)group); 1073 TurbineGroupPeer.doUpdate(criteria); 1074 return; 1075 } 1076 } 1077 catch(Exception e) 1078 { 1079 throw new DataBackendException("renameGroup(Group,String)" ,e); 1080 } 1081 finally 1082 { 1083 unlockExclusive(); 1084 } 1085 throw new UnknownEntityException("Unknown group '" + group + "'"); 1086 } 1087 1088 1097 public synchronized void renameRole( Role role, String name ) 1098 throws DataBackendException, UnknownEntityException 1099 { 1100 boolean roleExists = false; 1101 try 1102 { 1103 lockExclusive(); 1104 roleExists = checkExists(role); 1105 if (roleExists) 1106 { 1107 role.setName(name); 1108 Criteria criteria = TurbineRolePeer 1109 .buildCriteria((TurbineRole)role); 1110 TurbineRolePeer.doUpdate(criteria); 1111 return; 1112 } 1113 } 1114 catch(Exception e) 1115 { 1116 throw new DataBackendException("renameRole(Role,String)" ,e); 1117 } 1118 finally 1119 { 1120 unlockExclusive(); 1121 } 1122 throw new UnknownEntityException("Unknown role '" + role + "'"); 1123 } 1124 1125 1134 public synchronized void renamePermission(Permission permission, String name) 1135 throws DataBackendException, UnknownEntityException 1136 { 1137 boolean permissionExists = false; 1138 try 1139 { 1140 lockExclusive(); 1141 permissionExists = checkExists(permission); 1142 if (permissionExists) 1143 { 1144 ((SecurityEntity)permission).setName(name); 1145 Criteria criteria = TurbinePermissionPeer 1146 .buildCriteria((TurbinePermission)permission); 1147 TurbinePermissionPeer.doUpdate(criteria); 1148 return; 1149 } 1150 } 1151 catch(Exception e) 1152 { 1153 throw new DataBackendException("renamePermission(Permission,name)", e); 1154 } 1155 finally 1156 { 1157 unlockExclusive(); 1158 } 1159 throw new UnknownEntityException("Unknown permission '" + 1160 permission + "'"); 1161 } 1162 1163 1164 1165 1173 public Class getUserPeerClass() 1174 throws UnknownEntityException 1175 { 1176 String userPeerClassName = getConfiguration().getString( 1177 USER_PEER_CLASS_KEY, USER_PEER_CLASS_DEFAULT); 1178 1179 try 1180 { 1181 return Class.forName(userPeerClassName); 1182 } 1183 catch(Exception e) 1184 { 1185 throw new UnknownEntityException( 1186 "Failed create a Class object for UserPeer implementation", e); 1187 } 1188 } 1189 1190 1199 public UserPeer getUserPeerInstance() throws UnknownEntityException 1200 { 1201 UserPeer up; 1202 try 1203 { 1204 up = (UserPeer)getUserPeerClass().newInstance(); 1205 } 1206 catch(Exception e) 1207 { 1208 throw new UnknownEntityException( 1209 "Failed instantiate an UserPeer implementation object", e); 1210 } 1211 return up; 1212 } 1213 1214 1215 1224 protected boolean checkExists(Group group) 1225 throws DataBackendException, Exception 1226 { 1227 return TurbineGroupPeer.checkExists(group); 1228 } 1229 1230 1239 protected boolean checkExists(Role role) 1240 throws DataBackendException, Exception 1241 { 1242 return TurbineRolePeer.checkExists(role); 1243 } 1244 1245 1254 protected boolean checkExists(Permission permission) 1255 throws DataBackendException, Exception 1256 { 1257 return TurbinePermissionPeer.checkExists(permission); 1258 } 1259 1260} 1261 | Popular Tags |