Java Code Examples for org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer

The following examples show how to use org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer. These examples are extracted from open source projects. 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 Project: spring-boot-demo   Source File: AuthorizationServerConfig.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("client1")
            .resourceIds(RESOURCE_ID)
            .authorizedGrantTypes("authorization_code", "refresh_token", "implicit")
            .authorities("ROLE_CLIENT")
            .scopes("get_user_info", "get_childlist")
            .secret("secret")
            .redirectUris("http://localhost:8081/client/account/redirect")
            .autoApprove(true)
            .autoApprove("get_user_info")
            .and()

            .withClient("client2")
            .resourceIds(RESOURCE_ID)
            .authorizedGrantTypes("authorization_code", "refresh_token", "implicit")
            .authorities("ROLE_CLIENT")
            .scopes("get_user_info", "get_childlist")
            .secret("secret")
            .redirectUris("http://localhost:8082/client/account/redirect");
}
 
Example 2
Source Project: open-capacity-platform   Source File: OAuth2ServerConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 配置应用名称 应用id
 * 配置OAuth2的客户端相关信息
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

    // if(clientDetailsService!=null){
    // clients.withClientDetails(clientDetailsService);
    // }else{
    // clients.inMemory().withClient("neusoft1").secret("neusoft1")
    // .authorizedGrantTypes("authorization_code", "password",
    // "refresh_token").scopes("all")
    // .resourceIds(SERVER_RESOURCE_ID).accessTokenValiditySeconds(1200)
    // .refreshTokenValiditySeconds(50000)
    // .and().withClient("neusoft2").secret("neusoft2")
    // .authorizedGrantTypes("authorization_code", "password",
    // "refresh_token").scopes("all")
    // .resourceIds(SERVER_RESOURCE_ID).accessTokenValiditySeconds(1200)
    // .refreshTokenValiditySeconds(50000)
    // ;
    // }
    clients.withClientDetails(redisClientDetailsService);
    redisClientDetailsService.loadAllClientToCache();
}
 
Example 3
Source Project: spring-cloud-study   Source File: OAuth2Config.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.jdbc(dataSource);

//        clients.inMemory()
//                .withClient("order-client")
//                .secret(passwordEncoder.encode("order-secret-8888"))
//                .authorizedGrantTypes("refresh_token", "authorization_code", "password")
//                .accessTokenValiditySeconds(3600)
//                .scopes("all")
//                .and()
//                .withClient("user-client")
//                .secret(passwordEncoder.encode("user-secret-8888"))
//                .authorizedGrantTypes("refresh_token", "authorization_code", "password")
//                .accessTokenValiditySeconds(3600)
//                .scopes("all");
    }
 
Example 4
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("oauth2")
                .secret("$2a$10$uLCAqDwHD9SpYlYSnjtrXemXtlgSvZCNlOwbW/Egh0wufp93QjBUC")
                .resourceIds("oauth2")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "sms")
                .authorities("ROLE_ADMIN", "ROLE_USER")
                .scopes("all")
                .accessTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
                .refreshTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
                .redirectUris("http://example.com")
            .and()
            .withClient("test")
                .secret("$2a$10$wlgcx61faSJ8O5I4nLiovO9T36HBQgh4RhOQAYNORCzvANlInVlw2")
                .resourceIds("oauth2")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "sms")
                .authorities("ROLE_ADMIN", "ROLE_USER")
                .scopes("all")
                .accessTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
                .refreshTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
                .redirectUris("http://example.com");
}
 
Example 5
Source Project: tutorials   Source File: AuthorizationServerConfig.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients
      .inMemory()
      .withClient("baeldung")
      .secret(passwordEncoder().encode("baeldung"))
      .authorizedGrantTypes("client_credentials", "password", "authorization_code")
      .scopes("openid", "read")
      .autoApprove(true)
      .and()
      .withClient("baeldung-admin")
      .secret(passwordEncoder().encode("baeldung"))
      .authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token")
      .scopes("read", "write")
      .autoApprove(true);
}
 
