Search in sources :

Example 11 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class OrcidClientCredentialEndPointDelegatorTest method generateRefreshTokenTest.

@Test
public void generateRefreshTokenTest() {
    //Generate the access token
    SecurityContextTestUtils.setUpSecurityContextForClientOnly(CLIENT_ID_1, ScopePathType.ACTIVITIES_UPDATE, ScopePathType.READ_LIMITED);
    OrcidOauth2AuthoriziationCodeDetail authCode = createAuthorizationCode("code-1", CLIENT_ID_1, "http://www.APP-5555555555555555.com/redirect/oauth", true, "/activities/update");
    MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
    formParams.add("client_id", CLIENT_ID_1);
    formParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
    formParams.add("grant_type", "authorization_code");
    formParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
    formParams.add("code", authCode.getId());
    Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(null, formParams);
    assertNotNull(response);
    assertNotNull(response.getEntity());
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) response.getEntity();
    assertNotNull(token);
    assertTrue(!PojoUtil.isEmpty(token.getValue()));
    assertNotNull(token.getRefreshToken());
    assertTrue(!PojoUtil.isEmpty(token.getRefreshToken().getValue()));
    //Generate the refresh token
    MultivaluedMap<String, String> refreshTokenformParams = new MultivaluedMapImpl();
    refreshTokenformParams.add("client_id", CLIENT_ID_1);
    refreshTokenformParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
    refreshTokenformParams.add("grant_type", "refresh_token");
    refreshTokenformParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
    refreshTokenformParams.add("refresh_token", token.getRefreshToken().getValue());
    String authorization = "bearer " + token.getValue();
    Response refreshTokenResponse = orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, refreshTokenformParams);
    assertNotNull(refreshTokenResponse);
    assertNotNull(refreshTokenResponse.getEntity());
    DefaultOAuth2AccessToken refreshToken = (DefaultOAuth2AccessToken) refreshTokenResponse.getEntity();
    assertNotNull(refreshToken);
    assertTrue(!PojoUtil.isEmpty(refreshToken.getValue()));
    assertNotNull(refreshToken.getRefreshToken());
    assertTrue(!PojoUtil.isEmpty(refreshToken.getRefreshToken().getValue()));
    //Assert that both tokens expires at the same time
    assertEquals(token.getExpiration(), refreshToken.getExpiration());
    //Try to generate another one, and fail, because parent token was disabled
    try {
        orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, refreshTokenformParams);
    } catch (InvalidTokenException e) {
        assertTrue(e.getMessage().contains("Parent token is disabled"));
    }
}
Also used : Response(javax.ws.rs.core.Response) InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) OrcidOauth2AuthoriziationCodeDetail(org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class OauthHelper method getClientCredentialsAccessToken.

public String getClientCredentialsAccessToken(String clientId, String clientSecret, ScopePathType scope, APIRequestType apiRequerstType) throws JSONException {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("grant_type", "client_credentials");
    params.add("scope", scope.value());
    ClientResponse clientResponse = getResponse(params, apiRequerstType);
    assertEquals(200, clientResponse.getStatus());
    String body = clientResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    return accessToken;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Example 13 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project OpenAM by OpenRock.

the class DefaultEntityManagerImpl method searchEntity.

/**
     * Searches for entities from the data store.
     *
     * @param entityType the type of the entity
     * @param attributes the attributes to construct the search query
     *
     * @return a list of entity identifiers that satisfy the search criteria
     */
public List<String> searchEntity(String entityType, Map<String, String> attributes) {
    List<String> ids = new ArrayList<String>();
    if ((attributes == null) || (attributes.isEmpty())) {
        return ids;
    }
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    putAll(queryParams, attributes);
    if ((entityType != null) && (entityType.trim().length() != 0)) {
        queryParams.add(TOKEN_TYPE, entityType);
    }
    String resp = tokenResource.queryParams(queryParams).cookie(getCookie()).get(String.class);
    if (resp != null) {
        try {
            JSONArray ja = new JSONArray(resp);
            if (ja != null) {
                for (int i = 0; i < ja.length(); i++) {
                    String id = ja.getString(i);
                    ids.add(id);
                }
            }
        } catch (JSONException je) {
            Logger.getLogger(DefaultEntityManagerImpl.class.getName()).log(Level.INFO, null, je);
        }
    }
    return ids;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Example 14 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project cloudstack by apache.

the class MidoNetElement method deleteGuestNetworkRouters.

private void deleteGuestNetworkRouters(Network network) {
    String accountUuid = getAccountUuid(network);
    boolean isVpc = getIsVpc(network);
    long id = getRouterId(network, isVpc);
    Router tenantRouter = getGuestNetworkRouter(id, accountUuid, isVpc);
    // Delete any peer ports corresponding to this router
    for (Port peerPort : tenantRouter.getPeerPorts((new MultivaluedMapImpl()))) {
        if (peerPort != null && peerPort instanceof RouterPort) {
            RouterPort checkPort = (RouterPort) peerPort;
            if (checkPort.getType().equals("ExteriorRouter")) {
                checkPort.vifId(null).update();
            } else if (checkPort.getType().equals("InteriorRouter")) {
                checkPort.unlink();
            }
            checkPort.delete();
        } else if (peerPort != null && peerPort instanceof BridgePort) {
            BridgePort checkPort = (BridgePort) peerPort;
            if (checkPort.getType().equals("ExteriorBridge")) {
                checkPort.vifId(null).update();
            } else if (checkPort.getType().equals("InteriorBridge")) {
                checkPort.unlink();
            }
            checkPort.delete();
        }
    }
    if (tenantRouter != null) {
        // Remove all peer ports if any exist
        for (RouterPort p : tenantRouter.getPorts(new MultivaluedMapImpl())) {
            if (p.getType().equals("ExteriorRouter")) {
                // Set VIF ID to null
                p.vifId(null).update();
            // the port might have some chains associated with it
            }
            if (p.getType().equals("InteriorRouter")) {
                p.unlink();
            }
            // Delete port
            p.delete();
        }
        // Remove inbound and outbound filter chains
        String accountIdStr = String.valueOf(accountUuid);
        String routerName = getRouterName(isVpc, id);
        RuleChain pre = api.getChain(tenantRouter.getInboundFilterId());
        RuleChain preFilter = getChain(accountIdStr, routerName, RuleChainCode.TR_PREFILTER);
        RuleChain preNat = getChain(accountIdStr, routerName, RuleChainCode.TR_PRENAT);
        RuleChain post = api.getChain(tenantRouter.getOutboundFilterId());
        pre.delete();
        preFilter.delete();
        preNat.delete();
        post.delete();
        // Remove routes
        for (Route r : tenantRouter.getRoutes(new MultivaluedMapImpl())) {
            r.delete();
        }
        tenantRouter.delete();
    }
}
Also used : BridgePort(org.midonet.client.resource.BridgePort) RuleChain(org.midonet.client.resource.RuleChain) RouterPort(org.midonet.client.resource.RouterPort) BridgePort(org.midonet.client.resource.BridgePort) Port(org.midonet.client.resource.Port) Router(org.midonet.client.resource.Router) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) RouterPort(org.midonet.client.resource.RouterPort) Route(org.midonet.client.resource.Route)

Example 15 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project cloudstack by apache.

the class MidoNetElement method getChain.

protected RuleChain getChain(String networkId, String accountUuid, String routerName, RuleChainCode chainCode) {
    String chainName = getChainName(networkId, routerName, chainCode);
    MultivaluedMap findChain = new MultivaluedMapImpl();
    findChain.add("tenant_id", accountUuid);
    ResourceCollection<RuleChain> ruleChains = api.getChains(findChain);
    for (RuleChain chain : ruleChains) {
        if (chain.getName().equals(chainName)) {
            return chain;
        }
    }
    return null;
}
Also used : RuleChain(org.midonet.client.resource.RuleChain) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)69 JSONObject (org.codehaus.jettison.json.JSONObject)33 Test (org.junit.Test)31 ClientResponse (com.sun.jersey.api.client.ClientResponse)27 WebResource (com.sun.jersey.api.client.WebResource)19 Test (org.testng.annotations.Test)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)7 Response (javax.ws.rs.core.Response)6 BridgePort (org.midonet.client.resource.BridgePort)5 Router (org.midonet.client.resource.Router)5 Bridge (org.midonet.client.resource.Bridge)4 Route (org.midonet.client.resource.Route)4 RouterPort (org.midonet.client.resource.RouterPort)4 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)3 Client (com.sun.jersey.api.client.Client)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3