Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
App Blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Genesys PGR
App Blocks
Commits
66a63f01
Commit
66a63f01
authored
Feb 17, 2020
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Account expired
parent
6e96b331
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
security/src/main/java/org/genesys/blocks/security/model/BasicUser.java
...ain/java/org/genesys/blocks/security/model/BasicUser.java
+3
-1
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
...ys/blocks/security/service/impl/BasicUserServiceImpl.java
+8
-0
security/src/test/java/org/genesys/blocks/security/test/BasicUserServiceTest.java
...rg/genesys/blocks/security/test/BasicUserServiceTest.java
+14
-1
No files found.
security/src/main/java/org/genesys/blocks/security/model/BasicUser.java
View file @
66a63f01
...
...
@@ -370,7 +370,9 @@ public abstract class BasicUser<R extends GrantedAuthority> extends AclSid imple
@Override
@JsonView
(
JsonViews
.
Protected
.
class
)
public
boolean
isAccountNonExpired
()
{
return
(
accountExpires
==
null
)
||
!
accountExpires
.
before
(
new
Date
());
return
true
;
// TODO Re-enable when we have a way to extend accounts
// return (accountExpires == null) || !accountExpires.before(new Date());
}
/*
...
...
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
View file @
66a63f01
...
...
@@ -265,6 +265,12 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
public
T
changePassword
(
final
T
user
,
final
String
password
)
throws
PasswordPolicyException
{
if
(
user
.
getAccountType
()
==
AccountType
.
LOCAL
)
{
setPassword
(
user
,
password
);
// Set account to expire 1 month after change password
Calendar
accountExpires
=
Calendar
.
getInstance
();
accountExpires
.
add
(
Calendar
.
MONTH
,
1
);
user
.
setAccountExpires
(
accountExpires
.
getTime
());
return
deepLoad
(
_repository
.
save
(
user
));
}
else
{
throw
new
PasswordPolicyException
(
"Password can be set only for LOCAL account types"
);
...
...
@@ -282,8 +288,10 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
if
(
user
.
getAccountType
()
==
AccountType
.
LOCAL
)
{
assureGoodPassword
(
password
);
user
.
setPassword
(
password
==
null
?
null
:
passwordEncoder
.
encode
(
password
));
user
.
setPasswordExpires
(
null
);
}
else
{
user
.
setPassword
(
THIS_IS_NOT_A_PASSWORD
);
user
.
setPasswordExpires
(
null
);
}
}
...
...
security/src/test/java/org/genesys/blocks/security/test/BasicUserServiceTest.java
View file @
66a63f01
...
...
@@ -23,8 +23,11 @@ import static org.hamcrest.Matchers.is;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.Calendar
;
import
com.google.common.collect.Sets
;
import
org.genesys.blocks.security.NotUniqueUserException
;
...
...
@@ -55,7 +58,17 @@ public class BasicUserServiceTest extends ServiceTest {
assertThat
(
user
.
getId
(),
is
(
notNullValue
()));
assertThat
(
user
.
getUuid
(),
is
(
notNullValue
()));
assertThat
(
user
.
getAccountType
(),
is
(
AccountType
.
LOCAL
));
testUserService
.
changePassword
(
user
,
"newPassword2#"
);
TestUser
updatedUser
=
testUserService
.
changePassword
(
user
,
"newPassword2#"
);
Calendar
accountExpires
=
Calendar
.
getInstance
();
accountExpires
.
add
(
Calendar
.
MONTH
,
1
);
Calendar
updatedAccountExpires
=
Calendar
.
getInstance
();
updatedAccountExpires
.
setTime
(
updatedUser
.
getAccountExpires
());
assertEquals
(
accountExpires
.
get
(
Calendar
.
YEAR
),
updatedAccountExpires
.
get
(
Calendar
.
YEAR
));
assertEquals
(
accountExpires
.
get
(
Calendar
.
MONTH
),
updatedAccountExpires
.
get
(
Calendar
.
MONTH
));
assertEquals
(
accountExpires
.
get
(
Calendar
.
DAY_OF_MONTH
),
updatedAccountExpires
.
get
(
Calendar
.
DAY_OF_MONTH
));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment