• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BaseClientDetails类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.oauth2.provider.BaseClientDetails的典型用法代码示例。如果您正苦于以下问题:Java BaseClientDetails类的具体用法?Java BaseClientDetails怎么用?Java BaseClientDetails使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BaseClientDetails类属于org.springframework.security.oauth2.provider包,在下文中一共展示了BaseClientDetails类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: build

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
private ClientDetails build() {
	BaseClientDetails result = new BaseClientDetails();
	result.setClientId(clientId);
	result.setAuthorizedGrantTypes(authorizedGrantTypes);
	result.setAccessTokenValiditySeconds(accessTokenValiditySeconds);
	result.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds);
	result.setRegisteredRedirectUri(registeredRedirectUris);
	result.setClientSecret(secret);
	result.setScope(scopes);
	result.setAuthorities(AuthorityUtils.createAuthorityList(authorities.toArray(new String[authorities.size()])));
	result.setResourceIds(resourceIds);
	if (autoApprove) {
		result.setAutoApproveScopes(scopes);
	}
	return result;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:17,代码来源:InMemoryClientDetailsServiceConfigurer.java


示例2: testClientSpecificRefreshTokenExpiry

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testClientSpecificRefreshTokenExpiry() throws Exception {
	getTokenServices().setRefreshTokenValiditySeconds(1000);
	getTokenServices().setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId)
				throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setRefreshTokenValiditySeconds(100);
			client.setAuthorizedGrantTypes(Arrays.asList(
					"authorization_code", "refresh_token"));
			return client;
		}
	});
	OAuth2AccessToken accessToken = getTokenServices().createAccessToken(
			createAuthentication());
	DefaultExpiringOAuth2RefreshToken refreshToken = (DefaultExpiringOAuth2RefreshToken) accessToken
			.getRefreshToken();
	Date expectedExpiryDate = new Date(
			System.currentTimeMillis() + 102 * 1000L);
	assertTrue(expectedExpiryDate.after(refreshToken.getExpiration()));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:22,代码来源:AbstractTestDefaultTokenServices.java


示例3: testClientSpecificRefreshTokenExpiry

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testClientSpecificRefreshTokenExpiry() throws Exception {
	services.setRefreshTokenValiditySeconds(1000);
	services.setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setRefreshTokenValiditySeconds(100);
			client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
			return client;
		}
	});
	OAuth2AccessToken accessToken = services.createAccessToken(createAuthentication());
	DefaultExpiringOAuth2RefreshToken refreshToken = (DefaultExpiringOAuth2RefreshToken) accessToken
			.getRefreshToken();
	Date expectedExpiryDate = new Date(System.currentTimeMillis() + 102 * 1000L);
	assertTrue(expectedExpiryDate.after(refreshToken.getExpiration()));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:18,代码来源:JwtTokenServicesTests.java


示例4: testNoRefreshTokenIfNotAuthorized

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testNoRefreshTokenIfNotAuthorized() throws Exception {
	// create access token
	getTokenServices().setAccessTokenValiditySeconds(1);
	getTokenServices().setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setAccessTokenValiditySeconds(1);
			client.setAuthorizedGrantTypes(Arrays.asList("authorization_code"));
			return client;
		}
	});
	OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(null, "id", null, false, Collections.singleton("read"), null, null, null, null), new TestAuthentication("test2", false));
	DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
			expectedAuthentication);
	assertNull(token.getRefreshToken());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:18,代码来源:DefaultTokenServicesWithInMemoryTests.java


示例5: testOauthClient

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testOauthClient() throws Exception {
	AuthorizationRequest request = new AuthorizationRequest("foo",
			Collections.singleton("read"));
	request
			.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "", "", "client_credentials", "ROLE_CLIENT"));
	Authentication userAuthentication = null;
	
	OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request(request.getRequestParameters(), request.getClientId(), request.getAuthorities(), request.isApproved(), request.getScope(), request.getResourceIds(),
			request.getRedirectUri(), request.getResponseTypes(), request.getExtensions());
	
	OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
	MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
			"testOauthClient"));
	EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
	Expression expression = handler.getExpressionParser()
			.parseExpression("#oauth2.clientHasAnyRole('ROLE_CLIENT')");
	assertTrue((Boolean) expression.getValue(context));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:20,代码来源:OAuth2MethodSecurityExpressionHandlerTests.java


示例6: init

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Before
public void init() throws Exception {
	client = new BaseClientDetails();
	client.setRegisteredRedirectUri(Collections.singleton("http://anywhere.com"));
	client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "implicit"));
	endpoint.setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
			return client;
		}
	});
	endpoint.setTokenGranter(new TokenGranter() {
		public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
			return null;
		}
	});
	endpoint.setRedirectResolver(new DefaultRedirectResolver());
	endpoint.afterPropertiesSet();
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:19,代码来源:AuthorizationEndpointTests.java


