org.springframework.security.oauth2.provider.ClientDetailsService Java Examples

The following examples show how to use org.springframework.security.oauth2.provider.ClientDetailsService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuth2AutoConfigurationTests.java    From spring-security-oauth2-boot with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: OAuth2Config.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Bean
public Oauth2Service oauth2Service(
        ClientDetailsService clientDetailsService,
        OAuth2RequestFactory requestFactory,
        DefaultTokenGranter defaultTokenGranter) {
    return new Oauth2Service(clientDetailsService, requestFactory, defaultTokenGranter);
}
 
Example #3
Source File: WxLoginConfig.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
/**
 * 微信登录成功后的处理
 *
 * @return AuthenticationSuccessHandler
 */
@Bean
public AuthenticationSuccessHandler wxLoginSuccessHandler(PasswordEncoder encoder, ClientDetailsService clientDetailsService, ObjectMapper objectMapper,
                                                          AuthorizationServerTokenServices defaultAuthorizationServerTokenServices) {
    return WxLoginSuccessHandler.builder()
            .objectMapper(objectMapper)
            .clientDetailsService(clientDetailsService)
            .passwordEncoder(encoder)
            .defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}
 
Example #4
Source File: MobileLoginConfig.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
/**
 * 手机登录成功后的处理
 *
 * @return AuthenticationSuccessHandler
 */
@Bean
public AuthenticationSuccessHandler mobileLoginSuccessHandler(PasswordEncoder encoder, ClientDetailsService clientDetailsService, ObjectMapper objectMapper,
                                                              AuthorizationServerTokenServices defaultAuthorizationServerTokenServices) {
    return MobileLoginSuccessHandler.builder()
            .objectMapper(objectMapper)
            .clientDetailsService(clientDetailsService)
            .passwordEncoder(encoder)
            .defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}
 
Example #5
Source File: OAuth2SecurityConfiguration.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
private List<TokenGranter> getTokenGranters(AuthorizationCodeServices authorizationCodeServices,
                                            AuthorizationServerTokenServices tokenServices,
                                            ClientDetailsService clientDetailsService,
                                            OAuth2RequestFactory requestFactory) {
    return Stream.of(
            new ClientCredentialsTokenGranter(tokenServices, clientDetailsService, requestFactory),
            new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new PhonePasswordTokenGranter(authenticationManager, tokenServices, clientDetailsService, requestFactory),
            new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetailsService, requestFactory),
            new SmsTokenGranter(userServiceImpl, tokenServices, clientDetailsService, requestFactory))
            .collect(Collectors.toList());
}
 
Example #6
Source File: ClientAndUserDetailsService.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
public ClientAndUserDetailsService(ClientDetailsService clients,
		UserDetailsService users) {
	super();
	clients_ = clients;
	users_ = users;
	clientDetailsWrapper_ = new ClientDetailsUserDetailsService(clients_);
}
 
Example #7
Source File: CustomResourceOwnerPasswordTokenGranter.java    From spring-auth-example with MIT License 5 votes vote down vote up
protected CustomResourceOwnerPasswordTokenGranter(
    AuthenticationManager authenticationManager,
    AuthorizationServerTokenServices tokenServices,
    ClientDetailsService clientDetailsService,
    OAuth2RequestFactory requestFactory, String grantType) {
  super(tokenServices, clientDetailsService, requestFactory, grantType);
  this.authenticationManager = authenticationManager;
}
 
Example #8
Source File: OpenIdOAuth2Configuration.java    From cola with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class})
public OpenIdTokenGranter openIdTokenGranter(AuthenticationManager authenticationManager,
											 AuthorizationServerTokenServices tokenServices,
											 ClientDetailsService clientDetailsService) {
	return new OpenIdTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService));
}
 
Example #9
Source File: AcOAuth2Configuration.java    From cola with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class})
public AcTokenGranter acTokenGranter(AuthenticationManager authenticationManager,
									 AuthorizationServerTokenServices tokenServices,
									 ClientDetailsService clientDetailsService) {
	return new AcTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService));
}
 
