Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
879eadf5
Commit
879eadf5
authored
Dec 05, 2013
by
Matija Obreza
Browse files
Use User#uuid as 'username' for Principal
parent
622d0999
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/impl/User.java
View file @
879eadf5
...
...
@@ -18,6 +18,7 @@ package org.genesys2.server.model.impl;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.UUID
;
import
javax.persistence.CollectionTable
;
import
javax.persistence.Column
;
...
...
@@ -26,6 +27,7 @@ import javax.persistence.Entity;
import
javax.persistence.EnumType
;
import
javax.persistence.Enumerated
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.PrePersist
;
import
javax.persistence.Table
;
import
net.sf.oval.constraint.Email
;
...
...
@@ -44,6 +46,9 @@ public class User extends BusinessModel {
*/
private
static
final
long
serialVersionUID
=
4564013753931115445L
;
@Column
(
length
=
36
,
unique
=
true
)
private
String
uuid
;
// validation
@NotNull
(
message
=
"sample.error.not.null"
)
@NotEmpty
(
message
=
"sample.error.not.empty"
)
...
...
@@ -79,6 +84,14 @@ public class User extends BusinessModel {
@Column
(
nullable
=
false
,
updatable
=
false
,
name
=
"sys"
)
private
boolean
systemAccount
;
@PrePersist
void
ensureUUID
()
{
if
(
this
.
uuid
==
null
)
{
this
.
uuid
=
UUID
.
randomUUID
().
toString
();
}
}
public
String
getEmail
()
{
return
email
;
}
...
...
@@ -145,6 +158,16 @@ public class User extends BusinessModel {
public
String
toString
()
{
return
"User id="
+
id
+
" email="
+
email
;
}
public
String
getUuid
()
{
return
uuid
;
}
public
void
setUuid
(
String
uuid
)
{
this
.
uuid
=
uuid
;
}
public
void
setSystemAccount
(
boolean
systemAccount
)
{
this
.
systemAccount
=
systemAccount
;
...
...
src/main/java/org/genesys2/server/persistence/domain/UserPersistence.java
View file @
879eadf5
...
...
@@ -30,4 +30,7 @@ public interface UserPersistence extends JpaRepository<User, Long> {
@Query
(
"select u from User u where u.email = ?1 and u.systemAccount = true"
)
User
findSystemUser
(
String
username
);
@Query
(
"select u from User u where u.uuid = ?1 and u.systemAccount = false"
)
User
findByUuid
(
String
uuid
);
}
src/main/java/org/genesys2/server/service/UserService.java
View file @
879eadf5
...
...
@@ -45,6 +45,8 @@ public interface UserService {
User
getUserByEmail
(
String
email
);
User
getUserByUuid
(
String
uuid
);
User
getUserById
(
long
userId
)
throws
UserException
;
boolean
exists
(
String
username
)
throws
UserException
;
...
...
@@ -58,4 +60,5 @@ public interface UserService {
User
getSystemUser
(
String
string
);
}
src/main/java/org/genesys2/server/service/impl/AclAssignerServiceImpl.java
View file @
879eadf5
...
...
@@ -83,7 +83,7 @@ public class AclAssignerServiceImpl implements AclAssignerService {
return
;
}
String
uuid
=
authUser
.
getUser
().
get
Id
().
toString
();
String
uuid
=
authUser
.
getUser
().
get
Uuid
();
// it's ok if it is null
// it can be pre-authorized Admin
...
...
src/main/java/org/genesys2/server/service/impl/AuthUserDetailsService.java
View file @
879eadf5
...
...
@@ -47,7 +47,7 @@ public class AuthUserDetailsService implements UserDetailsService {
return
null
;
}
AuthUserDetails
userDetails
=
new
AuthUserDetails
(
email
,
user
.
getPassword
(),
getGrantedAuthorities
(
user
));
AuthUserDetails
userDetails
=
new
AuthUserDetails
(
user
.
getUuid
()
,
user
.
getPassword
(),
getGrantedAuthorities
(
user
));
// set actual DB user for possible further purposes
userDetails
.
setUser
(
user
);
...
...
src/main/java/org/genesys2/server/service/impl/UserServiceImpl.java
View file @
879eadf5
...
...
@@ -227,6 +227,18 @@ public class UserServiceImpl implements UserService {
user
.
getRoles
().
size
();
return
user
;
}
@Override
public
User
getUserByUuid
(
String
uuid
)
{
User
user
=
userPersistence
.
findByUuid
(
uuid
);
if
(
user
==
null
)
{
throw
new
UsernameNotFoundException
(
uuid
);
}
user
.
getRoles
().
size
();
return
user
;
}
@Override
public
User
getSystemUser
(
String
username
)
{
...
...
@@ -247,7 +259,7 @@ public class UserServiceImpl implements UserService {
throw
new
UserException
(
e
);
}
}
@Override
public
boolean
exists
(
String
username
)
throws
UserException
{
return
userPersistence
.
findByEmail
(
username
)
!=
null
;
...
...
src/main/java/org/genesys2/server/servlet/controller/UserProfileController.java
View file @
879eadf5
...
...
@@ -68,9 +68,9 @@ public class UserProfileController extends BaseController {
return
"redirect:/profile/"
+
user
.
getEmail
();
}
@RequestMapping
(
"/{
email
:.+}"
)
public
String
someProfile
(
ModelMap
model
,
@PathVariable
(
"
email
"
)
String
email
)
{
User
user
=
userService
.
getUserBy
Email
(
email
);
@RequestMapping
(
"/{
uuid
:.+}"
)
public
String
someProfile
(
ModelMap
model
,
@PathVariable
(
"
uuid
"
)
String
uuid
)
{
User
user
=
userService
.
getUserBy
Uuid
(
uuid
);
if
(
user
==
null
)
{
throw
new
ResourceNotFoundException
();
}
...
...
@@ -81,11 +81,10 @@ public class UserProfileController extends BaseController {
return
"/user/profile"
;
}
@RequestMapping
(
"/{
email
:.+}/edit"
)
@RequestMapping
(
"/{
uuid
:.+}/edit"
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR') || principal.user.email == #email"
)
public
String
edit
(
ModelMap
model
,
@PathVariable
(
"email"
)
String
email
)
{
System
.
err
.
println
(
"email="
+
email
);
someProfile
(
model
,
email
);
public
String
edit
(
ModelMap
model
,
@PathVariable
(
"uuid"
)
String
uuid
)
{
someProfile
(
model
,
uuid
);
return
"/user/edit"
;
}
...
...
src/main/resources/log4j.properties
View file @
879eadf5
...
...
@@ -28,3 +28,6 @@ log4j.rootLogger=info, stdout
#log4j.category.org.hibernate.search=debug
log4j.category.org.apache.tomcat.jdbc.pool
=
debug
log4j.category.org.springframework.security.oauth2
=
trace
#log4j.category.org.springframework.security.access=trace
#log4j.category.org.springframework.security.acl=trace
#log4j.category.org.springframework.expression=trace
src/main/webapp/WEB-INF/decorator/header.jsp
View file @
879eadf5
...
...
@@ -53,7 +53,7 @@
</security:authorize>
<security:authorize
access=
"isAuthenticated()"
>
<ul
class=
"nav"
>
<li
class=
"dropdown"
><a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
title=
"
<spring:message
code=
"locale.language.change"
/>
"
><spring:message
code=
"user.pulldown.heading"
arguments=
"
${
user
.
username
}
"
/>
<b
class=
"caret"
></b>
<li
class=
"dropdown"
><a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
title=
"
<spring:message
code=
"locale.language.change"
/>
"
><spring:message
code=
"user.pulldown.heading"
arguments=
"
${
user
.
user
.
name
}
"
/>
<b
class=
"caret"
></b>
</a>
<ul
class=
"dropdown-menu"
>
<security:authorize
access=
"hasRole('ADMINISTRATOR')"
>
...
...
Write
Preview
Supports
Markdown
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