示例7: loadClientByClientId

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId)
        throws OAuth2Exception {

    if (clientId.equals(id))
    {
        List<String> authorizedGrantTypes = new ArrayList<String>();
        authorizedGrantTypes.add("password");
        authorizedGrantTypes.add("refresh_token");
        authorizedGrantTypes.add("client_credentials");

        BaseClientDetails clientDetails = new BaseClientDetails();
        clientDetails.setClientId(id);
        clientDetails.setClientSecret(secretKey);
        clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes);

        return clientDetails;
    }
    else {
        throw new NoSuchClientException("No client recognized with id: "
                + clientId);
    }
}
 
开发者ID:NCIP,项目名称:national-biomedical-image-archive,代码行数:24,代码来源:ClientDetailServiceImpl.java


示例8: loadClientByClientId

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId(CLIENT_ID);
    clientDetails.setClientSecret(CLIENT_SECRET);
    clientDetails.setAuthorizedGrantTypes(Arrays.asList(GRANT_TYPES));
    return clientDetails;
}
 
开发者ID:OADA,项目名称:oada-ref-impl-java,代码行数:9,代码来源:ClientDetailsServiceImpl.java


示例9: testClientSpecificTokenExpiry

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testClientSpecificTokenExpiry() throws Exception {
	getTokenServices().setAccessTokenValiditySeconds(1000);
	getTokenServices().setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId)
				throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setAccessTokenValiditySeconds(100);
			return client;
		}
	});
	OAuth2AccessToken accessToken = getTokenServices().createAccessToken(
			createAuthentication());
	assertTrue(100 >= accessToken.getExpiresIn());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:16,代码来源:AbstractTestDefaultTokenServices.java


示例10: testClientSpecificTokenExpiry

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testClientSpecificTokenExpiry() throws Exception {
	services.setAccessTokenValiditySeconds(1000);
	services.setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setAccessTokenValiditySeconds(100);
			return client;
		}
	});
	OAuth2AccessToken accessToken = services.createAccessToken(createAuthentication());
	assertTrue(100 >= accessToken.getExpiresIn());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:14,代码来源:JwtTokenServicesTests.java


示例11: testDifferentRefreshTokenMaintainsState

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testDifferentRefreshTokenMaintainsState() throws Exception {
	// create access token
	getTokenServices().setAccessTokenValiditySeconds(1);
	getTokenServices().setClientDetailsService(new ClientDetailsService() {
		public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
			BaseClientDetails client = new BaseClientDetails();
			client.setAccessTokenValiditySeconds(1);
			client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
			return client;
		}
	});
	OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(null, "id", null, false, Collections.singleton("read"), null, null, null, null), new TestAuthentication("test2", false));
	DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
			expectedAuthentication);
	OAuth2RefreshToken expectedExpiringRefreshToken = firstAccessToken.getRefreshToken();
	// Make it expire (and rely on mutable state in volatile token store)
	firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
	// create another access token
	OAuth2AccessToken secondAccessToken = getTokenServices().createAccessToken(expectedAuthentication);
	assertFalse("The new access token should be different",
			firstAccessToken.getValue().equals(secondAccessToken.getValue()));
	assertEquals("The new access token should have the same refresh token",
			expectedExpiringRefreshToken.getValue(), secondAccessToken.getRefreshToken().getValue());
	// refresh access token with refresh token
	
	TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id", Collections.singleton("read"), null);
	getTokenServices().refreshAccessToken(expectedExpiringRefreshToken.getValue(), tokenRequest);
	assertEquals(1, getAccessTokenCount());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:31,代码来源:DefaultTokenServicesWithInMemoryTests.java


