use of org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class DefaultOAuth2RequestAuthenticatorTests method addsAccessToken.
@Test
public void addsAccessToken() {
context.setAccessToken(new DefaultOAuth2AccessToken("FOO"));
BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
authenticator.authenticate(resource, context, request);
String header = request.getHeaders().getFirst("Authorization");
assertEquals("bearer FOO", header);
}
use of org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class DefaultOAuth2RequestAuthenticatorTests method missingAccessToken.
@Test(expected = AccessTokenRequiredException.class)
public void missingAccessToken() {
BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
authenticator.authenticate(resource, new DefaultOAuth2ClientContext(), request);
}
use of org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method open.
@Before
public void open() throws Exception {
resource = new BaseOAuth2ProtectedResourceDetails();
// Facebook and older specs:
resource.setTokenName("bearer_token");
restTemplate = new OAuth2RestTemplate(resource);
restTemplate.setAccessTokenProvider(accessTokenProvider);
request = Mockito.mock(ClientHttpRequest.class);
headers = new HttpHeaders();
Mockito.when(request.getHeaders()).thenReturn(headers);
ClientHttpResponse response = Mockito.mock(ClientHttpResponse.class);
HttpStatus statusCode = HttpStatus.OK;
Mockito.when(response.getStatusCode()).thenReturn(statusCode);
Mockito.when(request.execute()).thenReturn(response);
}
use of org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails in project spring-boot by spring-projects.
the class UserInfoTokenServices method getMap.
@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Getting user info from: " + path);
}
try {
OAuth2RestOperations restTemplate = this.restTemplate;
if (restTemplate == null) {
BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
resource.setClientId(this.clientId);
restTemplate = new OAuth2RestTemplate(resource);
}
OAuth2AccessToken existingToken = restTemplate.getOAuth2ClientContext().getAccessToken();
if (existingToken == null || !accessToken.equals(existingToken.getValue())) {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(accessToken);
token.setTokenType(this.tokenType);
restTemplate.getOAuth2ClientContext().setAccessToken(token);
}
return restTemplate.getForEntity(path, Map.class).getBody();
} catch (Exception ex) {
this.logger.warn("Could not fetch user details: " + ex.getClass() + ", " + ex.getMessage());
return Collections.<String, Object>singletonMap("error", "Could not fetch user details");
}
}
use of org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails in project spring-security-oauth by spring-projects.
the class AbstractIntegrationTests method fixPaths.
@BeforeOAuth2Context
public void fixPaths() {
String prefix = server.getServletPrefix();
http.setPort(port);
http.setPrefix(prefix);
BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) context.getResource();
resource.setAccessTokenUri(http.getUrl(tokenPath()));
if (resource instanceof AbstractRedirectResourceDetails) {
((AbstractRedirectResourceDetails) resource).setUserAuthorizationUri(http.getUrl(authorizePath()));
}
if (resource instanceof ImplicitResourceDetails) {
resource.setAccessTokenUri(http.getUrl(authorizePath()));
}
if (resource instanceof ResourceOwnerPasswordResourceDetails) {
((ResourceOwnerPasswordResourceDetails) resource).setUsername(security.getUser().getName());
((ResourceOwnerPasswordResourceDetails) resource).setPassword(security.getUser().getPassword());
}
}
Aggregations