Search in sources :

Example 81 with MultivaluedMap

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

the class TelegramServiceRestBotAPIAdapter method buildTextPart.

private Attachment buildTextPart(String name, String value) {
    MultivaluedMap m = new MultivaluedHashMap<>();
    m.putSingle("Content-Type", "text/plain");
    m.putSingle("Content-Disposition", "form-data; name=\"" + escapeMimeName(name) + "\"");
    Attachment a = new Attachment(m, value);
    return a;
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 82 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 83 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 84 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 85 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)

Aggregations

MultivaluedMap (javax.ws.rs.core.MultivaluedMap)135 Map (java.util.Map)67 List (java.util.List)51 HashMap (java.util.HashMap)45 MediaType (javax.ws.rs.core.MediaType)35 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)28 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)27 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)23 Test (org.junit.Test)21 WebApplicationException (javax.ws.rs.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)18 Type (java.lang.reflect.Type)16 Response (javax.ws.rs.core.Response)16 InputStream (java.io.InputStream)14 OutputStream (java.io.OutputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)13 Method (java.lang.reflect.Method)11 Optional (java.util.Optional)11