Examples of ClientAccessToken


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

    @Test
    public void testSAML2BearerAuthenticationInterceptor() throws Exception {
        String address = "https://localhost:" + PORT + "/oauth2-auth/token";
        WebClient wc = createWebClientWithProps(address);
       
        ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
                                                               new CustomGrant());
        assertNotNull(at.getTokenKey());
    }
View Full Code Here

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

        throws IOException, WebApplicationException {
        Map<String, String> params = readJSONResponse(is);
        if (Map.class.isAssignableFrom(cls)) {
            return params;
        }
        ClientAccessToken token = OAuthClientUtils.fromMapToClientToken(params);
        if (token == null) {
            throw new WebApplicationException(500);
        } else {
            return token;
        }
View Full Code Here

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

public class OAuthJSONProviderTest extends Assert {

    @Test
    public void testWriteClientAccessToken() throws Exception {
        ClientAccessToken token = new ClientAccessToken("bearer", "1234");
        token.setExpiresIn(12345);
        token.setRefreshToken("5678");
        token.setApprovedScope("read");
        token.setParameters(Collections.singletonMap("my_parameter", "abc"));
       
        OAuthJSONProvider provider = new OAuthJSONProvider();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(token,
                         ClientAccessToken.class,
View Full Code Here

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

    @SuppressWarnings({
        "unchecked", "rawtypes"
    })
    public void doReadClientAccessToken(String response) 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("bearer", token.getTokenType());
        assertEquals("5678", token.getRefreshToken());
        assertEquals(12345, token.getExpiresIn());
        assertEquals("read", token.getApprovedScope());
        Map<String, String> extraParams = token.getParameters();
        assertEquals(1, extraParams.size());
        assertEquals("abc", extraParams.get("my_parameter"));
    }
View Full Code Here

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());
        if (writeOptionalParameters) {
            clientToken.setExpiresIn(serverToken.getLifetime());
            List<OAuthPermission> perms = serverToken.getScopes();
            if (!perms.isEmpty()) {
                clientToken.setApprovedScope(OAuthUtils.convertPermissionsToScope(perms));   
            }
            clientToken.setParameters(serverToken.getParameters());
        }
       
        //TODO: also set a refresh token if any
       
        // Return it to the client
View Full Code Here

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

            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

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

    }
   
    public static ClientAccessToken fromMapToClientToken(Map<String, String> map) {
        if (map.containsKey(OAuthConstants.ACCESS_TOKEN)
            && map.containsKey(OAuthConstants.ACCESS_TOKEN_TYPE)) {
            ClientAccessToken token = new ClientAccessToken(
                                          map.remove(OAuthConstants.ACCESS_TOKEN_TYPE),
                                          map.remove(OAuthConstants.ACCESS_TOKEN));
           
            String refreshToken = map.remove(OAuthConstants.REFRESH_TOKEN);
            if (refreshToken != null) {
                token.setRefreshToken(refreshToken);
            }
            String expiresInStr = map.remove(OAuthConstants.ACCESS_TOKEN_EXPIRES_IN);
            if (expiresInStr != null) {
                token.setExpiresIn(Long.valueOf(expiresInStr));
            }
            String scope = map.remove(OAuthConstants.SCOPE);
            if (scope != null) {
                token.setApprovedScope(scope);
            }
           
            token.setParameters(map);
            return token;
        } else {
            return null;
        }
    }
View Full Code Here

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

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

            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

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

    }
   
    public static ClientAccessToken fromMapToClientToken(Map<String, String> map) {
        if (map.containsKey(OAuthConstants.ACCESS_TOKEN)
            && map.containsKey(OAuthConstants.ACCESS_TOKEN_TYPE)) {
            ClientAccessToken token = new ClientAccessToken(
                                          map.remove(OAuthConstants.ACCESS_TOKEN_TYPE),
                                          map.remove(OAuthConstants.ACCESS_TOKEN));
           
            String refreshToken = map.remove(OAuthConstants.REFRESH_TOKEN);
            if (refreshToken != null) {
                token.setRefreshToken(refreshToken);
            }
            String expiresInStr = map.remove(OAuthConstants.ACCESS_TOKEN_EXPIRES_IN);
            if (expiresInStr != null) {
                token.setExpiresIn(Long.valueOf(expiresInStr));
            }
            String issuedAtStr = map.remove(OAuthConstants.ACCESS_TOKEN_ISSUED_AT);
            token.setIssuedAt(issuedAtStr != null ? Long.valueOf(issuedAtStr)
                                                  : System.currentTimeMillis() / 1000);
            String scope = map.remove(OAuthConstants.SCOPE);
            if (scope != null) {
                token.setApprovedScope(scope);
            }
           
            token.setParameters(map);
            return token;
        } else {
            return null;
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.