-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1005 from pascalgrimaud/oauth2-account-context
OAuth2: add account context
- Loading branch information
Showing
45 changed files
with
1,090 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
20 changes: 20 additions & 0 deletions
20
...r/server/springboot/mvc/security/oauth2/src/account/domain/AccountConstants.java.mustache
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,20 @@ | ||
package {{packageName}}.account.domain; | ||
|
||
public class AccountConstants { | ||
public static final String DEFAULT_LANGUAGE = "en"; | ||
public static final String SUB = "sub"; | ||
public static final String UID = "uid"; | ||
public static final String PREFERRED_USERNAME = "preferred_username"; | ||
public static final String FAMILY_NAME = "family_name"; | ||
public static final String EMAIL_VERIFIED = "email_verified"; | ||
public static final String EMAIL = "email"; | ||
public static final String LANG_KEY = "langKey"; | ||
public static final String LOCALE = "locale"; | ||
public static final String PICTURE = "picture"; | ||
public static final String GIVEN_NAME = "given_name"; | ||
public static final String NAME = "name"; | ||
private AccountConstants() {} | ||
} |
46 changes: 46 additions & 0 deletions
46
...mvc/security/oauth2/src/account/infrastructure/primary/rest/AccountResource.java.mustache
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,46 @@ | ||
package {{packageName}}.account.infrastructure.primary.rest; | ||
|
||
import java.security.Principal; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import {{packageName}}.error.domain.AccountException; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
class AccountResource { | ||
private final Logger log = LoggerFactory.getLogger(AccountResource.class); | ||
/** | ||
* {@code GET /account} : get the current user. | ||
* | ||
* @param principal the current user; resolves to {@code null} if not authenticated. | ||
* @return the current user. | ||
* @throws AccountException {@code 500 (Internal Server Error)} if the user couldn't be returned. | ||
*/ | ||
@GetMapping("/account") | ||
@SuppressWarnings("unchecked") | ||
public UserDTO getAccount(Principal principal) { | ||
if (principal instanceof AbstractAuthenticationToken authenticationToken) { | ||
return UserDTO.getUserDTOFromToken(authenticationToken); | ||
} | ||
throw new AccountException("User could not be found"); | ||
} | ||
|
||
/** | ||
* {@code GET /authenticate} : check if the user is authenticated, and return its login. | ||
* | ||
* @param request the HTTP request. | ||
* @return the login if the user is authenticated. | ||
*/ | ||
@GetMapping("/authenticate") | ||
public String isAuthenticated(HttpServletRequest request) { | ||
log.debug("REST request to check if the current user is authenticated"); | ||
return request.getRemoteUser(); | ||
} | ||
} |
Oops, something went wrong.