org.springframework.security.oauth2.common.AuthenticationScheme Java Examples

The following examples show how to use org.springframework.security.oauth2.common.AuthenticationScheme. 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: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public AuthorizationCodeResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);

    return resourceDetails;
}
 
Example #2
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    //@formatter:off
    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
Example #3
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails authorizationCode() {
    AuthorizationCodeResourceDetails resourceDetails = new AuthorizationCodeResourceDetails();

    //@formatter:off
    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri(("http://localhost:9000/callback"));
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
Example #4
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
    //@formatter:off
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();

details.setId("oauth2server");
details.setTokenName("oauth_token");
details.setClientId("clientadmin");
details.setClientSecret("123");
details.setAccessTokenUri("http://localhost:8080/oauth/token");
details.setScope(Arrays.asList("admin"));

details.setClientAuthenticationScheme(AuthenticationScheme.header);
//@formatter:on

    return details;
}
 
Example #5
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
    //@formatter:off
    ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();

    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setClientSecret("123456");
    resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
    resourceDetails.setScope(Arrays.asList("read_profile"));

    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
    //@formatter:on

    return resourceDetails;
}
 
Example #6
Source File: ClientConfiguration.java    From OAuth-2.0-Cookbook with MIT License 6 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails implicitResourceDetails() {
    ImplicitResourceDetails resourceDetails = new ImplicitResourceDetails();

    //@formatter:off
    resourceDetails.setId("oauth2server");
    resourceDetails.setTokenName("oauth_token");
    resourceDetails.setClientId("clientapp");
    resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
    resourceDetails.setScope(Arrays.asList("read_profile"));
    resourceDetails.setPreEstablishedRedirectUri("http://localhost:9000/callback");
    resourceDetails.setUseCurrentUri(false);
    resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.query);
    //@formatter:on

    return resourceDetails;
}
 
Example #7
Source File: Oauth2ClientRestTemplate.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 该方式没有实验成功,设置为 Deprecated!
 * <p>
 * 演示 grant_type=implicit 时,获取资源的方法
 *
 * @param client_id
 * @param client_secret     取决于 AuthorizationServer 设置,如果 client 设置了secret,则此项参数为必需,否则可以没有
 * @param authorization_uri
 * @param access_token_uri
 * @param scope
 * @return
 */
@Deprecated
public OAuth2RestOperations implicitResourceRestTemplate(String client_id, String client_secret, String authorization_uri, String access_token_uri, String... scope) {

    // 防止 url 写错
    if (!authorization_uri.contains("authorize"))
        throw new RuntimeException("uri is wrong :  authorization_uri" + authorization_uri);

    ImplicitResourceDetails details = new ImplicitResourceDetails();
    details.setId("2");
    details.setClientId(client_id);
    if (client_secret != null && !client_secret.isEmpty())
        details.setClientSecret(client_secret);
    details.setAccessTokenUri(authorization_uri);
    details.setClientAuthenticationScheme(AuthenticationScheme.header);
    details.setUseCurrentUri(true);
    details.setScope(Arrays.asList(scope));
    // return restTemplate;
    return new OAuth2RestTemplate(details, oAuth2ClientContext);
}
 
Example #8
Source File: OpenRestTemplate.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 构建网关Oauth2 password方式请求
 *
 * @param clientId
 * @param clientSecret
 * @param accessTokenUri
 * @param username
 * @param password
 * @return
 */
public OAuth2RestTemplate buildOAuth2PasswordRequest(String clientId, String clientSecret, String accessTokenUri, String username, String password) {
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setUsername(username);
    resource.setPassword(password);
    resource.setClientId(clientId);
    resource.setClientSecret(clientSecret);
    resource.setAccessTokenUri(accessTokenUri);
    resource.setAuthenticationScheme(AuthenticationScheme.form);
    resource.setGrantType("password");
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource);
    return restTemplate;
}
 
Example #9
Source File: OAuth2FeignAutoConfiguration.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
/**
 * Resource details client credentials resource details.
 *
 * @return the client credentials resource details
 */
@Bean("resourceOwnerPasswordResourceDetails")
public ClientCredentialsResourceDetails resourceDetails() {
    ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
    details.setAccessTokenUri(oauth2ClientProperties.getAccessTokenUri());
    details.setClientId(oauth2ClientProperties.getClientId());
    details.setClientSecret(oauth2ClientProperties.getClientSecret());
    details.setClientAuthenticationScheme(AuthenticationScheme.header);
    details.setScope(!CollectionUtils.isEmpty(oauth2ClientProperties.getScopes()) ? oauth2ClientProperties.getScopes() : Collections.singletonList("app"));

    return details;
}
 
Example #10
Source File: OAuth2FeignAutoConfiguration.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * Resource details client credentials resource details.
 *
 * @return the client credentials resource details
 */
@Bean("paascloudClientCredentialsResourceDetails")
public ClientCredentialsResourceDetails resourceDetails() {
	ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
	details.setId(oauth2ClientProperties.getId());
	details.setAccessTokenUri(oauth2ClientProperties.getAccessTokenUrl());
	details.setClientId(oauth2ClientProperties.getClientId());
	details.setClientSecret(oauth2ClientProperties.getClientSecret());
	details.setAuthenticationScheme(AuthenticationScheme.valueOf(oauth2ClientProperties.getClientAuthenticationScheme()));
	return details;
}
 
Example #11
Source File: OAuthClient.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private OAuth2ProtectedResourceDetails getResourceDetails(String username, String password, String clientId, String clientSecret) {
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setUsername(username);
    resource.setPassword(password);

    resource.setClientId(clientId);
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(authorizationUrl + "/oauth/token");

    return resource;
}
 
Example #12
Source File: FacebookConfiguration.java    From OAuth-2.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public OAuth2ProtectedResourceDetails resourceDetails() {
    AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
    details.setClientId(properties.getClientId());
    details.setClientSecret(properties.getClientSecret());
    details.setUserAuthorizationUri(properties.getAppAuthorizationUri());
    details.setAccessTokenUri(properties.getAppTokenUri());
    details.setPreEstablishedRedirectUri(properties.getRedirectUri());
    details.setScope(Arrays.asList("email", "public_profile"));
    details.setClientAuthenticationScheme(AuthenticationScheme.query);
    details.setUseCurrentUri(false);
    return details;
}
 
Example #13
Source File: AbstractOperationTest.java    From uaa-java-client with Apache License 2.0 5 votes vote down vote up
protected ClientCredentialsResourceDetails getDefaultClientCredentials() {

		ClientCredentialsResourceDetails credentials = new ClientCredentialsResourceDetails();
		credentials.setAccessTokenUri(UAA_BASE_URL + "/oauth/token");
		credentials.setClientAuthenticationScheme(AuthenticationScheme.header);
		credentials.setClientId("admin");
		credentials.setClientSecret("adminsecret");

		return credentials;
	}
 
Example #14
Source File: IHealthShim.java    From shimmer with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2ProtectedResourceDetails getResource() {

    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) super.getResource();
    resource.setAuthenticationScheme(AuthenticationScheme.none);
    return resource;
}