Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/InitFrom/src/org/litesoft/initfrom/client/boviews/UserViewAccessControlFactory.java

Diff revisions: vs.
  @@ -1,33 +1,28 @@
1 1 package org.litesoft.initfrom.client.boviews;
2 2
3 - import java.util.*;
4 -
5 3 import org.litesoft.core.simpletypes.*;
6 4 import org.litesoft.initfrom.client.*;
7 5 import org.litesoft.security.*;
8 6 import org.litesoft.uispecification.*;
9 7
10 - public class UserViewAccessControlFactory
11 - {
8 + import java.util.*;
9 +
10 + public class UserViewAccessControlFactory {
12 11 private static final Map<AccessKey, ViewAccessControlManager> CACHE = new HashMap<AccessKey, ViewAccessControlManager>();
13 12
14 - public static synchronized ViewAccessControlManager get( UserView pUser )
15 - {
13 + public static synchronized ViewAccessControlManager get( UserView pUser ) {
16 14 AccessKey zKey = new AccessKey( pUser );
17 15 ViewAccessControlManager zManager = CACHE.get( zKey );
18 - if ( zManager == null )
19 - {
16 + if ( zManager == null ) {
20 17 CACHE.put( zKey, zManager = createManager( zKey ) );
21 18 }
22 19 return zManager;
23 20 }
24 21
25 - private static class AccessKey
26 - {
22 + private static class AccessKey {
27 23 private int mFlags;
28 24
29 - private AccessKey( UserView pUser )
30 - {
25 + private AccessKey( UserView pUser ) {
31 26 mFlags = bit( Role.BITS.sAdminFlag, pUser.getCanAdministrate() ) + //
32 27 bit( Role.BITS.sRestrictedResourceMgrFlag, pUser.getRestrictedResourceManage() ) + //
33 28 bit( Role.BITS.sSprAdminFlag, pUser.getSuperAdmin() ) + //
  @@ -35,61 +30,49 @@
35 30 bit( Role.BITS.sNonGuestFlag, !pUser.isGuest() ) + //
36 31 Role.BITS.BIT.none();
37 32 TextLines zAllowedRoles = pUser.getCurrentRestrictedResourceAllowedRoles();
38 - for ( TextLine zRole : zAllowedRoles )
39 - {
33 + for ( TextLine zRole : zAllowedRoles ) {
40 34 mFlags += Role.getBitFor( zRole.getLine() );
41 35 }
42 36 }
43 37
44 - private int bit( int zBit, Boolean zFlag )
45 - {
38 + private int bit( int zBit, Boolean zFlag ) {
46 39 return Boolean.TRUE.equals( zFlag ) ? zBit : 0;
47 40 }
48 41
49 - private boolean isBit( int zBit )
50 - {
42 + private boolean isBit( int zBit ) {
51 43 return (0 != (mFlags & zBit));
52 44 }
53 45
54 - public boolean isRole( Role pRole )
55 - {
46 + public boolean isRole( Role pRole ) {
56 47 return isBit( pRole.getBit() );
57 48 }
58 49
59 - public boolean isAdminFlag()
60 - {
50 + public boolean isAdminFlag() {
61 51 return isBit( Role.BITS.sAdminFlag );
62 52 }
63 53
64 - public boolean isRestrictedResourceMgrFlag()
65 - {
54 + public boolean isRestrictedResourceMgrFlag() {
66 55 return isBit( Role.BITS.sRestrictedResourceMgrFlag );
67 56 }
68 57
69 - public boolean isSprAdminFlag()
70 - {
58 + public boolean isSprAdminFlag() {
71 59 return isBit( Role.BITS.sSprAdminFlag );
72 60 }
73 61
74 - public boolean isHelpDeskFlag()
75 - {
62 + public boolean isHelpDeskFlag() {
76 63 return isBit( Role.BITS.sHelpDeskFlag );
77 64 }
78 65
79 - public boolean isNonGuest()
80 - {
66 + public boolean isNonGuest() {
81 67 return isBit( Role.BITS.sNonGuestFlag );
82 68 }
83 69
84 70 @Override
85 - public boolean equals( Object o )
86 - {
87 - if ( this == o )
88 - {
71 + public boolean equals( Object o ) {
72 + if ( this == o ) {
89 73 return true;
90 74 }
91 - if ( o == null || getClass() != o.getClass() )
92 - {
75 + if ( o == null || getClass() != o.getClass() ) {
93 76 return false;
94 77 }
95 78
  @@ -99,22 +82,18 @@
99 82 }
100 83
101 84 @Override
102 - public int hashCode()
103 - {
85 + public int hashCode() {
104 86 return mFlags;
105 87 }
106 88 }
107 89
108 - private static void addSection( List<ViewDef[]> pSections, boolean pFlag, ViewDef[] pViewDefs )
109 - {
110 - if ( pFlag && (pViewDefs != null) )
111 - {
90 + private static void addSection( List<ViewDef[]> pSections, boolean pFlag, ViewDef[] pViewDefs ) {
91 + if ( pFlag && (pViewDefs != null) ) {
112 92 pSections.add( pViewDefs );
113 93 }
114 94 }
115 95
116 - private static ViewAccessControlManager createManager( AccessKey pKey )
117 - {
96 + private static ViewAccessControlManager createManager( AccessKey pKey ) {
118 97 List<ViewDef[]> zSections = new ArrayList<ViewDef[]>();
119 98 zSections.add( ViewDefs.ANY_USER );
120 99
  @@ -124,8 +103,7 @@
124 103 addSection( zSections, pKey.isRestrictedResourceMgrFlag(), ViewDefs.CAN_MANAGE_RESTRICTED_RESOURCES );
125 104 addSection( zSections, pKey.isSprAdminFlag(), ViewDefs.CAN_SUPER_ADMIN );
126 105
127 - for ( Role zRole : Role.values() )
128 - {
106 + for ( Role zRole : Role.values() ) {
129 107 addSection( zSections, pKey.isRole( zRole ), ViewDefs.ROLES_MAP.get( zRole ) );
130 108 }
131 109 return new ViewAccessControlManager.Only( zSections );