Package org.apache.cxf.rs.security.oauth2.common

Examples of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken


        if (serverToken == null) {
            return createErrorResponse(params, OAuthConstants.INVALID_GRANT);
        }
       
        // Extract the information to be of use for the client
        ClientAccessToken clientToken = new ClientAccessToken(serverToken.getTokenType(),
                                                              serverToken.getTokenKey());
        clientToken.setRefreshToken(serverToken.getRefreshToken());
        if (isWriteOptionalParameters()) {
            clientToken.setExpiresIn(serverToken.getExpiresIn());
            List<OAuthPermission> perms = serverToken.getScopes();
            if (!perms.isEmpty()) {
                clientToken.setApprovedScope(OAuthUtils.convertPermissionsToScope(perms));   
            }
            clientToken.setParameters(serverToken.getParameters());
        }
       
        // Return it to the client
        return Response.ok(clientToken)
                       .header(HttpHeaders.CACHE_CONTROL, "no-store")
View Full Code Here


public class OAuthJSONProviderTest extends Assert {

    @Test
    public void testWriteBearerClientAccessToken() throws Exception {
        ClientAccessToken token = new ClientAccessToken(OAuthConstants.BEARER_TOKEN_TYPE, "1234");
        token.setExpiresIn(12345);
        token.setRefreshToken("5678");
        token.setApprovedScope("read");
        token.setParameters(Collections.singletonMap("my_parameter", "http://abc"));
       
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(token,
                         ClientAccessToken.class,
                         ClientAccessToken.class,
                         new Annotation[]{},
                         MediaType.APPLICATION_JSON_TYPE,
                         new MetadataMap<String, Object>(),
                         bos);
        doReadClientAccessToken(bos.toString(), OAuthConstants.BEARER_TOKEN_TYPE, token.getParameters());
    }
View Full Code Here

   
    public ClientAccessToken doReadClientAccessToken(String response,
                                        String expectedTokenType,
                                        Map<String, String> expectedParams) throws Exception {
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ClientAccessToken token = (ClientAccessToken)provider.readFrom((Class)ClientAccessToken.class,
                          ClientAccessToken.class,
                          new Annotation[]{},
                          MediaType.APPLICATION_JSON_TYPE,
                          new MetadataMap<String, String>(),
                          new ByteArrayInputStream(response.getBytes()));
        assertEquals("1234", token.getTokenKey());
        assertEquals(expectedTokenType, token.getTokenType());
        assertEquals("5678", token.getRefreshToken());
        assertEquals(12345, token.getExpiresIn());
        assertEquals("read", token.getApprovedScope());
        Map<String, String> extraParams = token.getParameters();
        if (expectedParams != null) {
            assertEquals(expectedParams, extraParams);
        }
        assertEquals("http://abc", extraParams.get("my_parameter"));
       
View Full Code Here

       
    }
   
    @Test
    public void testWriteHawkClientAccessToken() throws Exception {
        ClientAccessToken token = new ClientAccessToken("hawk", "1234");
        token.setExpiresIn(12345);
        token.setRefreshToken("5678");
        token.setApprovedScope("read");
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put(OAuthConstants.HAWK_TOKEN_KEY, "test_mac_secret");
        params.put(OAuthConstants.HAWK_TOKEN_ALGORITHM, HmacUtils.ALGO_HMAC_SHA_1);
        params.put("my_parameter", "http://abc");
       
        token.setParameters(params);
       
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {},
                         MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
View Full Code Here

    public void testReadHawkClientAccessToken() throws Exception {
        String response = "{" + "\"access_token\":\"1234\"," + "\"token_type\":\"hawk\","
            + "\"refresh_token\":\"5678\"," + "\"expires_in\":12345," + "\"scope\":\"read\","
            + "\"secret\":\"adijq39jdlaska9asud\"," + "\"algorithm\":\"hmac-sha-256\","
            + "\"my_parameter\":\"http://abc\"" + "}";
        ClientAccessToken macToken = doReadClientAccessToken(response, "hawk", null);
        assertEquals("adijq39jdlaska9asud",
                     macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_KEY));
        assertEquals("hmac-sha-256",
                     macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_ALGORITHM));
    }
