org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder Java Examples
The following examples show how to use
org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder.
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: AuthorizationServerConfiguration.java From fw-spring-cloud with Apache License 2.0 | 6 votes |
/** * 配置客户端一些信息 * * @param clients * @throws Exception */ @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { InMemoryClientDetailsServiceBuilder build = clients.inMemory(); if (ArrayUtil.isNotEmpty(securityProperties.getOauth().getClients())) { for (OAuth2ClientProperties config : securityProperties.getOauth().getClients()) { build.withClient(config.getClientId()) .secret(passwordEncoder.encode(config.getClientSecret())) .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds()) .refreshTokenValiditySeconds(60 * 60 * 24 * 15) .authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式 .redirectUris("http://www.baidu.com") .scopes("all"); } } }
Example #2
Source File: AuthorizationServerConfiguration.java From fw-spring-cloud with Apache License 2.0 | 6 votes |
/** * 配置客户端一些信息 * * @param clients * @throws Exception */ @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { InMemoryClientDetailsServiceBuilder build = clients.inMemory(); if (ArrayUtil.isNotEmpty(securityProperties.getOauth().getClients())) { for (OAuth2ClientProperties config : securityProperties.getOauth().getClients()) { build.withClient(config.getClientId()) .secret(passwordEncoder.encode(config.getClientSecret())) .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds()) .refreshTokenValiditySeconds(config.getRefreshTokenValiditySecond()) .authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式 .redirectUris(config.getRedirectUri()) .autoApprove(config.getAutoApprove())//设置自动认证 .scopes(config.getScope()); } } }
Example #3
Source File: SophiaAuthorizationServerConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 配置客户端详情信息,客户端详情信息在这里进行初始化,通过数据库来存储调取详情信息 */ @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 #4
Source File: RestClientDetailsServiceImpl.java From paascloud-master with Apache License 2.0 | 6 votes |
/** * Init. */ @PostConstruct public void init() { InMemoryClientDetailsServiceBuilder builder = new InMemoryClientDetailsServiceBuilder(); if (ArrayUtils.isNotEmpty(securityProperties.getOauth2().getClients())) { for (OAuth2ClientProperties client : securityProperties.getOauth2().getClients()) { builder.withClient(client.getClientId()) .secret(client.getClientSecret()) .authorizedGrantTypes("refresh_token", "password", "client_credentials") .accessTokenValiditySeconds(client.getAccessTokenValidateSeconds()) .refreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()) .scopes(client.getScope()); } } try { clientDetailsService = builder.build(); } catch (Exception e) { log.error("init={}", e.getMessage(), e); } }
Example #5
Source File: OAuth2AuthorizationServerConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 6 votes |
@Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder builder = clients.inMemory() .withClient(this.details.getClientId()); builder.secret(this.details.getClientSecret()) .resourceIds(this.details.getResourceIds().toArray(new String[0])) .authorizedGrantTypes(this.details.getAuthorizedGrantTypes().toArray(new String[0])) .authorities( AuthorityUtils.authorityListToSet(this.details.getAuthorities()).toArray(new String[0])) .scopes(this.details.getScope().toArray(new String[0])); if (this.details.getAutoApproveScopes() != null) { builder.autoApprove(this.details.getAutoApproveScopes().toArray(new String[0])); } if (this.details.getAccessTokenValiditySeconds() != null) { builder.accessTokenValiditySeconds(this.details.getAccessTokenValiditySeconds()); } if (this.details.getRefreshTokenValiditySeconds() != null) { builder.refreshTokenValiditySeconds(this.details.getRefreshTokenValiditySeconds()); } if (this.details.getRegisteredRedirectUri() != null) { builder.redirectUris(this.details.getRegisteredRedirectUri().toArray(new String[0])); } }
Example #6
Source File: AuthorizationServerConfig.java From springboot-seed with MIT License | 6 votes |
/** * 配置客户端 * * @param clients * @throws Exception */ @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { InMemoryClientDetailsServiceBuilder build = clients.inMemory(); if (ArrayUtils.isNotEmpty(oAuth2Properties.getClients())) { for (OAuth2ClientProperties config : oAuth2Properties.getClients()) { String password = passwordEncoder.encode(config.getClientSecret()); build.withClient(config.getClientId()) .secret(password) .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds()) .refreshTokenValiditySeconds(config.getRefreshTokenValiditySeconds()) .authorizedGrantTypes("refresh_token", "password", "authorization_code") .redirectUris(config.getRedirectUri()) .scopes("all"); } } }
Example #7
Source File: ApiBootAuthorizationMemoryServerAutoConfiguration.java From beihu-boot with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: ApiBootAuthorizationServerRedisAutoConfiguration.java From beihu-boot with Apache License 2.0 | 5 votes |
/** * 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 #9
Source File: Oauth2AuthorizationServerConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
private void configClient(ClientDetailsServiceConfigurer clients) throws Exception { InMemoryClientDetailsServiceBuilder builder = clients.inMemory(); for (BaseClientDetails client : clientDetails.getClient()) { ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder clientBuilder = builder.withClient(client.getClientId()); clientBuilder .secret(client.getClientSecret()) .resourceIds(client.getResourceIds().toArray(new String[0])) .authorizedGrantTypes(client.getAuthorizedGrantTypes().toArray(new String[0])) .authorities( AuthorityUtils.authorityListToSet(client.getAuthorities()) .toArray(new String[0])) .scopes(client.getScope().toArray(new String[0])); if (client.getAutoApproveScopes() != null) { clientBuilder.autoApprove( client.getAutoApproveScopes().toArray(new String[0])); } if (client.getAccessTokenValiditySeconds() != null) { clientBuilder.accessTokenValiditySeconds( client.getAccessTokenValiditySeconds()); } if (client.getRefreshTokenValiditySeconds() != null) { clientBuilder.refreshTokenValiditySeconds( client.getRefreshTokenValiditySeconds()); } if (client.getRegisteredRedirectUri() != null) { clientBuilder.redirectUris( client.getRegisteredRedirectUri().toArray(new String[0])); } } }
Example #10
Source File: ApiBootAuthorizationMemoryServerAutoConfiguration.java From api-boot with Apache License 2.0 | 5 votes |
/** * 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()) .refreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds())); }
Example #11
Source File: ApiBootAuthorizationServerRedisAutoConfiguration.java From api-boot with Apache License 2.0 | 5 votes |
/** * 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()) .refreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds())); }
Example #12
Source File: AuthServerConfig.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder builder = clients .inMemory().withClient(this.details.getClientId()); builder.secret(this.details.getClientSecret()) .resourceIds(this.details.getResourceIds().toArray(new String[0])) .authorizedGrantTypes( this.details.getAuthorizedGrantTypes().toArray(new String[0])) .authorities(AuthorityUtils .authorityListToSet(this.details.getAuthorities()) .toArray(new String[0])) .scopes(this.details.getScope().toArray(new String[0])); if (this.details.getAutoApproveScopes() != null) { builder.autoApprove( this.details.getAutoApproveScopes().toArray(new String[0])); } if (this.details.getAccessTokenValiditySeconds() != null) { builder.accessTokenValiditySeconds( this.details.getAccessTokenValiditySeconds()); } if (this.details.getRefreshTokenValiditySeconds() != null) { builder.refreshTokenValiditySeconds( this.details.getRefreshTokenValiditySeconds()); } if (this.details.getRegisteredRedirectUri() != null) { builder.redirectUris( this.details.getRegisteredRedirectUri().toArray(new String[0])); } }
Example #13
Source File: AuthServerConfig.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder builder = clients .inMemory().withClient(this.details.getClientId()); builder.secret(this.details.getClientSecret()) .resourceIds(this.details.getResourceIds().toArray(new String[0])) .authorizedGrantTypes( this.details.getAuthorizedGrantTypes().toArray(new String[0])) .authorities(AuthorityUtils .authorityListToSet(this.details.getAuthorities()) .toArray(new String[0])) .scopes(this.details.getScope().toArray(new String[0])); if (this.details.getAutoApproveScopes() != null) { builder.autoApprove( this.details.getAutoApproveScopes().toArray(new String[0])); } if (this.details.getAccessTokenValiditySeconds() != null) { builder.accessTokenValiditySeconds( this.details.getAccessTokenValiditySeconds()); } if (this.details.getRefreshTokenValiditySeconds() != null) { builder.refreshTokenValiditySeconds( this.details.getRefreshTokenValiditySeconds()); } if (this.details.getRegisteredRedirectUri() != null) { builder.redirectUris( this.details.getRegisteredRedirectUri().toArray(new String[0])); } }
Example #14
Source File: AuthorizationServerConfiguration.java From onetwo with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") protected void configInMemory(ClientDetailsServiceConfigurer clients) throws Exception{ Map<String, MemoryUser> clientUsers = oauth2Properties.getAuthorizationServer().getClientDetails(); InMemoryClientDetailsServiceBuilder inMemory = clients.inMemory(); clientUsers.forEach((user, config)->{ ClientBuilder cb = inMemory.withClient(user).secret(config.getSecret()); if(!LangUtils.isEmpty(config.getScopes())){ cb.scopes(config.getScopes()); } if(!LangUtils.isEmpty(config.getAuthorities())){ cb.authorities(config.getAuthorities()); } if(config.getAccessTokenValiditySeconds()!=null){ cb.accessTokenValiditySeconds(config.getAccessTokenValiditySeconds()); } cb.autoApprove(config.isAutoApprove()); if(!LangUtils.isEmpty(config.getAutoApproveScopes())){ cb.autoApprove(config.getAutoApproveScopes()); } if(!LangUtils.isEmpty(config.getResourceIds())){ cb.resourceIds(config.getResourceIds()); } if(!LangUtils.isEmpty(config.getAuthorizedGrantTypes())){ cb.authorizedGrantTypes(config.getAuthorizedGrantTypes()); } if(config.getRefreshTokenValiditySeconds()!=null){ cb.refreshTokenValiditySeconds(config.getRefreshTokenValiditySeconds()); } if(!LangUtils.isEmpty(config.getRegisteredRedirectUris())){ cb.redirectUris(config.getRegisteredRedirectUris()); } }); inMemory.build(); }
Example #15
Source File: OAuth2SecurityConfiguration.java From mobilecloud-15 with Apache License 2.0 | 4 votes |
/** * * 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 #16
Source File: ClientDetailsServiceConfigurer.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | votes |
public InMemoryClientDetailsServiceBuilder inMemory() throws Exception { return null; }