Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
userManagement
Commits
4e5edcde
Commit
4e5edcde
authored
1 year ago
by
shishir suman
Browse files
Options
Download
Patches
Plain Diff
code changes for logout
parent
4a389fef
uat
UPHRH_8164_ErrorHandling
dev
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
src/main/java/com/tarento/upsmf/userManagement/controller/UserController.java
+9
-0
...rento/upsmf/userManagement/controller/UserController.java
src/main/java/com/tarento/upsmf/userManagement/exception/LogoutFailedException.java
+21
-0
...upsmf/userManagement/exception/LogoutFailedException.java
src/main/java/com/tarento/upsmf/userManagement/handler/UserHandler.java
+4
-0
...com/tarento/upsmf/userManagement/handler/UserHandler.java
src/main/java/com/tarento/upsmf/userManagement/services/UserService.java
+3
-0
...om/tarento/upsmf/userManagement/services/UserService.java
src/main/java/com/tarento/upsmf/userManagement/utility/ErrorCode.java
+1
-0
...a/com/tarento/upsmf/userManagement/utility/ErrorCode.java
src/main/java/com/tarento/upsmf/userManagement/utility/KeycloakUserCredentialPersister.java
+32
-1
...erManagement/utility/KeycloakUserCredentialPersister.java
src/main/resources/application.properties
+2
-0
src/main/resources/application.properties
with
72 additions
and
1 deletion
+72
-1
src/main/java/com/tarento/upsmf/userManagement/controller/UserController.java
+
9
−
0
View file @
4e5edcde
...
...
@@ -124,4 +124,13 @@ public class UserController {
public
ResponseEntity
<
String
>
getUserByAttribute
(
@RequestBody
JsonNode
body
)
throws
SQLException
,
IOException
,
URISyntaxException
{
return
userHandler
.
getUserByAttribute
(
body
);
}
@GetMapping
(
value
=
"/{userId}/logout"
,
produces
=
"application/json"
)
public
ResponseEntity
<?>
logout
(
@PathVariable
String
userId
)
{
try
{
return
userHandler
.
logout
(
userId
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Error in terminating session"
);
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/exception/LogoutFailedException.java
0 → 100644
+
21
−
0
View file @
4e5edcde
package
com.tarento.upsmf.userManagement.exception
;
import
com.tarento.upsmf.userManagement.utility.ErrorCode
;
public
class
LogoutFailedException
extends
CustomException
{
public
LogoutFailedException
(
String
message
)
{
super
(
message
);
}
public
LogoutFailedException
(
String
message
,
String
description
)
{
super
(
message
,
description
);
}
public
LogoutFailedException
(
String
message
,
ErrorCode
errorCode
)
{
super
(
message
,
errorCode
);
}
public
LogoutFailedException
(
String
message
,
ErrorCode
errorCode
,
String
description
)
{
super
(
message
,
errorCode
,
description
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/handler/UserHandler.java
+
4
−
0
View file @
4e5edcde
...
...
@@ -196,4 +196,8 @@ public class UserHandler {
public
ResponseEntity
<
String
>
getUserByAttribute
(
JsonNode
body
)
throws
SQLException
,
IOException
,
URISyntaxException
{
return
userService
.
getUserListByAttribute
(
body
);
}
public
ResponseEntity
<
String
>
logout
(
String
userId
)
throws
IOException
{
return
userService
.
logout
(
userId
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/services/UserService.java
+
3
−
0
View file @
4e5edcde
...
...
@@ -294,4 +294,7 @@ public class UserService {
return
result
;
}
public
ResponseEntity
<
String
>
logout
(
String
userId
)
throws
IOException
{
return
keycloakUserCredentialPersister
.
usrLogout
(
userId
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/utility/ErrorCode.java
+
1
−
0
View file @
4e5edcde
...
...
@@ -9,6 +9,7 @@ public enum ErrorCode {
RC_UM_101
(
"Token Inaccessibility - RC User Management"
),
RC_UM_201
(
"Invalid OTP - RC User Management"
),
RC_UM_301
(
"Login failed - RC User Management"
),
RC_UM_302
(
"Error in terminating user session"
),
RC_UM_0
(
"Undefined - RC User Management"
),
CE_UM_001
(
"User creation failed - Central User Management"
),
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/utility/KeycloakUserCredentialPersister.java
+
32
−
1
View file @
4e5edcde
...
...
@@ -2,8 +2,10 @@ package com.tarento.upsmf.userManagement.utility;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.tarento.upsmf.userManagement.exception.LoginFailedException
;
import
com.tarento.upsmf.userManagement.exception.LogoutFailedException
;
import
org.apache.http.HttpHeaders
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.HttpClients
;
...
...
@@ -13,11 +15,11 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.core.env.Environment
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.io.IOException
;
import
java.util.UUID
;
@Component
@PropertySource
({
"classpath:application.properties"
})
...
...
@@ -44,6 +46,8 @@ public class KeycloakUserCredentialPersister {
private
String
USER_LOGIN
;
private
String
USER_LOGOUT
;
@PostConstruct
public
void
init
(){
environment
=
env
;
...
...
@@ -51,6 +55,7 @@ public class KeycloakUserCredentialPersister {
OTP_MAIL_ENDPOINT
=
getPropertyValue
(
"otp.mail.endpoint"
);
USER_CREATE_MAIL_ENDPOINT
=
getPropertyValue
(
"user.create.mail.endpoint"
);
USER_LOGIN
=
getPropertyValue
(
"user.login"
);
USER_LOGOUT
=
getPropertyValue
(
"user.logout"
);
}
public
static
String
getPropertyValue
(
String
property
){
...
...
@@ -146,4 +151,30 @@ public class KeycloakUserCredentialPersister {
}
}
public
ResponseEntity
<
String
>
usrLogout
(
String
userId
)
{
try
{
logger
.
info
(
"login user endpoint {}. "
,
USER_LOGIN
);
HttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
USER_LOGOUT
.
concat
(
"/"
).
concat
(
userId
));
JsonNode
adminToken
=
sunbirdRCKeycloakTokenRetriever
.
getAdminToken
();
String
authToken
=
adminToken
.
get
(
"access_token"
).
asText
();
httpGet
.
setHeader
(
HttpHeaders
.
CONTENT_TYPE
,
"application/json"
);
httpGet
.
setHeader
(
HttpHeaders
.
AUTHORIZATION
,
"Bearer "
+
authToken
);
logger
.
info
(
"payload logout user with header {}"
,
httpGet
);
org
.
apache
.
http
.
HttpResponse
response
=
httpClient
.
execute
(
httpGet
);
logger
.
info
(
"Response from server {}"
,
response
);
String
responseBody
=
EntityUtils
.
toString
(
response
.
getEntity
());
if
(
response
.
getStatusLine
().
getStatusCode
()
==
500
)
{
logger
.
error
(
"Error while trying to logout in RC User Management -- code -- 500"
);
throw
new
LogoutFailedException
(
"Error in terminating session"
,
ErrorCode
.
RC_UM_302
,
responseBody
);
}
return
ResponseEntity
.
ok
(
responseBody
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Error while terminating session"
);
throw
new
LogoutFailedException
(
"Error while terminating session"
,
ErrorCode
.
RC_UM_302
,
e
.
getMessage
());
}
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
+
2
−
0
View file @
4e5edcde
...
...
@@ -35,4 +35,6 @@ spring.jpa.hibernate.ddl-auto=none
otp.mail.endpoint
=
/api/v1/keycloak/mail/sendOTP
user.create.mail.endpoint
=
/api/v1/keycloak/mail/userCreate
user.login
=
/api/v1/login
user.logout
=
/api/v1/logout
aes_key_for_payment_success
=
XXXXXXXXXXXXXXXXX
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets