forked from alfio-event/alf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retrieve user details from claim, add /me endpoint
- Loading branch information
Showing
4 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
src/main/java/alfio/config/authentication/support/OpenIdPublicCallbackLoginFilter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package alfio.controller.api.v2.model; | ||
|
||
public class User { | ||
private final String firstName; | ||
private final String lastName; | ||
private final String emailAddress; | ||
|
||
public User(String firstName, String lastName, String emailAddress) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.emailAddress = emailAddress; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public String getEmailAddress() { | ||
return emailAddress; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/alfio/controller/api/v2/user/UserApiV2Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package alfio.controller.api.v2.user; | ||
|
||
import alfio.controller.api.v2.model.User; | ||
import alfio.manager.user.UserManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v2/public/user") | ||
@RequiredArgsConstructor | ||
public class UserApiV2Controller { | ||
|
||
private final UserManager userManager; | ||
|
||
@GetMapping("/me") | ||
public ResponseEntity<User> getUserIdentity(Authentication authentication) { | ||
if(authentication != null) { | ||
return userManager.findOptionalEnabledUserByUsername(authentication.getName()) | ||
.map(u -> ResponseEntity.ok(new User(u.getFirstName(), u.getLastName(), u.getEmailAddress()))) | ||
.orElseGet(() -> ResponseEntity.status(HttpStatus.NO_CONTENT).build()); | ||
} | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters