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

The following are top voted examples for showing how to use org.springframework.security.oauth2.provider.ClientDetailsService. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: joyrest   File: InMemoryOAuthConfiguration.java   Source Code and License 8 votes vote down vote up
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
  }
 
Example 2
Project: metagraph-auth   File: AuthorizationServerConfigurer.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 3
Project: Android_watch_magpie   File: OAuth2SecurityConfiguration.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 4
Project: tcloud-microservices   File: AuthServiceApplication.java   Source Code and License 6 votes vote down vote up
@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)));
}
 
Example 5
Project: contestparser   File: OAuth2AutoConfigurationTests.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 6
Project: magpie   File: OAuth2SecurityConfiguration.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 7
Project: oauth-client-master   File: AbstractTestDefaultTokenServices.java   Source Code and License 6 votes vote down vote up
@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()));
}
 
Example 8
Project: oauth-client-master   File: JwtTokenServicesTests.java   Source Code and License 6 votes vote down vote up
@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()));
}
 
Example 9
Project: oauth-client-master   File: DefaultTokenServicesWithInMemoryTests.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 10
Project: oauth-client-master   File: AuthorizationEndpointTests.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 11
Project: spring-security-oauth2-boot   File: OAuth2AutoConfigurationTests.java   Source Code and License 5 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 12
Project: spring-auth-example   File: CustomResourceOwnerPasswordTokenGranter.java   Source Code and 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 13
Project: spring-auth-example   File: CustomResourceOwnerPasswordTokenGranter.java   Source Code and 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 14
Project: Android_watch_magpie   File: ClientAndUserDetailsService.java   Source Code and License 5 votes vote down vote up
public ClientAndUserDetailsService(ClientDetailsService clients,
		UserDetailsService users) {
	super();
	clients_ = clients;
	users_ = users;
	clientDetailsWrapper_ = new ClientDetailsUserDetailsService(clients_);
}
 
Example 15
Project: graviteeio-access-management   File: CustomAuthorizationServerSecurityConfiguration.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 16
Project: tcloud-microservices   File: AuthServiceApplication.java   Source Code and License 5 votes vote down vote up
@Autowired
public AuthorizationServerConfig(AuthenticationManager authenticationManager,
                                 ClientDetailsService clientDetailsService, UserDetailsService userDetailsService) {
    this.authenticationManager = authenticationManager;
    this.clientDetailsService = clientDetailsService;
    this.userDetailsService = userDetailsService;
}
 
Example 17
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: OAuth2AutoConfigurationTests.java   Source Code and License 5 votes vote down vote up
@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();
}
 
Example 18
Project: oyd-pia   File: PluginMapper.java   Source Code and License 5 votes vote down vote up
public PluginUrlSetter(ServerDetection detection, ProcessRepository processRepository,ClientDetailsService clientDetailsService,PluginDTO pluginDTO) {
    this.serverDetection = detection;
    this.processRepository = processRepository;
    this.clientDetailsService = clientDetailsService;

    this.pluginDTO = pluginDTO;
}
 
Example 19
Project: spring-boot-concourse   File: OAuth2AutoConfigurationTests.java   Source Code and License 5 votes vote down vote up
@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();
}
 
Example 20
Project: auth-server   File: LessStrictRedirectUriAuthorizationCodeTokenGranter.java   Source Code and 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 21
Project: osiam   File: LessStrictRedirectUriAuthorizationCodeTokenGranter.java   Source Code and 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 22
Project: joyrest   File: JdbcClientDetailsServiceConfigurer.java   Source Code and License 5 votes vote down vote up
@Override
protected ClientDetailsService performBuild() {
    JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
    clientDetailsService.setPasswordEncoder(passwordEncoder);
    clientDetails.forEach(clientDetailsService::addClientDetails);
    return clientDetailsService;
}
 
Example 23
Project: joyrest   File: OAuth2Initializer.java   Source Code and License 5 votes vote down vote up
private TokenGranter compositeTokenGranter(final ClientDetailsService clientService,
                                           final AuthenticationManager manager,
                                           final DefaultTokenServices tokenServices,
                                           final OAuth2RequestFactory requestFactory,
                                           final AuthorizationCodeServices authorizationCodeServices) {

    List<TokenGranter> granters = new ArrayList<>();
    granters.add(new ClientCredentialsTokenGranter(tokenServices, clientService, requestFactory));
    granters.add(new ImplicitTokenGranter(tokenServices, clientService, requestFactory));
    granters.add(new ResourceOwnerPasswordTokenGranter(manager, tokenServices, clientService, requestFactory));
    granters.add(new RefreshTokenGranter(tokenServices, clientService, requestFactory));
    granters.add(new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientService, requestFactory));
    return new CompositeTokenGranter(granters);
}
 
Example 24
Project: joyrest   File: TokenEndpoint.java   Source Code and License 5 votes vote down vote up
public TokenEndpoint(AuthenticationManager authenticationManager,
                     ClientDetailsService clientDetailsService, TokenGranter tokenGranter) {
    this.clientDetailsService = clientDetailsService;
    this.tokenGranter = tokenGranter;
    this.basicAuthenticator = new BasicAuthenticator(authenticationManager);
    this.requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService);
}
 
