Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
2048c36f
Commit
2048c36f
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-869: check if the list of identities or security groups is null/empty before querying
parent
ef61beaa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/basesecurity/BaseSecurityManager.java
+3
-0
3 additions, 0 deletions
src/main/java/org/olat/basesecurity/BaseSecurityManager.java
src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
+30
-0
30 additions, 0 deletions
...t/java/org/olat/basesecurity/BaseSecurityManagerTest.java
with
33 additions
and
0 deletions
src/main/java/org/olat/basesecurity/BaseSecurityManager.java
+
3
−
0
View file @
2048c36f
...
...
@@ -637,6 +637,9 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity {
@Override
public
boolean
removeIdentityFromSecurityGroups
(
List
<
Identity
>
identities
,
List
<
SecurityGroup
>
secGroups
)
{
if
(
identities
==
null
||
identities
.
isEmpty
())
return
true
;
//nothing to do
if
(
secGroups
==
null
||
secGroups
.
isEmpty
())
return
true
;
//nothing to do
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"delete from "
).
append
(
SecurityGroupMembershipImpl
.
class
.
getName
()).
append
(
" as msi "
)
.
append
(
" where msi.identity.key in (:identityKeys) and msi.securityGroup.key in (:secGroupKeys)"
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
+
30
−
0
View file @
2048c36f
...
...
@@ -240,6 +240,36 @@ public class BaseSecurityManagerTest extends OlatTestCase {
Assert
.
assertEquals
(
id2
,
members
.
get
(
0
));
}
@Test
public
void
testRemoveFromSecurityGroup_list
()
{
//create a security group with 2 identites
Identity
id1
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"rm-3-sec-"
+
UUID
.
randomUUID
().
toString
());
Identity
id2
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"rm-4-sec-"
+
UUID
.
randomUUID
().
toString
());
SecurityGroup
secGroup
=
securityManager
.
createAndPersistSecurityGroup
();
securityManager
.
addIdentityToSecurityGroup
(
id1
,
secGroup
);
securityManager
.
addIdentityToSecurityGroup
(
id2
,
secGroup
);
dbInstance
.
commitAndCloseSession
();
//remove the first one
List
<
Identity
>
ids
=
new
ArrayList
<
Identity
>();
ids
.
add
(
id1
);
ids
.
add
(
id2
);
securityManager
.
removeIdentityFromSecurityGroups
(
ids
,
Collections
.
singletonList
(
secGroup
));
dbInstance
.
commitAndCloseSession
();
int
countMembers
=
securityManager
.
countIdentitiesOfSecurityGroup
(
secGroup
);
Assert
.
assertEquals
(
0
,
countMembers
);
List
<
Identity
>
members
=
securityManager
.
getIdentitiesOfSecurityGroup
(
secGroup
);
Assert
.
assertNotNull
(
members
);
Assert
.
assertTrue
(
members
.
isEmpty
());
//check if robust against null and empty
securityManager
.
removeIdentityFromSecurityGroups
(
ids
,
Collections
.<
SecurityGroup
>
emptyList
());
securityManager
.
removeIdentityFromSecurityGroups
(
Collections
.<
Identity
>
emptyList
(),
Collections
.
singletonList
(
secGroup
));
securityManager
.
removeIdentityFromSecurityGroups
(
ids
,
null
);
securityManager
.
removeIdentityFromSecurityGroups
(
null
,
Collections
.
singletonList
(
secGroup
));
}
/**
*
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment