org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken Java Examples

The following examples show how to use org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken. 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: CustomAuthenticationManager.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
    return Mono.justOrEmpty(authentication)
            .filter(a -> a instanceof BearerTokenAuthenticationToken)
            .cast(BearerTokenAuthenticationToken.class)
            .map(BearerTokenAuthenticationToken::getToken)
            .flatMap((accessTokenValue -> {
                OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue);
                if (accessToken == null) {
                    return Mono.error(new InvalidTokenException("Invalid access token: " + accessTokenValue));
                } else if (accessToken.isExpired()) {
                    tokenStore.removeAccessToken(accessToken);
                    return Mono.error(new InvalidTokenException("Access token expired: " + accessTokenValue));
                }

                OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
                if (result == null) {
                    return Mono.error(new InvalidTokenException("Invalid access token: " + accessTokenValue));
                }
                return Mono.just(result);
            }))
            .cast(Authentication.class);
}
 
Example #2
Source File: RedisAuthenticationManager.java    From open-cloud with MIT License 6 votes vote down vote up
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
    return Mono.justOrEmpty(authentication)
            .filter(a -> a instanceof BearerTokenAuthenticationToken)
            .cast(BearerTokenAuthenticationToken.class)
            .map(BearerTokenAuthenticationToken::getToken)
            .flatMap((token -> {
                OAuth2Authentication oAuth2Authentication = this.tokenStore.readAuthentication(token);
                if(oAuth2Authentication==null){
                    return Mono.error(new InvalidTokenException(ErrorCode.INVALID_TOKEN.getMessage()));
                }else{
                    return Mono.just(oAuth2Authentication);
                }
            }))
            .cast(Authentication.class);
}
 
Example #3
Source File: SecurityConfiguration.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@Bean
// Configure which authentication types you support.
GrpcAuthenticationReader authenticationReader() {
    return new BearerAuthenticationReader(accessToken -> new BearerTokenAuthenticationToken(accessToken));
}
 
Example #4
Source File: SecurityConfiguration.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@Bean
// Configure which authentication types you support.
GrpcAuthenticationReader authenticationReader() {
    return new BearerAuthenticationReader(accessToken -> new BearerTokenAuthenticationToken(accessToken));
}
 
Example #5
Source File: SecurityConfig.java    From feast with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an AuthenticationReader that the AuthenticationManager will use to authenticate
 * requests
 *
 * @return GrpcAuthenticationReader
 */
@Bean
@ConditionalOnProperty(prefix = "feast.security.authentication", name = "enabled")
GrpcAuthenticationReader authenticationReader() {
  return new BearerAuthenticationReader(BearerTokenAuthenticationToken::new);
}