File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
src/main/java/com/accolite/pru/health/AuthApp Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1111import com .accolite .pru .health .AuthApp .exception .TokenRefreshException ;
1212import com .accolite .pru .health .AuthApp .exception .UpdatePasswordException ;
1313import com .accolite .pru .health .AuthApp .exception .UserLoginException ;
14+ import com .accolite .pru .health .AuthApp .exception .UserLogoutException ;
1415import com .accolite .pru .health .AuthApp .exception .UserRegistrationException ;
1516import com .accolite .pru .health .AuthApp .model .payload .ApiResponse ;
1617import org .apache .log4j .Logger ;
@@ -216,4 +217,14 @@ public ApiResponse handleTokenRefreshException(TokenRefreshException ex) {
216217 return apiResponse ;
217218 }
218219
220+ @ ExceptionHandler (value = UserLogoutException .class )
221+ @ ResponseStatus (HttpStatus .EXPECTATION_FAILED )
222+ @ ResponseBody
223+ public ApiResponse handleUserLogoutException (UserLogoutException ex ) {
224+ ApiResponse apiResponse = new ApiResponse ();
225+ apiResponse .setSuccess (false );
226+ apiResponse .setData (ex .getMessage ());
227+ return apiResponse ;
228+ }
229+
219230}
Original file line number Diff line number Diff line change 1+ package com .accolite .pru .health .AuthApp .exception ;
2+
3+ import org .springframework .http .HttpStatus ;
4+ import org .springframework .web .bind .annotation .ResponseStatus ;
5+
6+ @ ResponseStatus (HttpStatus .EXPECTATION_FAILED )
7+ public class UserLogoutException extends RuntimeException {
8+
9+ private String user ;
10+ private String message ;
11+
12+ public UserLogoutException (String user , String message ) {
13+ super (String .format ("Couldn't log out device [%s]: [%s])" , user , message ));
14+ this .user = user ;
15+ this .message = message ;
16+ }
17+ }
Original file line number Diff line number Diff line change 11package com .accolite .pru .health .AuthApp .service ;
22
3+ import com .accolite .pru .health .AuthApp .exception .UserLogoutException ;
34import com .accolite .pru .health .AuthApp .model .CustomUserDetails ;
45import com .accolite .pru .health .AuthApp .model .Role ;
56import com .accolite .pru .health .AuthApp .model .RoleName ;
@@ -125,6 +126,8 @@ private Set<Role> getRolesForNewUser(Boolean isAdmin) {
125126 public void logoutUser (CustomUserDetails customUserDetails , LogOutRequest logOutRequest ) {
126127 String deviceId = logOutRequest .getDeviceInfo ().getDeviceId ();
127128 Optional <UserDevice > userDeviceOpt = userDeviceService .findByDeviceId (deviceId );
129+ userDeviceOpt .orElseThrow (() -> new UserLogoutException (logOutRequest .getDeviceInfo ().getDeviceId (), "" +
130+ "Invalid device Id supplied. No matching user device found" ));
128131 logger .info ("Removing refresh token associated with device [" + userDeviceOpt + "]" );
129132 userDeviceOpt .map (UserDevice ::getRefreshToken )
130133 .map (RefreshToken ::getId )
You can’t perform that action at this time.
0 commit comments