use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testNonBearerToken.
@Test
public void testNonBearerToken() throws Exception {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
token.setTokenType("MINE");
restTemplate.getOAuth2ClientContext().setAccessToken(token);
ClientHttpRequest http = restTemplate.createRequest(URI.create("https://nowhere.com/api/crap"), HttpMethod.GET);
String auth = http.getHeaders().getFirst("Authorization");
assertTrue(auth.startsWith("MINE "));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testDoubleEncodingOfAccessTokenValue.
/**
* tests encoding of access token value passed in protected requests ref: SECOAUTH-90
*/
@Test
public void testDoubleEncodingOfAccessTokenValue() throws Exception {
// try with fictitious token value with many characters to encode
OAuth2AccessToken token = new DefaultOAuth2AccessToken("1 qI+x:y=z");
// System.err.println(UriUtils.encodeQueryParam(token.getValue(), "UTF-8"));
URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search"), token);
assertEquals("https://graph.facebook.com/search?bearer_token=1+qI%2Bx%3Ay%3Dz", appended.toString());
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class OAuth2ClientAuthenticationProcessingFilterTests method testAuthentication.
@Test
public void testAuthentication() throws Exception {
filter.setRestTemplate(restTemplate);
filter.setTokenServices(tokenServices);
Mockito.when(restTemplate.getAccessToken()).thenReturn(new DefaultOAuth2AccessToken("FOO"));
Set<String> scopes = new HashSet<String>();
scopes.addAll(Arrays.asList("read", "write"));
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("client", false, scopes);
this.authentication = new OAuth2Authentication(storedOAuth2Request, null);
Mockito.when(tokenServices.loadAuthentication("FOO")).thenReturn(authentication);
Authentication authentication = filter.attemptAuthentication(new MockHttpServletRequest(), null);
assertEquals(this.authentication, authentication);
Mockito.verify(restTemplate, Mockito.times(1)).getAccessToken();
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class ResourceServerConfigurationTests method init.
@Before
public void init() {
token = new DefaultOAuth2AccessToken("FOO");
ClientDetails client = new BaseClientDetails("client", null, "read", "client_credentials", "ROLE_CLIENT");
authentication = new OAuth2Authentication(new TokenRequest(null, "client", null, "client_credentials").createOAuth2Request(client), null);
tokenStore.clear();
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JaxbOAuth2AccessTokenMessageConverterTests method before.
@Before
public void before() throws Exception {
converter = new JaxbOAuth2AccessTokenMessageConverter();
accessToken = new DefaultOAuth2AccessToken("SlAV32hkKG");
accessToken.setExpiration(expiration);
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("8xLOxBtZp8"));
}
Aggregations