2
2
3
3
import com .mysql .cj .core .conf .url .ConnectionUrlParser ;
4
4
import main .controllers .BaseController ;
5
+ import main .controllers .IController ;
5
6
import main .exceptions .AqualityException ;
6
7
import main .exceptions .AqualityPermissionsException ;
7
8
import main .model .db .dao .project .PasswordDao ;
24
25
import java .util .Objects ;
25
26
import java .util .UUID ;
26
27
27
- public class UserController extends BaseController <UserDto > {
28
+ public class UserController extends BaseController <UserDto > implements IController < UserDto > {
28
29
private UserDao userDao ;
29
30
private PasswordDao passwordDao ;
30
31
private UserSessionDao userSessionDao ;
@@ -38,12 +39,12 @@ public UserController(UserDto user) {
38
39
39
40
@ Override
40
41
public UserDto create (UserDto template ) throws AqualityException {
41
- if (baseUser .isAdmin () || baseUser .getId ().equals (template .getId ())){
42
- if (template .getPassword () != null ){
42
+ if (baseUser .isAdmin () || baseUser .getId ().equals (template .getId ())) {
43
+ if (template .getPassword () != null ) {
43
44
template .setPassword (saltPassword (template , template .getPassword ()));
44
45
}
45
46
return userDao .create (template );
46
- }else {
47
+ } else {
47
48
throw new AqualityPermissionsException ("Account is not allowed to create User" , baseUser );
48
49
}
49
50
}
@@ -55,9 +56,9 @@ public List<UserDto> get(UserDto template) throws AqualityException {
55
56
56
57
@ Override
57
58
public boolean delete (UserDto template ) throws AqualityException {
58
- if (baseUser .isAdmin ()){
59
+ if (baseUser .isAdmin ()) {
59
60
return userDao .delete (template );
60
- }else {
61
+ } else {
61
62
throw new AqualityPermissionsException ("Account is not allowed to delete User" , baseUser );
62
63
}
63
64
}
@@ -77,7 +78,7 @@ public UserDto updatePassword(PasswordDto password) throws AqualityException {
77
78
}
78
79
79
80
UserDto auth (String authString , boolean ldap ) throws AqualityException {
80
- Base64 base64 = new Base64 ();
81
+ Base64 base64 = new Base64 ();
81
82
String authStringDecoded = StringUtils .newStringUtf8 (base64 .decode (authString ));
82
83
String [] authStringSplit = authStringDecoded .split (":" );
83
84
ConnectionUrlParser .Pair <String , PrivateKey > privateKeyPair
@@ -94,7 +95,7 @@ UserDto auth(String authString, boolean ldap) throws AqualityException {
94
95
95
96
UserDto user = ldap ? handleLDAPAuthorization (authStringSplit [0 ], password ) : checkUser (authStringSplit [0 ], password );
96
97
97
- if (user != null ){
98
+ if (user != null ) {
98
99
user .setSession_code (generateSessionCode (user ));
99
100
updateSession (user );
100
101
return user ;
@@ -113,7 +114,7 @@ private List<UserDto> toPublicUsers(List<UserDto> users) {
113
114
}
114
115
115
116
private String generateSessionCode (UserDto user ) {
116
- Base64 base64 = new Base64 ();
117
+ Base64 base64 = new Base64 ();
117
118
DateUtils dates = new DateUtils ();
118
119
String encode = null ;
119
120
try {
@@ -124,21 +125,21 @@ private String generateSessionCode(UserDto user) {
124
125
return encode ;
125
126
}
126
127
127
- private String saltPassword (UserDto user , String password ){
128
+ private String saltPassword (UserDto user , String password ) {
128
129
String passHash = DigestUtils .md5Hex (password );
129
- return DigestUtils .md5Hex (user .getEmail ()+ passHash + "kjr1fdd00das" );
130
+ return DigestUtils .md5Hex (user .getEmail () + passHash + "kjr1fdd00das" );
130
131
}
131
132
132
133
private UserDto checkUser (String user_name , String password ) throws AqualityException {
133
134
UserDto user = new UserDto ();
134
135
user .setUser_name (user_name );
135
136
List <UserDto > users = userDao .searchAll (user );
136
137
137
- if (users .size () > 0 ){
138
+ if (users .size () > 0 ) {
138
139
user = users .get (0 );
139
140
String correctHex = user .getPassword ();
140
141
String actualHex = saltPassword (user , password );
141
- if (correctHex .equals (actualHex )){
142
+ if (correctHex .equals (actualHex )) {
142
143
return user ;
143
144
}
144
145
}
@@ -150,12 +151,12 @@ private UserDto handleLDAPAuthorization(String userName, String password) throws
150
151
LDAPAuthenticator ldap = new LDAPAuthenticator ();
151
152
UserDto user ;
152
153
user = ldap .tryAuthWithLdap (userName , password );
153
- if (user != null ){
154
+ if (user != null ) {
154
155
UserDto templateUser = new UserDto ();
155
156
templateUser .setUser_name (user .getUser_name ());
156
157
List <UserDto > users = get (templateUser );
157
158
158
- if (users .size () > 0 ){
159
+ if (users .size () > 0 ) {
159
160
user .setId (users .get (0 ).getId ());
160
161
}
161
162
0 commit comments