Example usage for org.springframework.security.oauth2.common DefaultOAuth2AccessToken DefaultOAuth2AccessToken

List of usage examples for org.springframework.security.oauth2.common DefaultOAuth2AccessToken DefaultOAuth2AccessToken

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common DefaultOAuth2AccessToken DefaultOAuth2AccessToken.

Prototype

public DefaultOAuth2AccessToken(OAuth2AccessToken accessToken) 

Source Link

Document

Copy constructor for access token.

Usage

From source file:com.orange.clara.cloud.services.sandbox.ElpaasoSandboxServiceApplication.java

@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public OAuth2AccessToken getOAuth2AccessToken() {
    OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext()
            .getAuthentication();/*from w  w  w.ja  v  a2s  .c  om*/
    final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();
    return new DefaultOAuth2AccessToken(details.getTokenValue());
}

From source file:org.icgc.dcc.metadata.client.config.ClientConfig.java

@Bean
public RestTemplate restTemplate(@Value("${accessToken}") String accessToken) {
    val details = new AuthorizationCodeResourceDetails();
    val clientContext = new DefaultOAuth2ClientContext(new DefaultOAuth2AccessToken(accessToken));
    val restTemplate = new OAuth2RestTemplate(details, clientContext);

    return restTemplate;
}

From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java

@Test
public void testListTokensForOAuth2User() throws Exception {
    Mockito.when(tokenServices.findTokensByUserName("marissa"))
            .thenReturn(Collections.<OAuth2AccessToken>singleton(new DefaultOAuth2AccessToken("FOO")));
    Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("marissa",
            new OAuth2Authentication(authorizationRequest, new TestingAuthenticationToken("marissa", "")),
            false);//from  w w  w . ja v  a 2  s .  co m
    assertEquals(1, tokens.size());
    assertNotNull(tokens.iterator().next().getAdditionalInformation().get(JwtTokenEnhancer.TOKEN_ID));
}

From source file:com.springsource.greenhouse.settings.SettingsControllerTest.java

@Before
public void setup() {
    db = new GreenhouseTestDatabaseBuilder().member().connectedApp().testData(getClass()).getDatabase();
    tokenStore = new JdbcTokenStore(db);
    jdbcTemplate = new JdbcTemplate(db);
    controller = new SettingsController(tokenStore, jdbcTemplate);

    AuthorizationRequest authorizationRequest = new DefaultAuthorizationRequest(
            "a08318eb478a1ee31f69a55276f3af64", Arrays.asList("read", "write"));
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken("1", "whateveryouwantittobe");
    tokenStore.storeAccessToken(new DefaultOAuth2AccessToken("authme"),
            new OAuth2Authentication(authorizationRequest, userAuthentication));
    assertEquals(1, tokenStore.findTokensByUserName("1").size());
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStoreTests.java

@Test
public void testFindAccessTokensByUserName() {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(
            RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
    OAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");

    getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);

    Collection<OAuth2AccessToken> actualOAuth2AccessTokens = getTokenStore().findTokensByUserName("test2");
    assertEquals(1, actualOAuth2AccessTokens.size());
}

From source file:com.katropine.oauth.LogoutImpl.java

public void removeaccess(HttpServletRequest req) {

    String tokens = req.getHeader("Authorization");
    System.out.println(tokens);/*  w w w  .  j av  a2 s .  co  m*/
    String value = tokens.substring(tokens.indexOf(" ")).trim();
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(value);
    System.out.println(token);
    tokenstore.removeAccessToken(value);
    System.out.println("\n\tAccess Token Removed Successfully!!!!!!!!");

}

From source file:org.cloudfoundry.maven.LoginAndLogoutTest.java

@Test
public void tokenSavedOnLogin() throws MojoExecutionException, IOException, URISyntaxException {
    DefaultOAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("refreshtoken");
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("accesstoken");
    accessToken.setRefreshToken(refreshToken);
    when(client.login()).thenReturn(accessToken);

    HashMap<String, Object> info = new HashMap<String, Object>(1);
    info.put("version", "2");
    when(client.getCloudInfo()).thenReturn(new CloudInfo(info));

    Date date = new Date();
    CloudOrganization org = new CloudOrganization(new CloudEntity.Meta(UUID.randomUUID(), date, date),
            "my-org");
    CloudSpace space = new CloudSpace(new CloudEntity.Meta(UUID.randomUUID(), date, date), "my-space", org);
    List<CloudSpace> spaces = Arrays.asList(space);
    when(client.getSpaces()).thenReturn(spaces);

    login.doExecute();// www.  j a va  2 s.  co m

    assertEquals(cloudFoundryMojo.retrieveToken().getValue(), "accesstoken");

    logout.doExecute();

    try {
        cloudFoundryMojo.retrieveToken();
        fail();
    } catch (MojoExecutionException e) {
        assertTrue(e.getMessage().contains("Can not authenticate to target"));
    }
}

From source file:io.jmnarloch.spring.cloud.feign.OAuth2HttpClientTest.java

@Test
public void authenticate() {

    // given/*from   w  w  w. j  a v  a2 s .co m*/
    final String token = UUID.randomUUID().toString();
    oauth2ClientContext.setAccessToken(new DefaultOAuth2AccessToken(token));

    // when
    final ResponseEntity response = authenticationClient.authenticate();

    // then
    assertNotNull(response);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue(response.getHeaders().containsKey("Authorization"));
    assertEquals(token, response.getHeaders().getFirst("Authorization").split(" ")[1]);
}

From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java

@Test
public void testListTokensForOAuth2UserWithClientId() throws Exception {
    Mockito.when(tokenServices.findTokensByUserName("marissa"))
            .thenReturn(Collections.<OAuth2AccessToken>singleton(new DefaultOAuth2AccessToken("FOO")));
    Mockito.when(tokenServices.getClientId("FOO")).thenReturn("foo");
    Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("marissa",
            new OAuth2Authentication(authorizationRequest, new TestingAuthenticationToken("marissa", "")),
            false);/*from ww  w . jav a2  s  .c  o  m*/
    assertEquals(1, tokens.size());
    assertNotNull(tokens.iterator().next().getAdditionalInformation().get(JwtTokenEnhancer.TOKEN_ID));
}

From source file:ru.ttk.baloo.rest.security.oauth.Logout.java

private void removeAccess(HttpServletRequest httpServletRequest) {
    if (httpServletRequest != null) {
        String bearerAndToken = httpServletRequest.getHeader("Authorization");
        LOG.info("bearerAndToken:" + bearerAndToken);

        if (StringUtils.isNotBlank(bearerAndToken)
                && bearerAndToken.length() >= OAUTH_HEADER_VALUE_BEARER_PLUS_SPACE.length()) {
            if (bearerAndToken.contains(OAUTH_HEADER_VALUE_BEARER_PLUS_SPACE)) {
                String extractedToken = bearerAndToken
                        .substring(bearerAndToken.indexOf(OAUTH_HEADER_VALUE_BEARER_PLUS_SPACE)
                                + OAUTH_HEADER_VALUE_BEARER_PLUS_SPACE.length())
                        .trim();/*from w w w  .j a va 2s. c  o m*/

                if (StringUtils.isNotBlank(extractedToken) && extractedToken.length() > 0) {
                    DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(extractedToken);
                    if (this.getTokenStore() != null) {
                        this.getTokenStore().removeAccessToken(oAuth2AccessToken);
                        LOG.info("Access OAuth token removed " + oAuth2AccessToken);
                    }
                }
            }
        }
    }
}