Example usage for org.springframework.security.oauth2.common OAuth2RefreshToken getValue

List of usage examples for org.springframework.security.oauth2.common OAuth2RefreshToken getValue

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common OAuth2RefreshToken getValue.

Prototype

@JsonValue
String getValue();

Source Link

Document

The value of the token.

Usage

From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2DeserializerTests.java

private static void assertTokenEquals(OAuth2AccessToken expected, OAuth2AccessToken actual) {
    assertEquals(expected.getTokenType(), actual.getTokenType());
    assertEquals(expected.getValue(), actual.getValue());

    OAuth2RefreshToken expectedRefreshToken = expected.getRefreshToken();
    if (expectedRefreshToken == null) {
        assertNull(actual.getRefreshToken());
    } else {/*from   w ww. ja  v a 2s.  com*/
        assertEquals(expectedRefreshToken.getValue(), actual.getRefreshToken().getValue());
    }
    assertEquals(expected.getScope(), actual.getScope());
    Date expectedExpiration = expected.getExpiration();
    if (expectedExpiration == null) {
        assertNull(actual.getExpiration());
    } else {
        assertEquals(expectedExpiration.getTime(), actual.getExpiration().getTime());
    }
    assertEquals(expected.getAdditionalInformation(), actual.getAdditionalInformation());
}

From source file:com.epam.reportportal.auth.store.OAuth2MongoTokenStore.java

@Override
public void removeRefreshToken(OAuth2RefreshToken token) {
    if (null != token && null != token.getValue()) {
        oAuth2RefreshTokenRepository.delete(token.getValue());
    }//from  ww w .  j a  va2 s. c  o  m
}

From source file:com.mycompany.apps.oauth2.authentication.security.LogoutImpl.java

/**
 * ????<br>/*  w w w  . jav  a2  s  .c  om*/
 * ?????
 *
 * @param paramHttpServletRequest
 * @param paramHttpServletResponse
 * @param paramAuthentication
 * @throws IOException
 * @throws ServletException
 */
@Override
public void onLogoutSuccess(HttpServletRequest paramHttpServletRequest,
        HttpServletResponse paramHttpServletResponse, Authentication paramAuthentication)
        throws IOException, ServletException {

    String tokens = paramHttpServletRequest.getHeader("Authorization");
    String values[] = StringUtils.split(tokens, " ");
    LOG.debug("\n\ttoken type: " + values[0]);
    LOG.debug("\n\ttoken: " + values[1]);

    String accessTokenId = null;
    String refreshTokenId = null;

    if (values.length != 2) {
        return;
    }

    if (values[1] != null) {
        accessTokenId = values[1];
    } else {
        return;
    }

    // ?
    OAuth2AccessToken accessToken = tokenstore.readAccessToken(accessTokenId);
    if (accessToken != null) {

        // ???
        OAuth2RefreshToken rt = accessToken.getRefreshToken();
        refreshTokenId = rt.getValue();

        // ?
        tokenstore.removeAccessToken(values[1]);
        LOG.info("\n\tAccess Token Removed Successfully!");

    } else {
        LOG.info("\n\tAccess Token Not Exist(Not Removed)!");
    }

    // ?
    OAuth2RefreshToken refreshToken = tokenstore.readRefreshToken(refreshTokenId);
    if (refreshToken != null) {

        // ?
        tokenstore.removeRefreshToken(refreshTokenId);
        LOG.info("\n\tRefresh Token Removed Successfully!");

    } else {
        LOG.info("\n\tRefresh Token Not Exist(Not Removed)!");
    }

    paramHttpServletResponse.getOutputStream().write("\n\tYou Have Logged Out successfully.".getBytes());
}

From source file:com.epam.reportportal.auth.store.OAuth2MongoTokenStore.java

@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
    return Optional.ofNullable(oAuth2RefreshTokenRepository.findByTokenId(token.getValue()))
            .map(OAuth2RefreshTokenEntity::getoAuth2RefreshToken)
            .map(SerializationUtils::<OAuth2Authentication>deserialize).orElse(null);
}

From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java

@Override
public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    jgen.writeStartObject();// w  w  w  . j a  v a2s.c  o m
    jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue());
    jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType());
    OAuth2RefreshToken refreshToken = token.getRefreshToken();
    if (refreshToken != null) {
        jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue());
    }
    Date expiration = token.getExpiration();
    if (expiration != null) {
        long now = System.currentTimeMillis();
        jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000);
    }
    Set<String> scope = token.getScope();
    if (scope != null && !scope.isEmpty()) {
        StringBuffer scopes = new StringBuffer();
        for (String s : scope) {
            Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + "");
            scopes.append(s);
            scopes.append(" ");
        }
        jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1));
    }
    Map<String, Object> additionalInformation = token.getAdditionalInformation();
    for (String key : additionalInformation.keySet()) {
        jgen.writeObjectField(key, additionalInformation.get(key));
    }
    jgen.writeEndObject();
}

From source file:oauth2.authentication.tokens.TokenServiceImpl.java

@Override
public void removeRefreshToken(OAuth2RefreshToken token) {
    String tokenId = extractTokenKey(token.getValue());
    RefreshToken entity = refreshTokenRepository.findByTokenId(tokenId);
    if (entity != null) {
        refreshTokenRepository.delete(entity);
    }//w w  w  .  j  a  v a  2 s. com
}

From source file:oauth2.authentication.tokens.TokenServiceImpl.java

@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
    String tokenId = extractTokenKey(token.getValue());
    RefreshToken entity = refreshTokenRepository.findByTokenId(tokenId);
    if (entity == null) {
        return null;
    }/*from   ww w.j ava2s. c om*/
    return entity.getAuthentication();
}

From source file:com.epam.reportportal.auth.store.OAuth2MongoTokenStore.java

@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
    oAuth2AccessTokenRepository.delete(oAuth2AccessTokenRepository.findByRefreshToken(refreshToken.getValue()));
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(token.getValue()));
    OAuth2AuthenticationRefreshToken auth2AuthenticationRefreshToken = mongoTemplate.findOne(query,
            OAuth2AuthenticationRefreshToken.class, "oauth2_refresh_token");
    return auth2AuthenticationRefreshToken.getAuthentication();
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public void removeRefreshToken(OAuth2RefreshToken accessToken) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(accessToken.getValue()));
    OAuth2AuthenticationRefreshToken token = mongoTemplate.findOne(query,
            OAuth2AuthenticationRefreshToken.class, "oauth2_refresh_token");
    if (token != null) {
        oAuth2RefreshTokenRepository.delete(token);
    }/*from   w  w w. ja v  a2 s  .co  m*/
}