use of org.xwiki.security.authorization.SecurityEntry in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method InsertUsersWithouShadow.
private Map<String, SecurityEntry> InsertUsersWithouShadow() throws ConflictingInsertionException, ParentEntryEvictedException {
Map<String, SecurityEntry> entries = new HashMap<String, SecurityEntry>();
// Add wikis
for (SecurityReference ref : wikiRefs) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
// XWiki spaces are required to load user entries
for (SecurityReference ref : xwikiSpaceRefs) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
// Insert some users
for (SecurityReference ref : userRefs) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
// Insert some groups
for (SecurityReference ref : groupRefs.keySet()) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
// Insert users in groups
for (SecurityReference ref : groupUserRefs) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
return entries;
}
use of org.xwiki.security.authorization.SecurityEntry in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method InsertUsers.
private Map<String, SecurityEntry> InsertUsers() throws ConflictingInsertionException, ParentEntryEvictedException {
Map<String, SecurityEntry> entries = InsertUsersWithouShadow();
// Check inserting shadow users
for (UserSecurityReference ref : userRefs) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
entries.put(AddUserEntry(entry), entry);
}
}
}
// Insert some groups
for (GroupSecurityReference ref : groupRefs.keySet()) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
entries.put(AddUserEntry(entry), entry);
}
}
}
// Insert shadow users in shadow groups
for (UserSecurityReference ref : groupUserRefs) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
entries.put(AddUserEntry(entry), entry);
}
}
}
return entries;
}
use of org.xwiki.security.authorization.SecurityEntry in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method testAddSecurityShadowEntry.
@Test
public void testAddSecurityShadowEntry() throws Exception {
InsertUsersWithouShadow();
final List<SecurityShadowEntry> allEntries = new ArrayList<SecurityShadowEntry>();
// Check inserting shadow users
for (UserSecurityReference ref : userRefs) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
assertThat(((DefaultSecurityCache) securityCache).get(AddUserEntry(entry)), sameInstance((SecurityEntry) entry));
allEntries.add(entry);
}
}
}
// Check inserting some shadow groups
for (GroupSecurityReference ref : groupRefs.keySet()) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
assertThat(((DefaultSecurityCache) securityCache).get(AddUserEntry(entry)), sameInstance((SecurityEntry) entry));
allEntries.add(entry);
}
}
}
// Check inserting shadow users in shadow groups
for (UserSecurityReference ref : groupUserRefs) {
if (ref.isGlobal()) {
for (SecurityReference wiki : Arrays.asList(wikiRef, anotherWikiRef)) {
SecurityShadowEntry entry = mockSecurityShadowEntry(ref, wiki);
assertThat(((DefaultSecurityCache) securityCache).get(AddUserEntry(entry)), sameInstance((SecurityEntry) entry));
allEntries.add(entry);
}
}
}
// Check a duplicate insertion
try {
AddUserEntry(allEntries.get(0));
} catch (ConflictingInsertionException e) {
fail("Inserting the same shadow entry twice should NOT throw a ConflictingInsertionException.");
}
// Check inserting a shadow for a missing user in an existing wiki
try {
AddUserEntry(mockSecurityShadowEntry(aMissingUserRef, wikiRef));
fail("Inserting a shadow entry without inserting its global user first should throw" + " a ParentEntryEvictedException.");
} catch (ParentEntryEvictedException ignore) {
// Expected.
}
// Check inserting a shadow for a existing user in a missing wiki
try {
AddUserEntry(mockSecurityShadowEntry(xuserRef, aMissingWikiRef));
fail("Inserting a shadow entry without inserting its wiki first should throw" + " a ParentEntryEvictedException.");
} catch (ParentEntryEvictedException ignore) {
// Expected.
}
}
use of org.xwiki.security.authorization.SecurityEntry in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method InsertEntities.
private Map<String, SecurityEntry> InsertEntities() throws ConflictingInsertionException, ParentEntryEvictedException {
Map<String, SecurityEntry> entries = new HashMap<String, SecurityEntry>();
for (SecurityReference ref : entityRefs) {
if (securityCache.get(ref) == null) {
SecurityRuleEntry entry = mockSecurityRuleEntry(ref);
entries.put(AddRuleEntry(entry), entry);
}
}
return entries;
}
use of org.xwiki.security.authorization.SecurityEntry in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method InsertAccess.
private Map<String, SecurityEntry> InsertAccess() throws ConflictingInsertionException, ParentEntryEvictedException {
Map<String, SecurityEntry> entries = new HashMap<String, SecurityEntry>();
// Insert access for simple users
for (UserSecurityReference user : userRefs) {
for (SecurityReference ref : entityRefs) {
SecurityAccessEntry entry = mockSecurityAccessEntry(ref, user);
String key = AddAccessEntry(entry);
if (key != null)
entries.put(key, entry);
}
SecurityAccessEntry entry = mockSecurityAccessEntry(user, user);
String key = AddAccessEntry(entry);
if (key != null)
entries.put(key, entry);
}
// Insert access for group users
for (UserSecurityReference user : groupUserRefs) {
for (SecurityReference ref : entityRefs) {
SecurityAccessEntry entry = mockSecurityAccessEntry(ref, user);
String key = AddAccessEntry(entry);
if (key != null)
entries.put(key, entry);
}
SecurityAccessEntry entry = mockSecurityAccessEntry(user, user);
String key = AddAccessEntry(entry);
if (key != null)
entries.put(key, entry);
}
return entries;
}
Aggregations