Usando Java 8 y Spring Boot 1.5.2
Spring Security: estoy tratando de almacenar tokens en la base de datos de Cassandra. Para lograr esto he implementado TokenStore. getAccessToken(...) antes storeAccessToken(...) y debido a este token siempre es nulo. ¿Qué debo hacer para almacenar primero el token de acceso en la base de datos y luego consultarlo?
@Override public OAuth2AccessToken getAccessToken(final OAuth2Authentication authentication) { OAuth2AccessToken accessToken = null; final String key = authenticationKeyGenerator.extractKey(authentication); final Select select = QueryBuilder.select("token_body").from("authentication_service", "oauth_access_token"); select.where(QueryBuilder.eq("authentication_id", key)); final ByteBuffer token = cassandraOperations.queryForObject(select, ByteBuffer.class); if (token != null) { accessToken = deserializeAccessToken(token.array()); if (accessToken != null && !key.equals(authenticationKeyGenerator.extractKey(readAuthentication(accessToken.getValue())))) { removeAccessToken(accessToken.getValue()); storeAccessToken(accessToken, authentication); } } return accessToken; }storeAccessToken(...)
@Override public void storeAccessToken(final OAuth2AccessToken token, final OAuth2Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue()) != null) { removeAccessToken(token.getValue()); } final AccessTokenBuilder accessTokenBuilder = new AccessTokenBuilder(); accessTokenRepository.save(accessTokenBuilder .authenticationId(authenticationKeyGenerator.extractKey(authentication)) .tokenId(extractTokenKey(token.getValue())) .tokenBody(ByteBuffer.wrap(serializeAccessToken(token))) .username(authentication.getName()) .clientId(authentication.getOAuth2Request().getClientId()) .authentication(ByteBuffer.wrap(serializeAuthentication(authentication))) .refreshTokenId(extractTokenKey(refreshToken)) .createAccessToken()); }