本文整理汇总了Java中org.springframework.security.oauth2.provider.ClientDetailsService类的典型用法代码示例。如果您正苦于以下问题:Java ClientDetailsService类的具体用法?Java ClientDetailsService怎么用?Java ClientDetailsService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientDetailsService类属于org.springframework.security.oauth2.provider包,在下文中一共展示了ClientDetailsService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCustomizedTokenGranters
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
private List<TokenGranter> getCustomizedTokenGranters() {
AuthorizationServerTokenServices tokenServices = tokenServices();
ClientDetailsService clientDetails = clientDetailsService();
AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices();
OAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetails);
AuthorizationCodeTokenGranter authorizationCodeTokenGranter = new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetails, requestFactory);
RefreshTokenGranter refreshTokenGranter = new RefreshTokenGranter(tokenServices, clientDetails, requestFactory);
ImplicitTokenGranter implicit = new ImplicitTokenGranter(tokenServices, clientDetails, requestFactory);
ClientCredentialsTokenGranter clientCredentialsTokenGranter = new ClientCredentialsTokenGranter(tokenServices, clientDetails, requestFactory);
clientCredentialsTokenGranter.setAllowRefresh(true);//custom config, see AuthorizationServerEndpointsConfigurer.getDefaultTokenGranters
List<TokenGranter> tokenGranters = new ArrayList<>();
tokenGranters.add(authorizationCodeTokenGranter);
tokenGranters.add(refreshTokenGranter);
tokenGranters.add(implicit);
tokenGranters.add(clientCredentialsTokenGranter);
if (authenticationManager != null) {
tokenGranters.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetails, requestFactory));
}
return tokenGranters;
}
示例2: clientDetailsService
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
private ClientDetailsService clientDetailsService() throws Exception {
// @formatter:off
return new InMemoryClientDetailsServiceBuilder()
.withClient("clientapp")
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.secret("123456")
.and()
.withClient("clientapp2")
.authorizedGrantTypes("client_credentials")
.authorities("USER")
.scopes("read", "write")
.secret("123456")
.and()
.withClient("clientapp3")
.authorizedGrantTypes("authorization_code")
.authorities("USER")
.redirectUris(
"http://localhost:5000/login.html",
"http://localhost:5000/diff_login.html")
.scopes("read", "write")
.secret("123456")
.and().build();
// @formatter:on
}
示例3: OAuthConfig
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
public OAuthConfig() throws Exception {
ClientDetailsService csvc = new InMemoryClientDetailsServiceBuilder()
.withClient("mobile").authorizedGrantTypes("password")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read","write").resourceIds("prublisher")
.accessTokenValiditySeconds(3600).and().build();
UserDetailsService svc = new InMemoryUserDetailsManager(
Arrays.asList(
User.create("publisher", "publisher", MobileClient.ROLE_PUBLISHER),
User.create("subscriber", "subscriber", MobileClient.ROLE_SUBSCRIBER)));
combinedService_ = new ClientAndUserDetailsService(csvc,svc);
}
示例4: clientDetailsService
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Bean
ClientDetailsService clientDetailsService() {
return clientId -> clientRepository.findByClientId(clientId)
.map(client -> {
BaseClientDetails details = new BaseClientDetails(
client.getClientId(),
null,
client.getScopes(),
client.getAuthorizedGrantTypes(),
client.getAuthorities(),
client.getRegisteredRedirectUri()
);
details.setClientSecret(client.getSecret());
details.setAutoApproveScopes(Arrays.asList(client.getAutoApproveScopes().split(",")));
details.setAccessTokenValiditySeconds(1800); // 30mn Token < 1h RefreshToken!
details.setRefreshTokenValiditySeconds(3600);
return details;
})
.orElseThrow(() -> new ClientRegistrationException(String.format("no client %s registered", clientId)));
}
示例5: testDefaultConfiguration
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Test
public void testDefaultConfiguration() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(AUTHORIZATION_SERVER_CONFIG);
this.context.getBean(RESOURCE_SERVER_CONFIG);
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(BaseClientDetails.class);
AuthorizationEndpoint endpoint = this.context
.getBean(AuthorizationEndpoint.class);
UserApprovalHandler handler = (UserApprovalHandler) ReflectionTestUtils
.getField(endpoint, "userApprovalHandler");
ClientDetailsService clientDetailsService = this.context
.getBean(ClientDetailsService.class);
ClientDetails clientDetails = clientDetailsService
.loadClientByClientId(config.getClientId());
assertThat(AopUtils.isJdkDynamicProxy(clientDetailsService), equalTo(true));
assertThat(AopUtils.getTargetClass(clientDetailsService).getName(),
is(equalTo(InMemoryClientDetailsService.class.getName())));
assertThat(handler instanceof ApprovalStoreUserApprovalHandler, equalTo(true));
assertThat(clientDetails, equalTo(config));
verifyAuthentication(config);
}
示例6: testClientSpecificRefreshTokenExpiry
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的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()));
}
示例7: testClientSpecificRefreshTokenExpiry
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的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()));
}
示例8: testNoRefreshTokenIfNotAuthorized
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的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());
}
示例9: init
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的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();
}
示例10: testDefaultConfiguration
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Test
public void testDefaultConfiguration() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(AUTHORIZATION_SERVER_CONFIG);
this.context.getBean(RESOURCE_SERVER_CONFIG);
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(BaseClientDetails.class);
AuthorizationEndpoint endpoint = this.context
.getBean(AuthorizationEndpoint.class);
UserApprovalHandler handler = (UserApprovalHandler) ReflectionTestUtils
.getField(endpoint, "userApprovalHandler");
ClientDetailsService clientDetailsService = this.context
.getBean(ClientDetailsService.class);
ClientDetails clientDetails = clientDetailsService
.loadClientByClientId(config.getClientId());
assertThat(AopUtils.isJdkDynamicProxy(clientDetailsService)).isTrue();
assertThat(AopUtils.getTargetClass(clientDetailsService).getName())
.isEqualTo(InMemoryClientDetailsService.class.getName());
assertThat(handler).isInstanceOf(ApprovalStoreUserApprovalHandler.class);
assertThat(clientDetails).isEqualTo(config);
verifyAuthentication(config);
assertThat(this.context.getBeanNamesForType(OAuth2RestOperations.class))
.isEmpty();
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:28,代码来源:OAuth2AutoConfigurationTests.java
示例11: CustomResourceOwnerPasswordTokenGranter
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
public CustomResourceOwnerPasswordTokenGranter(
AuthenticationManager authenticationManager,
AuthorizationServerTokenServices tokenServices,
ClientDetailsService clientDetailsService,
OAuth2RequestFactory requestFactory) {
this(authenticationManager, tokenServices, clientDetailsService,
requestFactory, GRANT_TYPE);
}
示例12: ClientAndUserDetailsService
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
public ClientAndUserDetailsService(ClientDetailsService clients,
UserDetailsService users) {
super();
clients_ = clients;
users_ = users;
clientDetailsWrapper_ = new ClientDetailsUserDetailsService(clients_);
}
示例13: configure
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Override
protected void configure(final HttpSecurity http) throws Exception {
AuthorizationServerSecurityConfigurer configurer = new AuthorizationServerSecurityConfigurer();
FrameworkEndpointHandlerMapping handlerMapping = endpoints.oauth2EndpointHandlerMapping();
http.setSharedObject(FrameworkEndpointHandlerMapping.class, handlerMapping);
configure(configurer);
http.apply(configurer);
String tokenEndpointPath = handlerMapping.getServletPath("/oauth/token");
String tokenKeyPath = handlerMapping.getServletPath("/oauth/token_key");
String checkTokenPath = handlerMapping.getServletPath("/oauth/check_token");
String revokeTokenPath = handlerMapping.getServletPath("/oauth/revoke");
if (!endpoints.getEndpointsConfigurer().isUserDetailsServiceOverride()) {
UserDetailsService userDetailsService = http.getSharedObject(UserDetailsService.class);
endpoints.getEndpointsConfigurer().userDetailsService(userDetailsService);
}
// @formatter:off
http
.authorizeRequests()
// Per the OAuth2 spec, we should only allow POST to the token endpoint.
// See: https://github.com/spring-projects/spring-security-oauth/issues/327
.antMatchers(HttpMethod.GET, tokenEndpointPath).denyAll()
.antMatchers(HttpMethod.PUT, tokenEndpointPath).denyAll()
.antMatchers(HttpMethod.PATCH, tokenEndpointPath).denyAll()
.antMatchers(HttpMethod.DELETE, tokenEndpointPath).denyAll()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "**").permitAll()
.antMatchers(tokenEndpointPath).fullyAuthenticated()
.antMatchers(tokenKeyPath).access(configurer.getTokenKeyAccess())
.antMatchers(checkTokenPath).access(configurer.getCheckTokenAccess())
.antMatchers(revokeTokenPath).access(configurer.getCheckTokenAccess())
.and()
.requestMatchers()
.antMatchers(tokenEndpointPath, tokenKeyPath, checkTokenPath, revokeTokenPath)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
// @formatter:on
http.setSharedObject(ClientDetailsService.class, clientDetailsService);
}
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:40,代码来源:CustomAuthorizationServerSecurityConfiguration.java
示例14: AuthorizationServerConfig
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Autowired
public AuthorizationServerConfig(AuthenticationManager authenticationManager,
ClientDetailsService clientDetailsService, UserDetailsService userDetailsService) {
this.authenticationManager = authenticationManager;
this.clientDetailsService = clientDetailsService;
this.userDetailsService = userDetailsService;
}
示例15: testDefaultConfiguration
import org.springframework.security.oauth2.provider.ClientDetailsService; //导入依赖的package包/类
@Test
public void testDefaultConfiguration() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(AUTHORIZATION_SERVER_CONFIG);
this.context.getBean(RESOURCE_SERVER_CONFIG);
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(BaseClientDetails.class);
AuthorizationEndpoint endpoint = this.context
.getBean(AuthorizationEndpoint.class);
UserApprovalHandler handler = (UserApprovalHandler) ReflectionTestUtils
.getField(endpoint, "userApprovalHandler");
ClientDetailsService clientDetailsService = this.context
.getBean(ClientDetailsService.class);
ClientDetails clientDetails = clientDetailsService
.loadClientByClientId(config.getClientId());
assertThat(AopUtils.isJdkDynamicProxy(clientDetailsService)).isTrue();
assertThat(AopUtils.getTargetClass(clientDetailsService).getName())
.isEqualTo(InMemoryClientDetailsService.class.getName());
assertThat(handler).isInstanceOf(ApprovalStoreUserApprovalHandler.class);
assertThat(clientDetails).isEqualTo(config);
verifyAuthentication(config);
assertThat(this.context.getBeanNamesForType(OAuth2RestOperations.class))
.isEmpty();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:28,代码来源:OAuth2AutoConfigurationTests.java