Example #10
Source File: SmsOAuth2Configuration.java    From cola with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnBean({AuthenticationManager.class, AuthorizationServerTokenServices.class, ClientDetailsService.class})
public SmsTokenGranter smsTokenGranter(AuthenticationManager authenticationManager,
									   AuthorizationServerTokenServices tokenServices,
									   ClientDetailsService clientDetailsService) {
	return new SmsTokenGranter(authenticationManager, tokenServices, clientDetailsService, new DefaultOAuth2RequestFactory(clientDetailsService));
}
 
Example #11
Source File: JdbcClientDetailsServiceConfig.java    From syhthems-platform with MIT License 5 votes vote down vote up
@Bean
@Primary
public ClientDetailsService jdbcClientDetailsService() {
    JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
    clientDetailsService.setPasswordEncoder(passwordEncoder);
    return clientDetailsService;
}
 
Example #12
Source File: LessStrictRedirectUriAuthorizationCodeTokenGranter.java    From osiam with MIT License 5 votes vote down vote up
public LessStrictRedirectUriAuthorizationCodeTokenGranter(
        AuthorizationServerTokenServices tokenServices,
        AuthorizationCodeServices authorizationCodeServices,
        ClientDetailsService clientDetailsService,
        OAuth2RequestFactory requestFactory
) {
    super(tokenServices, clientDetailsService, requestFactory, GRANT_TYPE);
    this.authorizationCodeServices = authorizationCodeServices;
}
 
Example #13
Source File: AuthorizationServerConfigration.java    From Taroco with Apache License 2.0 5 votes vote down vote up
/**
 * 客户端管理
 */
@Bean
@Lazy
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
public ClientDetailsService clientDetailsService() {
    return new CustomClientDetailsService(CacheConstants.REDIS_CLIENTS_PREFIX, dataSource, redisRepository, objectMapper);
}
 
Example #14
Source File: CustomResourceOwnerPasswordTokenGranter.java    From spring-auth-example with MIT License 5 votes vote down vote up
public CustomResourceOwnerPasswordTokenGranter(
    AuthenticationManager authenticationManager,
    AuthorizationServerTokenServices tokenServices,
    ClientDetailsService clientDetailsService,
    OAuth2RequestFactory requestFactory) {
  this(authenticationManager, tokenServices, clientDetailsService,
      requestFactory, GRANT_TYPE);
}
 
Example #15
Source File: WebSecurityConfiguration.java    From DAFramework with MIT License 4 votes vote down vote up
@Bean
public ClientDetailsService jdbcClientDetailsService() {
	return new JdbcClientDetailsService(dataSource);
}
 
Example #16
Source File: AccessConfirmationController.java    From osiam with MIT License 4 votes vote down vote up
@Autowired
public AccessConfirmationController(ClientDetailsService clientDetailsService) {
    this.clientDetailsService = clientDetailsService;
}
 
Example #17
Source File: OAuth2Configuration.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetailsService() {
    return new JdbcClientDetailsService(dataSource);
}
 
Example #18
Source File: CustomAuthCodeTokenGranter.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
protected CustomAuthCodeTokenGranter(AuthorizationServerTokenServices tokenServices, AuthorizationCodeServices authorizationCodeServices,
                                        ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, String grantType) {
    super(tokenServices, clientDetailsService, requestFactory, grantType);
    this.authorizationCodeServices = authorizationCodeServices;
}
 
Example #19
Source File: CustomAuthCodeTokenGranter.java    From OAuth-2.0-Cookbook with MIT License 4 votes vote down vote up
public CustomAuthCodeTokenGranter(AuthorizationServerTokenServices tokenServices,
                                     AuthorizationCodeServices authorizationCodeServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) {
    this(tokenServices, authorizationCodeServices, clientDetailsService, requestFactory, GRANT_TYPE);
}
 
Example #20
Source File: AuthorizationServerConfig.java    From lion with Apache License 2.0 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetails() {
    return new JdbcClientDetailsService(dataSource);
}
 