Example 6
@Bean
public AuthorizationServerConfigurer authorizationServerConfigurer(
		@Value("${client.web.name}") String clientName, 
   		@Value("${client.web.secret}") String clientSecret) {
	return new AuthorizationServerConfigurerAdapter() {

		@Override
		public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
			clients.inMemory()
			       .withClient(clientName)
			       .secret(passwordEncoder.encode(clientSecret))
			       .scopes("account", "message", "email")
			       .authorizedGrantTypes("client_credentials");
		}
		
		@Override
		public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
		    oauthServer.checkTokenAccess("isAuthenticated()");    
		}

		@Override
		public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
			endpoints.accessTokenConverter(accessTokenConverter());
		}
	};
}
 
Example 7
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients
            .inMemory()

            .withClient("trusted-app")
                .authorizedGrantTypes("client_credentials", "password", "refresh_token")
                .authorities(Role.ROLE_TRUSTED_CLIENT.toString())
                .scopes("read", "write")
                .resourceIds(resourceId)
                .accessTokenValiditySeconds(10)
                .refreshTokenValiditySeconds(30000)
                .secret("secret")
            .and()
            .withClient("register-app")
                .authorizedGrantTypes("client_credentials")
                .authorities(Role.ROLE_REGISTER.toString())
                .scopes("registerUser")
                .accessTokenValiditySeconds(10)
                .refreshTokenValiditySeconds(10)
                .resourceIds(resourceId)
                .secret("secret");
}
 
Example 8
/**
 * 配置客户端详情信息,客户端详情信息在这里进行初始化,通过数据库来存储调取详情信息
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    InMemoryClientDetailsServiceBuilder builder = clients.inMemory();
    if (ArrayUtils.isNotEmpty(securityProperties.getOauth2().getClients())) {
        for (OAuth2ClientProperties client : securityProperties.getOauth2().getClients()) {
            builder
                    .withClient(client.getClientId())
                    .secret(new BCryptPasswordEncoder().encode(client.getClientSecret()))
                    // .resourceIds("admin","auth")
                    //设置token的有效期,不设置默认12小时
                    .accessTokenValiditySeconds(client.getAccessTokenValidatySeconds())
                    //设置刷新token的有效期,不设置默认30天
                    .refreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds())
                    .redirectUris("http://www.baidu.com")
                    .authorizedGrantTypes("authorization_code","client_credentials", "refresh_token", "password")
                    .scopes("all", "read", "write")
                    .autoApprove(true);
        }
    }
}
 
Example 9
Source Project: tutorials   Source File: AuthServerConfigurer.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(
    ClientDetailsServiceConfigurer clients)
    throws Exception {
    clients
        .inMemory()
        .withClient("authserver")
        .secret(passwordEncoder.encode("passwordforauthserver"))
        .redirectUris("http://localhost:8080/login")
        .authorizedGrantTypes("authorization_code",
            "refresh_token")
        .scopes("myscope")
        .autoApprove(true)
        .accessTokenValiditySeconds(30)
        .refreshTokenValiditySeconds(1800);
}
 
Example 10
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
  configurer
      .inMemory()
      .withClient(CLIENT_ID)
      .secret(CLIENT_SECRET)
      .authorizedGrantTypes(GRANT_TYPE_PASSWORD, AUTHORIZATION_CODE, REFRESH_TOKEN, IMPLICIT,
          GRANT_TYPE_CLIENT_CREDENTIALS)
      .scopes(SCOPE_API)
      .accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS)
      .refreshTokenValiditySeconds(REFRESH_TOKEN_VALIDITY_SECONDS)
      .redirectUris("http://localhost:8765/");
}
 
Example 11
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient(ClientID)
            .secret(passwordEncoder.encode(ClientSecret))
            .authorizedGrantTypes("authorization_code")
            .scopes("user_info")
            .autoApprove(true)
            .redirectUris(RedirectURLs);
}
 
Example 12
@Override
public void configure(ClientDetailsServiceConfigurer clientDetailsServiceConfigurer) throws Exception {
    clientDetailsServiceConfigurer.inMemory()
            .withClient("client")
            .secret("clientsecret")
            .authorizedGrantTypes("authorization_code", "refresh_token", "implicit", "password", "client_credentials")
            .scopes("apiAccess");
}
 
Example 13
Source Project: oauth2lab   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients)
        throws Exception {
    clients.inMemory()
        .withClient("clientapp")
        .secret("112233")
        // 密码模式
        .authorizedGrantTypes("password")
        .scopes("read_userinfo", "read_contacts");
}
 
Example 14
Source Project: cloud-project   Source File: AuthorizationServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("app")
            .authorizedGrantTypes("authorization_code", "implicit")
            .authorities("ROLE_CLIENT")
            .scopes("read","write")
            .resourceIds(resourceId)
            .accessTokenValiditySeconds(accessTokenValiditySeconds);
}
 
Example 15
/**
 * configuration clients
 *
 * @param clients client details service configuration
 * @throws Exception exception
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    InMemoryClientDetailsServiceBuilder inMemoryClientDetailsServiceBuilder = clients.inMemory();
    apiBootOauthProperties.getClients().stream().forEach(client -> inMemoryClientDetailsServiceBuilder.withClient(client.getClientId())
            .secret(passwordEncoder().encode(client.getClientSecret()))
            .authorizedGrantTypes(client.getGrantTypes())
            .scopes(client.getScopes())
            .resourceIds(client.getResourceId())
            .accessTokenValiditySeconds(client.getAccessTokenValiditySeconds()));
}
 
Example 16
Source Project: gemini   Source File: OAuth2AuthorizationServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

    /* clients
            .inMemory()
            .withClient("client-gui")
            // .secret(passwordEncoder.encode(""))
            .authorizedGrantTypes("password", "refresh_token")
            .scopes("read")
            .accessTokenValiditySeconds(86400); // 24 hours */
    clients.withClientDetails(this.clientDetailsService);

}
 
Example 17
Source Project: oauth2-blog   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients
            .inMemory()
            .withClient(Const.CLIENT_ID)
            .secret(Const.CLIENT_SECRET)
            .authorizedGrantTypes(GRANT_TYPE_PASSWORD, AUTHORIZATION_CODE, REFRESH_TOKEN)
            .scopes(SCOPE_READ, SCOPE_WRITE, TRUST)
            .accessTokenValiditySeconds(VALID_FOREVER)
            .refreshTokenValiditySeconds(VALID_FOREVER);
}
 
Example 18
Source Project: oauth2lab   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients)
        throws Exception {
    clients.inMemory()
        .withClient("clientapp")
        .secret("112233")
        .redirectUris("http://localhost:9001/callback")
        // 简化模式
        .authorizedGrantTypes("implicit")
        .accessTokenValiditySeconds(120)
        .scopes("read_userinfo", "read_contacts");
}
 
Example 19
Source Project: cloud-service   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
/**
     * 我们将client信息存储到oauth_client_details表里<br>
     * 并将数据缓存到redis
     *
     * @param clients
     * @throws Exception
     */
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
//		clients.inMemory().withClient("system").secret(bCryptPasswordEncoder.encode("system"))
//				.authorizedGrantTypes("password", "authorization_code", "refresh_token").scopes("app")
//				.accessTokenValiditySeconds(3600);

//		clients.jdbc(dataSource);
        // 2019.06.06,这里优化一下,详细看下redisClientDetailsService这个实现类
        clients.withClientDetails(redisClientDetailsService);
        redisClientDetailsService.loadAllClientToCache();
    }
 
Example 20
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("oauth2")
            .secret("$2a$10$wlgcx61faSJ8O5I4nLiovO9T36HBQgh4RhOQAYNORCzvANlInVlw2")
            .resourceIds("oauth2")
            .authorizedGrantTypes("password", "authorization_code", "refresh_token")
            .authorities("ROLE_ADMIN", "ROLE_USER")
            .scopes("all")
            .accessTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
            .refreshTokenValiditySeconds(Math.toIntExact(Duration.ofHours(1).getSeconds()))
            .redirectUris("http://example.com");
}
 
