Search in sources :

Example 21 with MultivaluedMap

use of javax.ws.rs.core.MultivaluedMap in project OpenAM by OpenRock.

the class OAuthServiceUtils method isTokenValid.

public static boolean isTokenValid(String tokenId) throws OAuthServiceException {
    boolean result = false;
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(TOKEN_ID, tokenId);
    String response;
    try {
        response = tokenValidationResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Validate token failed", uie);
    }
    // ensure response is in expected format
    if (response.startsWith("boolean=true")) {
        result = true;
    }
    return result;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 22 with MultivaluedMap

use of javax.ws.rs.core.MultivaluedMap in project OpenAM by OpenRock.

the class OAuthServiceUtils method authenticate.

public static String authenticate(String username, String password, boolean appAuth) throws OAuthServiceException {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(AUTHN_USERNAME, username);
    params.add(AUTHN_PASSWORD, password);
    if (appAuth) {
        params.add("uri", "module=application");
    }
    String response;
    try {
        response = authenticateResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Authentication failed", uie);
    }
    // ensure response is in expected format
    if (!response.startsWith(ATTRIBUTE_TOKEN_ID_KEY + "=")) {
        return null;
    }
    String tokenId = response.substring(9);
    tokenId = tokenId.substring(0, tokenId.length() - 1);
    return tokenId;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 23 with MultivaluedMap

use of javax.ws.rs.core.MultivaluedMap in project OpenAM by OpenRock.

the class MultipleResourceRestTest method testEntitlements.

@Test
public void testEntitlements() throws Exception {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add("resource", RESOURCE_NAME);
    params.add("realm", REALM);
    params.add("subject", hashedTokenId);
    String json = entitlementsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
    List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
    for (JSONEntitlement e : entitlements) {
        String res = e.getResourceName();
        Map<String, Boolean> actionValues = e.getActionValues();
        if (res.equals(RESOURCE_NAME)) {
            if (!actionValues.isEmpty()) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for root");
            }
        } else if (res.equals(RESOURCE_NAME + ":80/index.html")) {
            if (actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /index.html");
            }
        } else if (res.equals(RESOURCE_NAME + ":80/*")) {
            if (!actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /*");
            }
        }
    }
}
Also used : JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) JSONObject(org.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.testng.annotations.Test)

Example 24 with MultivaluedMap

use of javax.ws.rs.core.MultivaluedMap in project OpenAM by OpenRock.

the class MultipleResourceRestTest method testDecisions.

@Test
public void testDecisions() throws Exception {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add("resources", RESOURCE_NAME + "/index.html");
    params.add("resources", RESOURCE_NAME + "/a");
    params.add("action", "GET");
    params.add("realm", REALM);
    params.add("subject", hashedTokenId);
    String json = decisionsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
    List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
    for (JSONEntitlement e : entitlements) {
        String res = e.getResourceName();
        Map<String, Boolean> actionValues = e.getActionValues();
        if (res.equals(RESOURCE_NAME + "/index.html")) {
            if (actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /index.html");
            }
        } else if (res.equals(RESOURCE_NAME + "/a")) {
            if (!actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /a");
            }
        }
    }
}
Also used : JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) JSONObject(org.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.testng.annotations.Test)

Example 25 with MultivaluedMap

use of javax.ws.rs.core.MultivaluedMap in project cloudstack by apache.

the class MidoNetElement method getGuestNetworkRouter.

private Router getGuestNetworkRouter(long id, String accountUuid, boolean isVpc) {
    MultivaluedMap qNetRouter = new MultivaluedMapImpl();
    String routerName = getRouterName(isVpc, id);
    qNetRouter.add("tenant_id", accountUuid);
    for (Router router : api.getRouters(qNetRouter)) {
        if (router.getName().equals(routerName)) {
            return router;
        }
    }
    return null;
}
Also used : Router(org.midonet.client.resource.Router) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

MultivaluedMap (javax.ws.rs.core.MultivaluedMap)29 Map (java.util.Map)11 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)8 List (java.util.List)8 IOException (java.io.IOException)6 MediaType (javax.ws.rs.core.MediaType)6 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)6 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Type (java.lang.reflect.Type)3 URI (java.net.URI)3 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 JSONEntitlement (com.sun.identity.entitlement.JSONEntitlement)2 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2