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
e30abcca
Commit
e30abcca
authored
Mar 27, 2020
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
throw exception if oauthClient or user not found
parent
eb51d62a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
security/src/main/java/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
...va/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
+4
-2
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
...ys/blocks/security/service/impl/BasicUserServiceImpl.java
+5
-3
No files found.
security/src/main/java/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
View file @
e30abcca
...
...
@@ -44,6 +44,8 @@ import org.springframework.transaction.annotation.Transactional;
import
com.querydsl.core.types.Predicate
;
import
javax.persistence.EntityNotFoundException
;
/**
* The Class OAuthServiceImpl.
*/
...
...
@@ -219,7 +221,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')"
)
public
final
String
resetSecret
(
OAuthClient
oauthClient
)
{
oauthClient
=
oauthClientRepository
.
findById
(
oauthClient
.
getId
()).
orElse
(
oauthClient
);
oauthClient
=
oauthClientRepository
.
findById
(
oauthClient
.
getId
()).
orElse
Throw
(()
->
new
EntityNotFoundException
(
"Record not found."
)
);
String
oldHash
=
oauthClient
.
getClientSecret
();
String
newHash
=
null
;
...
...
@@ -238,7 +240,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')"
)
public
final
OAuthClient
removeSecret
(
OAuthClient
oauthClient
)
{
oauthClient
=
oauthClientRepository
.
findById
(
oauthClient
.
getId
()).
orElse
(
oauthClient
);
oauthClient
=
oauthClientRepository
.
findById
(
oauthClient
.
getId
()).
orElse
Throw
(()
->
new
EntityNotFoundException
(
"Record not found."
)
);
if
(
oauthClient
.
getAuthorizedGrantTypes
().
contains
(
"client_credentials"
))
{
throw
new
RuntimeException
(
"OAuth Client with client_credentials grant must have a secret"
);
}
...
...
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
View file @
e30abcca
...
...
@@ -43,6 +43,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.EntityNotFoundException
;
/**
* The Class BasicUserServiceImpl.
*
...
...
@@ -203,7 +205,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@PreAuthorize
(
"hasRole('ADMINISTRATOR') || principal.id == #user.id"
)
public
T
updateUser
(
T
user
,
final
String
email
,
final
String
fullName
)
throws
NotUniqueUserException
,
UserException
{
// reload
user
=
_repository
.
findById
(
user
.
getId
()).
orElse
(
user
);
user
=
_repository
.
findById
(
user
.
getId
()).
orElse
Throw
(()
->
new
EntityNotFoundException
(
"Record not found."
)
);
if
(!
StringUtils
.
equals
(
email
,
user
.
getEmail
())
&&
getUserByEmail
(
email
)
!=
null
)
{
throw
new
NotUniqueUserException
(
"Email address already registered"
);
...
...
@@ -237,7 +239,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@Override
@Transactional
public
T
setRoles
(
T
user
,
final
Set
<
R
>
newRoles
)
{
user
=
_repository
.
findById
(
user
.
getId
()).
orElse
(
user
);
user
=
_repository
.
findById
(
user
.
getId
()).
orElse
Throw
(()
->
new
EntityNotFoundException
(
"Record not found."
)
);
// Remove transient roles
newRoles
.
removeAll
(
getDefaultUserRoles
());
...
...
@@ -345,7 +347,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@Override
@Transactional
public
T
setAccountType
(
T
user
,
AccountType
accountType
)
{
T
u
=
_repository
.
findById
(
user
.
getId
()).
orElse
(
user
);
T
u
=
_repository
.
findById
(
user
.
getId
()).
orElse
Throw
(()
->
new
EntityNotFoundException
(
"Record not found."
)
);
u
.
setAccountType
(
accountType
);
if
(
accountType
!=
AccountType
.
LOCAL
)
{
...
...
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