Search in sources :

Example 71 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project jersey by jersey.

the class MediaTypeSelectionTest method testNoAcceptHeader.

@Test
public void testNoAcceptHeader() {
    // This test is testing the situation when the client sends no Accept header to the server and it expects
    // APPLICATION_OCTET_STREAM_TYPE to be returned. But when no Accept header is defined by the client api the
    // HttpURLConnection (in HttpUrlConnector)  always put there some default Accept header (like */*, text/plain, ...).
    // To overwrite this behaviour we set Accept to empty String. This works fine as the server code handles empty
    // Accept header like no Accept header.
    final MultivaluedHashMap headers = new MultivaluedHashMap();
    headers.add("Accept", "");
    Response r = target("text/any").request().headers(headers).get();
    assertEquals(200, r.getStatus());
    assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, r.getMediaType());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 72 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap 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 73 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class UserAuthenticationFilterEmbeddedTest method requestAccessTokenCustomAuth4Step2.

@Parameters({ "tokenPath", "userId", "userSecret", "audience", "RS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret" })
@Test(dependsOnMethods = "requestAccessTokenCustomAuth4Step1")
public void requestAccessTokenCustomAuth4Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String dnName, final String keyStoreFile, final String keyStoreSecret) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    tokenRequest.setScope("email read_stream manage_pages");
    tokenRequest.setAuthUsername(clientId4);
    tokenRequest.setAuthPassword(clientSecret4);
    tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    tokenRequest.setCryptoProvider(cryptoProvider);
    tokenRequest.setKeyId(keyId);
    tokenRequest.setAudience(audience);
    tokenRequest.addCustomParameter("uid", userId);
    tokenRequest.addCustomParameter("pwd", userSecret);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenCustomAuth4Step2", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertTrue(!entity.equals(null), "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
        assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
        assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
        assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found");
    } catch (Exception e) {
        fail(e.getMessage(), e);
    }
}
Also used : OxAuthCryptoProvider(org.xdi.oxauth.model.crypto.OxAuthCryptoProvider) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 74 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class UserAuthenticationFilterEmbeddedTest method requestAccessTokenCustomAuth3Step2.

@Parameters({ "tokenPath", "userInum", "userEmail" })
@Test(dependsOnMethods = "requestAccessTokenCustomAuth3Step1")
public void requestAccessTokenCustomAuth3Step2(final String tokenPath, final String userInum, final String userEmail) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
    TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    tokenRequest.setScope("email read_stream manage_pages");
    tokenRequest.setAuthUsername(clientId3);
    tokenRequest.setAuthPassword(clientSecret3);
    tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
    tokenRequest.addCustomParameter("mail", userEmail);
    tokenRequest.addCustomParameter("inum", userInum);
    request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenCustomAuth3Step2", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertTrue(!entity.equals(null), "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
        assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
        assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
        assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 75 with MultivaluedHashMap

use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoHS384Step3.

@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoHS384Step2")
public void requestUserInfoHS384Step3(final String userInfoPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
    request.header("Authorization", "Bearer " + accessToken6);
    UserInfoRequest userInfoRequest = new UserInfoRequest(null);
    Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoHS384Step3", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
    assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        Jwt jwt = Jwt.parse(entity);
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.NAME));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EMAIL));
        assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.PICTURE));
    } catch (InvalidJwtException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) Jwt(org.xdi.oxauth.model.jwt.Jwt) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) UserInfoRequest(org.xdi.oxauth.client.UserInfoRequest) URISyntaxException(java.net.URISyntaxException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)133 Response (javax.ws.rs.core.Response)98 Builder (javax.ws.rs.client.Invocation.Builder)78 JSONException (org.codehaus.jettison.json.JSONException)77 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)77 Test (org.testng.annotations.Test)75 JSONObject (org.codehaus.jettison.json.JSONObject)73 Parameters (org.testng.annotations.Parameters)73 BaseTest (org.xdi.oxauth.BaseTest)73 TokenRequest (org.xdi.oxauth.client.TokenRequest)39 Test (org.junit.Test)28 URISyntaxException (java.net.URISyntaxException)27 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)21 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)18 ByteArrayInputStream (java.io.ByteArrayInputStream)12 UserInfoRequest (org.xdi.oxauth.client.UserInfoRequest)12 URI (java.net.URI)11 ResourceResponse (ddf.catalog.operation.ResourceResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9