Example #21
Source File: BootBasicAuthenticationFilter.java    From oauth-boot with MIT License 4 votes vote down vote up
public void setClientDetailsService(ClientDetailsService clientDetailsService) {
    this.clientDetailsService = clientDetailsService;
}
 
Example #22
Source File: AuthorizationSeverConfig.java    From springboot-vue.js-bbs with Apache License 2.0 4 votes vote down vote up
@Bean
@Primary
public ClientDetailsService clientDetailsService() {
    return new JdbcClientDetailsService(dataSource);
}
 
Example #23
Source File: ClientDetailsServiceBuilder.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ClientDetailsService build() throws Exception {
    return null;
}
 
Example #24
Source File: DefaultClientDetailsUserDetailsService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DefaultClientDetailsUserDetailsService( ClientDetailsService clientDetailsService )
{
    super( clientDetailsService );
}
 
Example #25
Source File: AuthorizationServerConfiguration.java    From MyShopPlus with Apache License 2.0 4 votes vote down vote up
@Bean
public ClientDetailsService jdbcClientDetailsService() {
    // 基于 JDBC 实现,需要事先在数据库配置客户端信息
    return new JdbcClientDetailsService(dataSource());
}
 
Example #26
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * This constructor is used to setup the clients and users that will be able to login to the
 * system. This is a VERY insecure setup that is using hard-coded lists of clients / users /
 * passwords and should never be used for anything other than local testing
 * on a machine that is not accessible via the Internet. Even if you use
 * this code for testing, at the bare minimum, you should consider changing the
 * passwords listed below and updating the VideoSvcClientApiTest.
 * 
 * @param auth
 * @throws Exception
 */
public OAuth2Config() throws Exception {
	
	// If you were going to reuse this class in another
	// application, this is one of the key sections that you
	// would want to change
	
	
	// Create a service that has the credentials for all our clients
	ClientDetailsService csvc = new InMemoryClientDetailsServiceBuilder()
			// Create a client that has "read" and "write" access to the
	        // video service
			.withClient("mobile").authorizedGrantTypes("password")
			.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
			.scopes("read","write").resourceIds("video")
			.and()
			// Create a second client that only has "read" access to the
			// video service
			.withClient("mobileReader").authorizedGrantTypes("password")
			.authorities("ROLE_CLIENT")
			.scopes("read").resourceIds("video")
			.accessTokenValiditySeconds(3600).and().build();

	// Create a series of hard-coded users. 
	UserDetailsService svc = new InMemoryUserDetailsManager(
			Arrays.asList(
					User.create("admin", "pass", "ADMIN", "USER"),
					User.create("user0", "pass", "USER"),
					User.create("user1", "pass", "USER"),
					User.create("user2", "pass", "USER"),
					User.create("user3", "pass", "USER"),
					User.create("user4", "pass", "USER"),
					User.create("user5", "pass", "USER")));

	// Since clients have to use BASIC authentication with the client's id/secret,
	// when sending a request for a password grant, we make each client a user
	// as well. When the BASIC authentication information is pulled from the
	// request, this combined UserDetailsService will authenticate that the
	// client is a valid "user". 
	combinedService_ = new ClientAndUserDetailsService(csvc, svc);
}
 
Example #27
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 4 votes vote down vote up
/**
 * Return the list of trusted client information to anyone who asks for it.
 */
@Bean
public ClientDetailsService clientDetailsService() throws Exception {
	return combinedService_;
}
 
Example #28
Source File: OAuth2ServerConfiguration.java    From spring-oauth-server with GNU General Public License v2.0 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetailsService(DataSource dataSource) {
    return new CustomJdbcClientDetailsService(dataSource);
}
 
Example #29
Source File: JdbcOAuth2SupportConfiguration.java    From omh-dsu-ri with Apache License 2.0 4 votes vote down vote up
/**
 * @return the service used to retrieve OAuth2 client details
 */
@Bean
public ClientDetailsService clientDetailsService() {

    return new JdbcClientDetailsService(dataSource);
}
 
Example #30
Source File: AuthorizationServerConfig.java    From platform with Apache License 2.0 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetailsService() {
    return new SecurityClientDetailsService(dataSource);
}