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;
}
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 /*");
}
}
}
}
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");
}
}
}
}
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;
}
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;
}
Aggregations