Example 21
Source Project: java-starthere   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception
{
    configurer.inMemory()
              .withClient(CLIENT_ID)
              .secret(encoder.encode(CLIENT_SECRET))
              .authorizedGrantTypes(GRANT_TYPE_PASSWORD,
                                    AUTHORIZATION_CODE,
                                    IMPLICIT)
              .scopes(SCOPE_READ,
                      SCOPE_WRITE,
                      TRUST)
              .accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS);
}
 
Example 22
/**
 * 客户端验证
 * @param clients
 * @throws Exception
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("client_id")
            .scopes("all")
            .secret(passwordEncoder.encode("123456"))
            .authorizedGrantTypes("implicit","password",  "refresh_token","client_credentials").autoApprove(true);
}
 
Example 23
Source Project: micro-ecommerce   Source File: AuthserverApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
	clients.inMemory().withClient("acme").secret("acmesecret").authorities("CLIENT")
			.authorizedGrantTypes("authorization_code", "refresh_token", "client_credentials", "password")
			.scopes("openid", "read_catalog", "write_catalog", "read_orders", "write_orders", "read_reviews",
					"write_reviews", "read_recommendations", "write_recommendations");
}
 
Example 24
Source Project: microservice-skeleton   Source File: InMemoryOAuth2Config.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("browser")
            .authorizedGrantTypes("refresh_token", "password")
            .scopes("ui")
            .and()
            .withClient("service-account")
            .secret(env.getProperty("SERVICE_ACCOUNT_PASSWORD"))
            .authorizedGrantTypes("client_credentials", "refresh_token")
            .scopes("server");
}
 
Example 25
@Override
public void configure(ClientDetailsServiceConfigurer clientDetailsServiceConfigurer) throws Exception {
    clientDetailsServiceConfigurer.inMemory()
            .withClient("client")
            .secret("clientsecret")
            .authorizedGrantTypes("authorization_code", "refresh_token", "implicit", "password", "client_credentials")
            .scopes("apiAccess");
}
 
Example 26
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
        .withClient("clientapp")
        .secret("123456")
        .scopes("read_profile")
        .authorizedGrantTypes(
            "password",
            "authorization_code");
}
 
Example 27
Source Project: OAuth-2.0-Cookbook   Source File: OAuth2AuthorizationServer.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients)
        throws Exception {
    //@formatter:off
    clients.inMemory()
        .withClient("clientapp")
        .secret("123456")
        .redirectUris("http://localhost:9000/callback")
        .authorizedGrantTypes("authorization_code",
                "implicit", "password")
        .scopes("read_profile", "read_contacts");
  //@formatter:on
}
 
Example 28
Source Project: spring-boot-examples   Source File: AuthServerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(final ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("SampleClientId")
            .secret(passwordEncoder.encode("secret"))
            .authorizedGrantTypes("authorization_code")
            .scopes("user_info")
            .autoApprove(true)
            .redirectUris("http://localhost:8301/login", "http://localhost:8302/login");
}
 
Example 29
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

    clients.inMemory()
            .withClient("android")
            .authorizedGrantTypes("authorization_code", "password", "implicit")
            .scopes("read", "write", "openid")
            .secret("secret")
            .and()
            .withClient("html5")
            .authorizedGrantTypes("authorization_code", "password", "implicit")
            .scopes("read", "write", "openid")
            .secret("secret");
}
 
Example 30
Source Project: syhthems-platform   Source File: AuthorizationServerConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.withClientDetails(clientDetailsService)
                /*.withClient("syhthems-web")
                .secret(passwordEncoder.encode("sunriseydy-syhthems-web-secret"))
                .authorizedGrantTypes("password", "refresh_token")
                .scopes("web")
                .autoApprove(true)*/;
}