Changeset 6180 for main/waeup.sirp/trunk/src/waeup/sirp/authentication.txt
- Timestamp:
- 21 May 2011, 01:31:03 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/authentication.txt
r5404 r6180 12 12 Before we can check access we have to create an app: 13 13 14 >>> from zope.component.hooks import setSite # only needed in tests 14 15 >>> from waeup.sirp.app import University 15 16 >>> root = getRootFolder() 16 17 >>> u = University() 17 18 >>> root['app'] = u 19 >>> setSite(root['app']) # only needed in tests 18 20 19 21 To make sure, we can 'watch' pages, we first have to initialize our … … 42 44 See ``users.txt`` for details about the UserContainer we use here. 43 45 46 Users and local roles 47 ===================== 48 49 Accounts also hold infos about local roles assigned to a user. In the 50 beginning, users have no local roles at all: 51 52 >>> alice.getLocalRoles() 53 {} 54 55 But we can tell an account, that Alice got some role for a certain 56 object: 57 58 >>> chalet = object() 59 >>> root['app']['chalet'] = chalet 60 >>> alice.notifyLocalRoleChanged(chalet, 'BigBoss', granted=True) 61 62 Now Alice is the Big Boss: 63 64 >>> alice.getLocalRoles() 65 {'BigBoss': [<object object at 0x...>]} 66 67 When we do not want Alice to be the Big Boss we can tell that too: 68 69 >>> alice.notifyLocalRoleChanged(chalet, 'BigBoss', granted=False) 70 >>> alice.getLocalRoles() 71 {} 72 73 We can also use events to trigger such actions. This is recommended 74 because we do not neccessarily know where Alice lives: 75 76 >>> from waeup.sirp.users import LocalRoleSetEvent 77 >>> from zope.event import notify 78 >>> notify(LocalRoleSetEvent(chalet, 'BigBoss', 'alice', 79 ... granted=True)) 80 >>> alice.getLocalRoles() 81 {'BigBoss': [<object object at 0x...>]} 82 83 When objects are deleted, local roles are also deleted 84 semi-magically. This happens through event subscribers listening to 85 IObjectRemovedEvents. The latters are naturally only fired when ZODB 86 stored objects are removed. Furthermore this subscriber reads the 87 internal local roles table. 88 89 We create a faculty and grant Bob a local role: 90 91 >>> from zope.securitypolicy.interfaces import IPrincipalRoleManager 92 >>> from waeup.sirp.university.faculty import Faculty 93 >>> faculty = Faculty() 94 >>> root['app']['bobs_fac'] = faculty 95 >>> role_manager = IPrincipalRoleManager(faculty) 96 >>> role_manager.assignRoleToPrincipal( 97 ... 'waeup.PortalManager', 'bob') 98 99 We notify the machinery about that fact: 100 101 >>> notify(LocalRoleSetEvent(faculty, 'waeup.PortalManager', 'bob', 102 ... granted=True)) 103 >>> bob = root['app']['users']['bob'] 104 >>> bob.getLocalRoles() 105 {'waeup.PortalManager': [<waeup.sirp...Faculty object at 0x...>]} 106 107 When we delete the faculty from ZODB, also Bobs roles are modified: 108 109 >>> del root['app']['bobs_fac'] 110 >>> bob.getLocalRoles() 111 {} 44 112 45 113 Logging in via side bar
Note: See TracChangeset for help on using the changeset viewer.