Java Code Examples for org.springframework.security.oauth2.provider.OAuth2Authentication#getName()

The following examples show how to use org.springframework.security.oauth2.provider.OAuth2Authentication#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoTokenStore.java    From spring-security-mongo with MIT License 6 votes vote down vote up
@Override
public void storeAccessToken(final OAuth2AccessToken token,
                             final OAuth2Authentication authentication) {
    String refreshToken = null;
    if (nonNull(token.getRefreshToken())) {
        refreshToken = token.getRefreshToken().getValue();
    }

    if (nonNull(readAccessToken(token.getValue()))) {
        removeAccessToken(token.getValue());
    }

    final String tokenKey = extractTokenKey(token.getValue());

    final MongoOAuth2AccessToken oAuth2AccessToken = new MongoOAuth2AccessToken(tokenKey,
            serializeAccessToken(token),
            authenticationKeyGenerator.extractKey(authentication),
            authentication.isClientOnly() ? null : authentication.getName(),
            authentication.getOAuth2Request().getClientId(),
            serializeAuthentication(authentication),
            extractTokenKey(refreshToken));

    mongoOAuth2AccessTokenRepository.save(oAuth2AccessToken);
}
 
Example 2
Source File: CustomTokenStore.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
    if (oauthProperties.isEnabledSingleLogin() && !authentication.isClientOnly()) {
        String key = authenticationKeyGenerator.extractKey(authentication);
        String username = authentication.getName();
        String clientId = authentication.getOAuth2Request().getClientId();
        accessTokenMapper.selectTokens(username, clientId, key);
        accessTokenMapper.deleteTokens(username, clientId, key);

    }
    return super.getAccessToken(authentication);
}
 
Example 3
Source File: _OAuth2AuthenticationAccessToken.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
@PersistenceConstructor
public OAuth2AuthenticationAccessToken(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication authentication, String authenticationId) {
    this.id = UUID.randomUUID().toString();
    this.tokenId = oAuth2AccessToken.getValue();
    this.oAuth2AccessToken = oAuth2AccessToken;
    this.authenticationId = authenticationId;
    this.userName = authentication.getName();
    this.clientId = authentication.getOAuth2Request().getClientId();
    this.authentication = authentication;
    if(oAuth2AccessToken.getRefreshToken() != null) {
        this.refreshToken = oAuth2AccessToken.getRefreshToken().getValue();
    }
}
 
Example 4
Source File: ResSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@GetMapping("/hello")
public String hello(OAuth2Authentication oauth) {
	return "hello " + oauth.getName();
}