當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientDetails.getScope方法代碼示例

本文整理匯總了Java中org.springframework.security.oauth2.provider.ClientDetails.getScope方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientDetails.getScope方法的具體用法?Java ClientDetails.getScope怎麽用?Java ClientDetails.getScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.security.oauth2.provider.ClientDetails的用法示例。


在下文中一共展示了ClientDetails.getScope方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addClientDetails

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@Override
public void addClientDetails(final ClientDetails clientDetails) throws ClientAlreadyExistsException {
	final MongoClientDetails mongoClientDetails = new MongoClientDetails(clientDetails.getClientId(),
			passwordEncoder.encode(clientDetails.getClientSecret()),
			clientDetails.getScope(),
			clientDetails.getResourceIds(),
			clientDetails.getAuthorizedGrantTypes(),
			clientDetails.getRegisteredRedirectUri(),
			newArrayList(clientDetails.getAuthorities()),
			clientDetails.getAccessTokenValiditySeconds(),
			clientDetails.getRefreshTokenValiditySeconds(),
			clientDetails.getAdditionalInformation(),
			null);

	mongoClientDetailsRepository.save(mongoClientDetails);
}
 
開發者ID:cloudade,項目名稱:authorization-server-with-mongodb,代碼行數:17,代碼來源:MongoClientDetailsService.java

示例2: updateClientDetails

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@Override
public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
	final MongoClientDetails mongoClientDetails = new MongoClientDetails(clientDetails.getClientId(),
			clientDetails.getClientSecret(),
			clientDetails.getScope(),
			clientDetails.getResourceIds(),
			clientDetails.getAuthorizedGrantTypes(),
			clientDetails.getRegisteredRedirectUri(),
			newArrayList(clientDetails.getAuthorities()),
			clientDetails.getAccessTokenValiditySeconds(),
			clientDetails.getRefreshTokenValiditySeconds(),
			clientDetails.getAdditionalInformation(),
			getAutoApproveScopes(clientDetails));
	final boolean result = mongoClientDetailsRepository.update(mongoClientDetails);

	if (!result) {
		throw new NoSuchClientException("No such Client Id");
	}
}
 
開發者ID:cloudade,項目名稱:authorization-server-with-mongodb,代碼行數:20,代碼來源:MongoClientDetailsService.java

示例3: oAuth2Authentication

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
public OAuth2Authentication oAuth2Authentication(final String clientId, final String username) {
	// Look up authorities, resourceIds and scopes based on clientId
	ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
	Collection<GrantedAuthority> authorities = client.getAuthorities();
	Set<String> resourceIds = client.getResourceIds();
	Set<String> scopes = client.getScope();

	// Default values for other parameters
	Map<String, String> requestParameters = Collections.emptyMap();
	boolean approved = true;
	String redirectUrl = null;
	Set<String> responseTypes = Collections.emptySet();
	Map<String, Serializable> extensionProperties = Collections.emptyMap();

	// Create request
	OAuth2Request oAuth2Request = new OAuth2Request(requestParameters, clientId, authorities, approved, scopes, resourceIds, redirectUrl, responseTypes, extensionProperties);

	// Create OAuth2AccessToken
	UserDetails user = userDetailsService.loadUserByUsername(username);
	UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user, null, authorities);
	OAuth2Authentication auth = new OAuth2Authentication(oAuth2Request, authenticationToken);
	return auth;
}
 
開發者ID:timtebeek,項目名稱:resource-server-testing,代碼行數:24,代碼來源:OAuthHelper.java

示例4: updateDBObject

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
private void updateDBObject(DBObject dbo, ClientDetails clientDetails) {
    dbo.put(resourceIdsFieldName, clientDetails.getResourceIds());
    dbo.put(scopeFieldName, clientDetails.getScope());
    dbo.put(authorizedGrantTypesFieldName, clientDetails.getAuthorizedGrantTypes());
    dbo.put(registeredRedirectUrisFieldName, clientDetails.getRegisteredRedirectUri());
    dbo.put(authoritiesFieldName, AuthorityUtils.authorityListToSet(clientDetails.getAuthorities()));
    dbo.put(accessTokenValidityFieldName, clientDetails.getAccessTokenValiditySeconds());
    dbo.put(refreshTokenValidityFieldName, clientDetails.getRefreshTokenValiditySeconds());
    dbo.put(additionalInformationFieldName, clientDetails.getAdditionalInformation());
    Set<String> autoApprove = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            autoApprove.add(scope);
        }
    }
    dbo.put(autoApproveFieldName, autoApprove.size() == 1 ? autoApprove.iterator().next() : autoApprove);
}
 
開發者ID:cedac-software,項目名稱:spring-security-mongodb,代碼行數:18,代碼來源:MongoClientDetailsService.java

示例5: authenticateClient

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> authenticateClient() {
  JsonNode json = request().body().asJson();
  String clientId = json.findPath("clientId").textValue();
  String clientSecret = json.findPath("clientSecret").textValue();

  UsernamePasswordAuthenticationToken authRequest =
      new UsernamePasswordAuthenticationToken(clientId, clientSecret);
  clientAuthenticationManager.authenticate(authRequest);

  ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
  TokenRequest tokenRequest = new TokenRequest(Collections.emptyMap(), clientId,
      clientDetails.getScope(), "password");
  OAuth2AccessToken token = tokenGranter.grant("client_credentials", tokenRequest);

  ObjectNode result = Json.newObject();
  result.setAll(ImmutableMap.of(
      "accessToken", result.textNode(token.getValue()),
      "clientId", result.textNode(clientId),
      "expiration", result.numberNode(token.getExpiration().getTime())));
  return Promise.pure(ok(result));
}
 
開發者ID:tfeng,項目名稱:play-oauth2,代碼行數:23,代碼來源:SecurityController.java

示例6: vote

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {

		int result = ACCESS_ABSTAIN;

		if (!(authentication instanceof OAuth2Authentication)) {
			return result;
		}

		OAuth2Authentication oauth2Authentication = (OAuth2Authentication) authentication;
		OAuth2Request clientAuthentication = oauth2Authentication.getOAuth2Request();
		ClientDetails client = clientDetailsService.loadClientByClientId(clientAuthentication.getClientId());
		Set<String> scopes = clientAuthentication.getScope();
		if (oauth2Authentication.isClientOnly() && clientAuthoritiesAreScopes) {
			scopes = AuthorityUtils.authorityListToSet(clientAuthentication.getAuthorities());
		}

		for (ConfigAttribute attribute : attributes) {
			if (this.supports(attribute)) {

				result = ACCESS_GRANTED;

				for (String scope : scopes) {
					if (!client.getScope().contains(scope)) {
						result = ACCESS_DENIED;
						break;
					}
				}

				if (result == ACCESS_DENIED && throwException) {
					InsufficientScopeException failure = new InsufficientScopeException(
							"Insufficient scope for this resource", client.getScope());
					throw new AccessDeniedException(failure.getMessage(), failure);
				}

				return result;
			}
		}

		return result;
	}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:41,代碼來源:ClientScopeVoter.java

示例7: testClientDetailsFromNonPropertyFile

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@Test
public void testClientDetailsFromNonPropertyFile() {

	// valid client details NOT from property file
	ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-non-property-file");
	assertNotNull(clientDetailsService);
	assertEquals("my-client-id-non-property-file", clientDetails.getClientId());
	assertEquals("my-client-secret-non-property-file", clientDetails.getClientSecret());

	Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
	assertNotNull(grantTypes);
	assertEquals(2, grantTypes.size());
	assertTrue(grantTypes.contains("password"));
	assertTrue(grantTypes.contains("authorization_code"));

	Set<String> scopes = clientDetails.getScope();
	assertNotNull(scopes);
	assertEquals(2, scopes.size());
	assertTrue(scopes.contains("scope1"));
	assertTrue(scopes.contains("scope2"));

	Collection<GrantedAuthority> authorities = clientDetails.getAuthorities();
	assertNotNull(authorities);
	assertEquals(2, authorities.size());
	assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
	assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_ANONYMOUS"));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:28,代碼來源:ClientDetailsServiceBeanDefinitionParserTests.java

示例8: testClientDetailsFromPropertyFile

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@Test
public void testClientDetailsFromPropertyFile() {

	// valid client details from property file
	ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-property-file");
	assertNotNull(clientDetailsService);
	assertEquals("my-client-id-property-file", clientDetails.getClientId());
	assertEquals("my-client-secret-property-file", clientDetails.getClientSecret());

	Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
	assertNotNull(grantTypes);
	assertEquals(2, grantTypes.size());
	assertTrue(grantTypes.contains("password"));
	assertTrue(grantTypes.contains("authorization_code"));

	Set<String> scopes = clientDetails.getScope();
	assertNotNull(scopes);
	assertEquals(2, scopes.size());
	assertTrue(scopes.contains("scope1"));
	assertTrue(scopes.contains("scope2"));

	Collection<GrantedAuthority> authorities = clientDetails.getAuthorities();
	assertNotNull(authorities);
	assertEquals(2, authorities.size());
	assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
	assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_ANONYMOUS"));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:28,代碼來源:ClientDetailsServiceBeanDefinitionParserTests.java


注:本文中的org.springframework.security.oauth2.provider.ClientDetails.getScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。