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
95abc52e
Commit
95abc52e
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-948: update credentials only if the algorithm or the password changed
parent
6fc2da37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+10
-0
10 additions, 0 deletions
src/main/java/org/olat/basesecurity/BaseSecurityManager.java
src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
+26
-0
26 additions, 0 deletions
...t/java/org/olat/basesecurity/BaseSecurityManagerTest.java
with
36 additions
and
0 deletions
src/main/java/org/olat/basesecurity/BaseSecurityManager.java
+
10
−
0
View file @
95abc52e
...
@@ -1532,6 +1532,16 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity {
...
@@ -1532,6 +1532,16 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity {
@Override
@Override
public
Authentication
updateCredentials
(
Authentication
authentication
,
String
password
,
Algorithm
algorithm
)
{
public
Authentication
updateCredentials
(
Authentication
authentication
,
String
password
,
Algorithm
algorithm
)
{
if
(
authentication
.
getAlgorithm
()
!=
null
&&
authentication
.
getAlgorithm
().
equals
(
algorithm
.
name
()))
{
//check if update is needed
String
currentSalt
=
authentication
.
getSalt
();
String
newCredentials
=
Encoder
.
encrypt
(
password
,
currentSalt
,
algorithm
);
if
(
newCredentials
.
equals
(
authentication
.
getCredential
()))
{
//same credentials
return
authentication
;
}
}
String
salt
=
algorithm
.
isSalted
()
?
Encoder
.
getSalt
()
:
null
;
String
salt
=
algorithm
.
isSalted
()
?
Encoder
.
getSalt
()
:
null
;
String
newCredentials
=
Encoder
.
encrypt
(
password
,
salt
,
algorithm
);
String
newCredentials
=
Encoder
.
encrypt
(
password
,
salt
,
algorithm
);
authentication
.
setSalt
(
salt
);
authentication
.
setSalt
(
salt
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
+
26
−
0
View file @
95abc52e
...
@@ -41,6 +41,7 @@ import org.olat.core.id.Roles;
...
@@ -41,6 +41,7 @@ import org.olat.core.id.Roles;
import
org.olat.core.id.User
;
import
org.olat.core.id.User
;
import
org.olat.core.id.UserConstants
;
import
org.olat.core.id.UserConstants
;
import
org.olat.core.util.Encoder
;
import
org.olat.core.util.Encoder
;
import
org.olat.login.LoginModule
;
import
org.olat.resource.OLATResource
;
import
org.olat.resource.OLATResource
;
import
org.olat.test.JunitTestHelper
;
import
org.olat.test.JunitTestHelper
;
import
org.olat.test.OlatTestCase
;
import
org.olat.test.OlatTestCase
;
...
@@ -929,6 +930,31 @@ public class BaseSecurityManagerTest extends OlatTestCase {
...
@@ -929,6 +930,31 @@ public class BaseSecurityManagerTest extends OlatTestCase {
dbInstance
.
commitAndCloseSession
();
dbInstance
.
commitAndCloseSession
();
}
}
@Test
public
void
updateToSaltedAuthentication
()
{
Identity
ident
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"auth-c-"
+
UUID
.
randomUUID
().
toString
());
dbInstance
.
commitAndCloseSession
();
Authentication
auth
=
securityManager
.
findAuthentication
(
ident
,
"OLAT"
);
String
credentials
=
auth
.
getCredential
();
Authentication
updatedAuth
=
securityManager
.
updateCredentials
(
auth
,
"secret"
,
LoginModule
.
getDefaultHashAlgorithm
());
Assert
.
assertNotNull
(
auth
);
Assert
.
assertNotNull
(
updatedAuth
);
Assert
.
assertEquals
(
auth
,
updatedAuth
);
Assert
.
assertFalse
(
credentials
.
equals
(
updatedAuth
.
getCredential
()));
dbInstance
.
commitAndCloseSession
();
Authentication
auth2
=
securityManager
.
findAuthentication
(
ident
,
"OLAT"
);
String
credentials2
=
auth2
.
getCredential
();
Authentication
notUpdatedAuth
=
securityManager
.
updateCredentials
(
auth2
,
"secret"
,
LoginModule
.
getDefaultHashAlgorithm
());
Assert
.
assertNotNull
(
auth2
);
Assert
.
assertNotNull
(
notUpdatedAuth
);
Assert
.
assertSame
(
auth2
,
notUpdatedAuth
);
Assert
.
assertEquals
(
credentials2
,
notUpdatedAuth
.
getCredential
());
Assert
.
assertFalse
(
credentials
.
equals
(
notUpdatedAuth
.
getCredential
()));
dbInstance
.
commitAndCloseSession
();
}
@Test
@Test
public
void
deleteAuthentication
()
{
public
void
deleteAuthentication
()
{
Identity
identity
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"auth-del-"
+
UUID
.
randomUUID
().
toString
());
Identity
identity
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"auth-del-"
+
UUID
.
randomUUID
().
toString
());
...
...
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