View Full Code Here

public class OAuthJSONProviderTest extends Assert {

    @Test
    public void testWriteBearerClientAccessToken() throws Exception {
        ClientAccessToken token = new ClientAccessToken(OAuthConstants.BEARER_TOKEN_TYPE, "1234");
        token.setExpiresIn(12345);
        token.setRefreshToken("5678");
        token.setApprovedScope("read");
        token.setParameters(Collections.singletonMap("my_parameter", "http://abc"));
       
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(token,
                         ClientAccessToken.class,
                         ClientAccessToken.class,
                         new Annotation[]{},
                         MediaType.APPLICATION_JSON_TYPE,
                         new MetadataMap<String, Object>(),
                         bos);
        doReadClientAccessToken(bos.toString(), OAuthConstants.BEARER_TOKEN_TYPE, token.getParameters());
    }
View Full Code Here

   
    public ClientAccessToken doReadClientAccessToken(String response,
                                        String expectedTokenType,
                                        Map<String, String> expectedParams) throws Exception {
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ClientAccessToken token = (ClientAccessToken)provider.readFrom((Class)ClientAccessToken.class,
                          ClientAccessToken.class,
                          new Annotation[]{},
                          MediaType.APPLICATION_JSON_TYPE,
                          new MetadataMap<String, String>(),
                          new ByteArrayInputStream(response.getBytes()));
        assertEquals("1234", token.getTokenKey());
        assertEquals(expectedTokenType, token.getTokenType());
        assertEquals("5678", token.getRefreshToken());
        assertEquals(12345, token.getExpiresIn());
        assertEquals("read", token.getApprovedScope());
        Map<String, String> extraParams = token.getParameters();
        if (expectedParams != null) {
            assertEquals(expectedParams, extraParams);
        }
        assertEquals("http://abc", extraParams.get("my_parameter"));
       
View Full Code Here

       
    }
   
    @Test
    public void testWriteHawkClientAccessToken() throws Exception {
        ClientAccessToken token = new ClientAccessToken("hawk", "1234");
        token.setExpiresIn(12345);
        token.setRefreshToken("5678");
        token.setApprovedScope("read");
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put(OAuthConstants.HAWK_TOKEN_KEY, "test_mac_secret");
        params.put(OAuthConstants.HAWK_TOKEN_ALGORITHM, OAuthConstants.HMAC_ALGO_SHA_1);
        params.put("my_parameter", "http://abc");
       
        token.setParameters(params);
       
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {},
                         MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
View Full Code Here

    public void testReadHawkClientAccessToken() throws Exception {
        String response = "{" + "\"access_token\":\"1234\"," + "\"token_type\":\"hawk\","
            + "\"refresh_token\":\"5678\"," + "\"expires_in\":12345," + "\"scope\":\"read\","
            + "\"secret\":\"adijq39jdlaska9asud\"," + "\"algorithm\":\"hmac-sha-256\","
            + "\"my_parameter\":\"http://abc\"" + "}";
        ClientAccessToken macToken = doReadClientAccessToken(response, "hawk", null);
        assertEquals("adijq39jdlaska9asud",
                     macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_KEY));
        assertEquals("hmac-sha-256",
                     macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_ALGORITHM));
    }
View Full Code Here

            map = new OAuthJSONProvider().readJSONResponse((InputStream)response.getEntity());
        } catch (IOException ex) {
            throw new ClientWebApplicationException(ex);
        }
        if (200 == response.getStatus()) {
            ClientAccessToken token = fromMapToClientToken(map);
            if (token == null) {
                throw new OAuthServiceException(OAuthConstants.SERVER_ERROR);
            } else {
                return token;
            }
View Full Code Here

TOP

Related Classes of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.