示例12: init

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Before
public void init() {
	handler.setApprovalStore(store);
	InMemoryClientDetailsService clientDetailsService = new InMemoryClientDetailsService();
	Map<String, ClientDetails> map = new HashMap<String, ClientDetails>();
	map.put("client", new BaseClientDetails("client", null, "read,write", "authorization_code", null));
	clientDetailsService.setClientDetailsStore(map);
	handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
	userAuthentication = new UsernamePasswordAuthenticationToken("user", "N/A",
			AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:12,代码来源:ApprovalStoreUserApprovalHandlerTests.java


示例13: testAutoapprovedScopes

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testAutoapprovedScopes() {
	handler.setClientDetailsService(clientDetailsService);
	BaseClientDetails client = new BaseClientDetails("client", null, "read", "authorization_code", null);
	client.setAutoApproveScopes(new HashSet<String>(Arrays.asList("read")));
	clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
	AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
	AuthorizationRequest result = handler.checkForPreApproval(authorizationRequest, userAuthentication);
	assertTrue(result.isApproved());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:ApprovalStoreUserApprovalHandlerTests.java


示例14: testAutoapprovedWildcardScopes

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testAutoapprovedWildcardScopes() {
	handler.setClientDetailsService(clientDetailsService);
	BaseClientDetails client = new BaseClientDetails("client", null, "read", "authorization_code", null);
	client.setAutoApproveScopes(new HashSet<String>(Arrays.asList(".*")));
	clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
	AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
	AuthorizationRequest result = handler.checkForPreApproval(authorizationRequest, userAuthentication);
	assertTrue(result.isApproved());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:ApprovalStoreUserApprovalHandlerTests.java


示例15: testAutoapprovedAllScopes

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testAutoapprovedAllScopes() {
	handler.setClientDetailsService(clientDetailsService);
	BaseClientDetails client = new BaseClientDetails("client", null, "read", "authorization_code", null);
	client.setAutoApproveScopes(new HashSet<String>(Arrays.asList("true")));
	clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
	AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
	AuthorizationRequest result = handler.checkForPreApproval(authorizationRequest, userAuthentication);
	assertTrue(result.isApproved());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:ApprovalStoreUserApprovalHandlerTests.java


示例16: init

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Before
public void init() {
	AuthorizationRequest authorizationRequest = new AuthorizationRequest();
	authorizationRequest.setClientId("client");
	authorizationRequest.setScope(Arrays.asList("read", "write"));
	authentication = new OAuth2Authentication(authorizationRequest.createOAuth2Request(), userAuthentication);
	InMemoryClientDetailsService clientDetailsService = new InMemoryClientDetailsService();
	client = new BaseClientDetails("client", "source", "read,write", "authorization_code,client_credentials",
			"read");
	clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
	voter.setClientDetailsService(clientDetailsService);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:13,代码来源:ClientScopeVoterTests.java


示例17: ResourceOwnerPasswordTokenGranterTests

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
public ResourceOwnerPasswordTokenGranterTests() {
	String clientId = "client";
	BaseClientDetails clientDetails = new BaseClientDetails();
	clientDetails.setClientId(clientId);

	providerTokenServices.setTokenStore(new InMemoryTokenStore());
	Map<String, String> parameters = new HashMap<String, String>();
	parameters.put("username", "foo");
	parameters.put("password", "bar");
	parameters.put("client_id", clientId);

	tokenRequest = requestFactory.createTokenRequest(parameters,
			clientDetails);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:15,代码来源:ResourceOwnerPasswordTokenGranterTests.java


示例18: testOauthClient

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testOauthClient() throws Exception {
	AuthorizationRequest request = new AuthorizationRequest("foo", Collections.singleton("read"));
	request.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "", "", "client_credentials", "ROLE_CLIENT"));
	
	OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request(request.getRequestParameters(), request.getClientId(), request.getAuthorities(), request.isApproved(), request.getScope(), request.getResourceIds(),
			request.getRedirectUri(), request.getResponseTypes(), request.getExtensions());
	
	Authentication userAuthentication = null;
	OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
	FilterInvocation invocation = new FilterInvocation("/foo", "GET");
	Expression expression = handler.getExpressionParser().parseExpression("#oauth2.clientHasAnyRole('ROLE_CLIENT')");
	assertTrue((Boolean) expression.getValue(handler.createEvaluationContext(oAuth2Authentication, invocation)));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:15,代码来源:OAuth2WebSecurityExpressionHandlerTests.java


示例19: testOauthClient

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Test
public void testOauthClient() throws Exception {
	AuthorizationRequest request = new AuthorizationRequest("foo",
			Collections.singleton("read"));
	request
			.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "", "", "client_credentials", "ROLE_CLIENT"));
	Authentication userAuthentication = null;
	
	OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request(request.getRequestParameters(), request.getClientId(), request.getAuthorities(), request.isApproved(), request.getScope(), request.getResourceIds(),
			request.getRedirectUri(), request.getResponseTypes(), request.getExtensions());
	
	OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
	assertTrue(new OAuth2SecurityExpressionMethods(oAuth2Authentication, true).clientHasAnyRole("ROLE_CLIENT"));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:15,代码来源:OAuth2SecurityExpressionMethodsTests.java


示例20: init

import org.springframework.security.oauth2.provider.BaseClientDetails; //导入依赖的package包/类
@Before
public void init() {
	token = new DefaultOAuth2AccessToken("FOO");
	ClientDetails client = new BaseClientDetails("client", null, "read", "client_credentials", "ROLE_CLIENT");
	authentication = new OAuth2Authentication(new TokenRequest(null, "client", null, "client_credentials").createOAuth2Request(client ), null);
	tokenStore.clear();		
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:ResourceServerConfigurationTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MemoMismatches类代码示例发布时间:2022-05-22
下一篇:
Java KDFDoublePipelineIterationParameters类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap