当前位置: 首页>>代码示例>>Java>>正文


Java OAuth2AccessToken.getValue方法代码示例

本文整理汇总了Java中org.springframework.security.oauth2.common.OAuth2AccessToken.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AccessToken.getValue方法的具体用法?Java OAuth2AccessToken.getValue怎么用?Java OAuth2AccessToken.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.oauth2.common.OAuth2AccessToken的用法示例。


在下文中一共展示了OAuth2AccessToken.getValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: acquireAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
protected OAuth2AccessToken acquireAccessToken(OAuth2ProtectedResourceDetails resource)
		throws UserRedirectRequiredException {
	AccessTokenRequest tokenRequest = oAuth2ClientContext.getAccessTokenRequest();
	if (tokenRequest == null) {
		throw new AccessTokenRequiredException(
				"Cannot find valid context on request for resource '" + resource.getId() + "'.", resource);
	}
	String stateKey = tokenRequest.getStateKey();
	if (stateKey != null) {
		tokenRequest.setPreservedState(oAuth2ClientContext.removePreservedState(stateKey));
	}
	OAuth2AccessToken existingToken = oAuth2ClientContext.getAccessToken();
	if (existingToken != null) {
		oAuth2ClientContext.setAccessToken(existingToken);
	}
	OAuth2AccessToken obtainableAccessToken;
	obtainableAccessToken = accessTokenProvider.obtainAccessToken(resource, tokenRequest);
	if (obtainableAccessToken == null || obtainableAccessToken.getValue() == null) {
		throw new IllegalStateException(
				" Access token provider returned a null token, which is illegal according to the contract.");
	}
	oAuth2ClientContext.setAccessToken(obtainableAccessToken);
	return obtainableAccessToken;
}
 
开发者ID:rhawan,项目名称:microservices-tcc-alfa,代码行数:25,代码来源:FeignOAuthInterceptor.java

示例2: testAccessRootUrlWithOAuth2AccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Test
public void testAccessRootUrlWithOAuth2AccessToken() throws Exception {

	final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
	resourceDetails.setClientId("myclient");
	resourceDetails.setClientSecret("mysecret");
	resourceDetails.setGrantType("client_credentials");
	resourceDetails
			.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");

	final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
	final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();

	final String accessTokenAsString = accessToken.getValue();

	localSkipperResource.getMockMvc().perform(get("/api").header("Authorization", "bearer " + accessTokenAsString))
			.andDo(print()).andExpect(status().isOk());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:19,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例3: testAccessAboutUrlWithOAuth2AccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Test
public void testAccessAboutUrlWithOAuth2AccessToken() throws Exception {

	final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
	resourceDetails.setClientId("myclient");
	resourceDetails.setClientSecret("mysecret");
	resourceDetails.setGrantType("client_credentials");
	resourceDetails
			.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");

	final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
	final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();

	final String accessTokenAsString = accessToken.getValue();

	localSkipperResource.getMockMvc()
			.perform(get("/api/about").header("Authorization", "bearer " + accessTokenAsString)).andDo(print())
			.andExpect(status().isOk())
			.andExpect(jsonPath("$.versionInfo.server.name", is("Spring Cloud Skipper Server")))
			.andExpect(jsonPath("$.versionInfo.server.version", notNullValue()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:22,代码来源:LocalServerSecurityWithOAuth2Tests.java

示例4: getUserInfo

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
private Map<String, Object> getUserInfo(String user) {
    // String userJson = getRestTemplate().getForObject(getUrl("/v2/users/{guid}"), String.class, user);
    // Map<String, Object> userInfo = (Map<String, Object>) JsonUtil.convertJsonToMap(userJson);
    // return userInfo();
    // TODO: remove this temporary hack once the /v2/users/ uri can be accessed by mere mortals
    String userJson = "{}";
    OAuth2AccessToken accessToken = oauthClient.getToken();
    if (accessToken != null) {
        String tokenString = accessToken.getValue();
        int x = tokenString.indexOf('.');
        int y = tokenString.indexOf('.', x + 1);
        String encodedString = tokenString.substring(x + 1, y);
        try {
            byte[] decodedBytes = new sun.misc.BASE64Decoder().decodeBuffer(encodedString);
            userJson = new String(decodedBytes, 0, decodedBytes.length, "UTF-8");
        } catch (IOException e) {
        }
    }
    return (JsonUtil.convertJsonToMap(userJson));
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:22,代码来源:CloudControllerClientImpl.java

示例5: createToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
private String createToken(Authentication userAuth) {
    OAuth2Request storedOAuth2Request = new OAuth2Request(null, "web_app", null, true, Sets.newHashSet("openid"),
        null, null, null, null);
    OAuth2Authentication oauth2 = new OAuth2Authentication(storedOAuth2Request, userAuth);
    OAuth2AccessToken oauthToken = tokenServices.createAccessToken(oauth2);
    return oauthToken.getValue();
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:8,代码来源:CustomSignInAdapter.java

示例6: getAuthorizationHeader

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
public String getAuthorizationHeader() {
    OAuth2AccessToken accessToken = getToken();
    if (accessToken != null) {
        return accessToken.getTokenType() + " " + accessToken.getValue();
    }
    return null;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:8,代码来源:OauthClient.java

示例7: AuthenticationAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
/**
 * Create a new OAuth2 Access Token holder.
 *
 * @param accessToken      The Access Token.
 * @param authentication   The authentication.
 * @param authenticationId The id of the authentication.
 */
public AuthenticationAccessToken(final OAuth2AccessToken accessToken,
                                 final OAuth2Authentication authentication,
                                 final String authenticationId) {
    this.tokenId = accessToken.getValue();
    this.accessToken = accessToken;
    this.authenticationId = authenticationId;
    this.userName = authentication.getName();
    this.clientId = authentication.getOAuth2Request().getClientId();
    this.authentication = authentication;
    this.refreshToken = accessToken.getRefreshToken().getValue();
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:19,代码来源:AuthenticationAccessToken.java

示例8: saveAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public void saveAccessToken(OAuth2ProtectedResourceDetails resource,
        Authentication authentication, OAuth2AccessToken accessToken) {
    ClientUser clientUser = getClientUser(authentication);

    clientUser.accessToken = accessToken.getValue();
    clientUser.expirationTime = accessToken.getExpiration().getTime();
    clientUser.additionalInformation = accessToken.getAdditionalInformation();

    users.put(clientUser.username, clientUser);
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:12,代码来源:OAuth2ClientTokenSevices.java

示例9: acquireAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
protected OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context) throws UserRedirectRequiredException {
    AccessTokenRequest accessTokenRequest = oauth2Context.getAccessTokenRequest();
    if (accessTokenRequest != null) {
        System.out.println("accesstokeRequest == " + accessTokenRequest.getCurrentUri());
    }
    if(accessTokenRequest == null) {
        throw new AccessTokenRequiredException("No OAuth 2 security context has been established. Unable to access resource '" + this.resource.getId() + "'.", this.resource);
    } else {
        String stateKey = accessTokenRequest.getStateKey();
        if(stateKey != null) {
            System.out.println("stateKey == " + stateKey);
            accessTokenRequest.setPreservedState(oauth2Context.removePreservedState(stateKey));
        }

        OAuth2AccessToken existingToken = oauth2Context.getAccessToken();
        if(existingToken != null) {
            accessTokenRequest.setExistingToken(existingToken);
        }

        OAuth2AccessToken accessToken = null;
        accessToken = this.accessTokenProvider.obtainAccessToken(this.resource, accessTokenRequest);
        if(accessToken != null && accessToken.getValue() != null) {
            oauth2Context.setAccessToken(accessToken);
            return accessToken;
        } else {
            throw new IllegalStateException("Access token provider returned a null access token, which is illegal according to the contract.");
        }
    }
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:30,代码来源:MyOAuth2RestTemplate.java

示例10: storeAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {

    String tokenId = token.getValue();

    final RefreshTokenEntity refreshToken;
    String authenticationKey = authenticationKeyGenerator.extractKey(authentication);

    if (token.getRefreshToken() != null) {
        refreshToken = refreshTokenRepository.findOneByTokenId(token.getRefreshToken().getValue()).orElseGet(() -> refreshTokenRepository.save(RefreshTokenEntity.builder().tokenId(token.getRefreshToken().getValue()).token(token.getRefreshToken()).authentication(authentication).build()));
    } else {
        refreshToken = null;
    }

    accessTokenRepository.findOneByAuthenticationId(authenticationKey).ifPresent(accessTokenEntity -> {
        if (!tokenId.equals(accessTokenEntity.getTokenId())) {
            accessTokenRepository.delete(accessTokenEntity);
        }
    });

    AccessTokenEntity entityToSave = accessTokenRepository.findOneByTokenId(tokenId).map(accessTokenEntity -> {
        accessTokenEntity.setToken(token);
        accessTokenEntity.setAuthenticationId(authenticationKey);
        accessTokenEntity.setAuthentication(authentication);
        accessTokenEntity.setUserName(authentication.isClientOnly() ? null : authentication.getName());
        accessTokenEntity.setClientId(authentication.getOAuth2Request().getClientId());
        accessTokenEntity.setRefreshToken(refreshToken);
        return accessTokenEntity;
    }).orElseGet(() -> AccessTokenEntity.builder().tokenId(tokenId).token(token).authenticationId(authenticationKey).authentication(authentication).userName(authentication.isClientOnly() ? null : authentication.getName()).clientId(authentication.getOAuth2Request().getClientId()).refreshToken(refreshToken).build());

    accessTokenRepository.save(entityToSave);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:33,代码来源:DatabaseTokenStoreService.java

示例11: prepareRemoveAccessTokenStatements

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
private List<RegularStatement> prepareRemoveAccessTokenStatements(OAuth2AccessToken token) {
  //String tokenId = token.getValue();
  String tokenValue = token.getValue();
  String jsonOAuth2AccessToken = OAuthUtil.serializeOAuth2AccessToken(token);
  List<RegularStatement> statementList = new ArrayList<RegularStatement>();
  
  // Delete from AccessToken table
  RegularStatement accessTokenDelete = prepareDeleteByPrimaryKeyRegularStatement(AccessToken.class, tokenValue);
  statementList.add(accessTokenDelete);

  // Lookup Authentication table for further deleting from AuthenticationToAccessToken table
  Authentication authentication = authenticationRepository.findOne(tokenValue);
  if (authentication != null) {
    ByteBuffer bufferedOAuth2Authentication = authentication.getoAuth2Authentication();
    byte[] serializedOAuth2Authentication = new byte[bufferedOAuth2Authentication.remaining()];
    bufferedOAuth2Authentication.get(serializedOAuth2Authentication);
    OAuth2Authentication oAuth2Authentication = SerializationUtils.deserialize(serializedOAuth2Authentication);
    String clientId = oAuth2Authentication.getOAuth2Request().getClientId();

    // Delete from Authentication table
    RegularStatement authenticationDelete = prepareDeleteByPrimaryKeyRegularStatement(Authentication.class, tokenValue);
    statementList.add(authenticationDelete);

    // Delete from AuthenticationToAccessToken table
    RegularStatement authToAccessDelete = prepareDeleteByPrimaryKeyRegularStatement(AuthenticationToAccessToken.class, authenticationKeyGenerator.extractKey(oAuth2Authentication));
    statementList.add(authToAccessDelete);

    // Delete from UsernameToAccessToken table
    Optional<UsernameToAccessToken> optionalUsernameToAccessToken = usernameToAccessTokenRepository.findByKeyAndOAuth2AccessToken(OAuthUtil.getApprovalKey(clientId, oAuth2Authentication.getName()), jsonOAuth2AccessToken);
    optionalUsernameToAccessToken.ifPresent(usernameToAccessToken -> {
      Delete usernameToAccessDelete = CassandraTemplate.createDeleteQuery(UsernameToAccessToken.TABLE, usernameToAccessToken, null, cassandraTemplate.getConverter());
      statementList.add(usernameToAccessDelete);
    });

    // Delete from ClientIdToAccessToken table
    Optional<ClientIdToAccessToken> optionalClientIdToAccessToken = clientIdToAccessTokenRepository.findByKeyAndOAuth2AccessToken(clientId, jsonOAuth2AccessToken);
    optionalClientIdToAccessToken.ifPresent(clientIdToAccessToken -> {
      Delete clientIdToAccessDelete = CassandraTemplate.createDeleteQuery(ClientIdToAccessToken.TABLE, clientIdToAccessToken, null, cassandraTemplate.getConverter());
      statementList.add(clientIdToAccessDelete);
    });
  }

  return statementList;
}
 
开发者ID:Mert-Z,项目名称:spring-oauth2-cassandra-token-store,代码行数:45,代码来源:CassandraTokenStore.java


注:本文中的org.springframework.security.oauth2.common.OAuth2AccessToken.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。