Example 25
Project: joyrest   File: AuthorizationEndpoint.java   Source Code and License 5 votes vote down vote up
public AuthorizationEndpoint(AuthorizationCodeServices authorizationCodeServices,
                             ClientDetailsService clientDetailsService,
                             TokenGranter tokenGranter,
                          TokenStoreUserApprovalHandler userApprovalHandler,
                             OAuth2RequestFactory requestFactory) {

 this.userApprovalHandler = userApprovalHandler;
    this.authorizationCodeServices = authorizationCodeServices;
    this.clientDetailsService = clientDetailsService;
    this.tokenGranter = tokenGranter;
    this.requestFactory = requestFactory;
}
 
Example 26
Project: mobilecloud-15   File: ClientAndUserDetailsService.java   Source Code and License 5 votes vote down vote up
public ClientAndUserDetailsService(ClientDetailsService clients,
		UserDetailsService users) {
	super();
	clients_ = clients;
	users_ = users;
	clientDetailsWrapper_ = new ClientDetailsUserDetailsService(clients_);
}
 
Example 27
Project: EDU_SYZT   File: UserController.java   Source Code and License 5 votes vote down vote up
@Autowired
public void setReviewService(UserService userService, DefaultTokenServices tokenServices,
                             PasswordEncoder passwordEncoder,
                             ClientDetailsService clientDetailsService,
                             BookshelfService bookshelfService) {
    this.userService = userService;
    this.tokenServices = tokenServices;
    this.passwordEncoder = passwordEncoder;
    this.clientDetailsService = clientDetailsService;
    this.bookshelfService = bookshelfService;
}
 
Example 28
Project: oauth2-provider   File: UserResource.java   Source Code and License 5 votes vote down vote up
@Autowired
public UserResource(final UserService userService, final VerificationTokenService verificationTokenService,
                    final DefaultTokenServices defaultTokenServices,
                    final PasswordEncoder passwordEncoder, ClientDetailsService clientDetailsService) {
    this.userService = userService;
    this.verificationTokenService = verificationTokenService;
    this.tokenServices = defaultTokenServices;
    this.passwordEncoder = passwordEncoder;
    this.clientDetailsService = clientDetailsService;
}
 
Example 29
Project: magpie   File: ClientAndUserDetailsService.java   Source Code and License 5 votes vote down vote up
public ClientAndUserDetailsService(ClientDetailsService clients,
		UserDetailsService users) {
	super();
	clients_ = clients;
	users_ = users;
	clientDetailsWrapper_ = new ClientDetailsUserDetailsService(clients_);
}
 
Example 30
Project: oauth-client-master   File: AbstractTokenGranter.java   Source Code and License 5 votes vote down vote up
protected AbstractTokenGranter(AuthorizationServerTokenServices tokenServices,
		ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, String grantType) {
	this.clientDetailsService = clientDetailsService;
	this.grantType = grantType;
	this.tokenServices = tokenServices;
	this.requestFactory = requestFactory;
}
 
Example 31
Project: oauth-client-master   File: InMemoryClientDetailsServiceConfigurer.java   Source Code and License 5 votes vote down vote up
@Override
public void init(AuthenticationManagerBuilder builder) throws Exception {
	Map<String, ClientDetails> clientDetails = new HashMap<String, ClientDetails>(clientBuilders.size());
	for (ClientBuilder clientDetailsBldr : clientBuilders) {
		clientDetails.put(clientDetailsBldr.clientId, clientDetailsBldr.build());
	}
	InMemoryClientDetailsService clientDetailsService = new InMemoryClientDetailsService();
	clientDetailsService.setClientDetailsStore(clientDetails);

	ClientDetailsUserDetailsService userDetailsService = new ClientDetailsUserDetailsService(clientDetailsService);
	builder.userDetailsService(userDetailsService);

	builder.setSharedObject(ClientDetailsService.class, clientDetailsService);
}
 
Example 32
Project: oauth-client-master   File: AbstractTestDefaultTokenServices.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 33
Project: oauth-client-master   File: JwtTokenServicesTests.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 34
Project: oauth-client-master   File: DefaultTokenServicesWithInMemoryTests.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 35
Project: OAuth-2.0-Cookbook   File: CustomAuthCodeTokenGranter.java   Source Code and 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 36
Project: OAuth-2.0-Cookbook   File: CustomAuthCodeTokenGranter.java   Source Code and 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 37
Project: OAuth-2.0-Cookbook   File: OAuth2Configuration.java   Source Code and License 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetailsService() {
    return new JdbcClientDetailsService(dataSource);
}
 
Example 38
Project: DAFramework   File: WebSecurityConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean
public ClientDetailsService jdbcClientDetailsService() {
	return new JdbcClientDetailsService(dataSource);
}
 
Example 39
Project: cloud   File: AuthorizationServerConfig.java   Source Code and License 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetails() {
	return new JdbcClientDetailsService(dataSource);
}
 
Example 40
Project: microservices-prototype   File: OAuthConfig.java   Source Code and License 4 votes vote down vote up
@Bean
public ClientDetailsService clientDetailsService() {
    return new JdbcClientDetailsService(dataSource);
}