Search in sources :

Example 76 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class OAuthJSONProviderTest method testReadTokenIntrospection.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadTokenIntrospection() throws Exception {
    String response = "{\"active\":true,\"client_id\":\"WjcK94pnec7CyA\",\"username\":\"alice\",\"token_type\":\"Bearer\"" + ",\"scope\":\"a\",\"aud\":\"https://localhost:8082/service\"," + "\"iat\":1453472181,\"exp\":1453475781}";
    OAuthJSONProvider provider = new OAuthJSONProvider();
    TokenIntrospection t = (TokenIntrospection) provider.readFrom((Class) TokenIntrospection.class, TokenIntrospection.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
    assertTrue(t.isActive());
    assertEquals("WjcK94pnec7CyA", t.getClientId());
    assertEquals("alice", t.getUsername());
    assertEquals("a", t.getScope());
    assertEquals(1, t.getAud().size());
    assertEquals("https://localhost:8082/service", t.getAud().get(0));
    assertEquals(1453472181L, t.getIat().longValue());
    assertEquals(1453475781L, t.getExp().longValue());
}
Also used : TokenIntrospection(org.apache.cxf.rs.security.oauth2.common.TokenIntrospection) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 77 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class OAuthJSONProviderTest method testReadTokenIntrospectionSingleAudAsArray.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadTokenIntrospectionSingleAudAsArray() throws Exception {
    String response = "{\"active\":false,\"client_id\":\"WjcK94pnec7CyA\",\"username\":\"alice\",\"token_type\":\"Bearer\"" + ",\"scope\":\"a\",\"aud\":[\"https://localhost:8082/service\"]," + "\"iat\":1453472181,\"exp\":1453475781}";
    OAuthJSONProvider provider = new OAuthJSONProvider();
    TokenIntrospection t = (TokenIntrospection) provider.readFrom((Class) TokenIntrospection.class, TokenIntrospection.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
    assertFalse(t.isActive());
    assertEquals("WjcK94pnec7CyA", t.getClientId());
    assertEquals("alice", t.getUsername());
    assertEquals("a", t.getScope());
    assertEquals(1, t.getAud().size());
    assertEquals("https://localhost:8082/service", t.getAud().get(0));
    assertEquals(1453472181L, t.getIat().longValue());
    assertEquals(1453475781L, t.getExp().longValue());
}
Also used : TokenIntrospection(org.apache.cxf.rs.security.oauth2.common.TokenIntrospection) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 78 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class OidcIdTokenRequestFilter method toFormData.

private MultivaluedMap<String, String> toFormData(ContainerRequestContext rc) {
    MultivaluedMap<String, String> requestState = new MetadataMap<String, String>();
    if (MediaType.APPLICATION_FORM_URLENCODED_TYPE.isCompatible(rc.getMediaType())) {
        String body = FormUtils.readBody(rc.getEntityStream(), StandardCharsets.UTF_8.name());
        FormUtils.populateMapFromString(requestState, JAXRSUtils.getCurrentMessage(), body, StandardCharsets.UTF_8.name(), false);
        rc.setEntityStream(new ByteArrayInputStream(StringUtils.toBytesUTF8(body)));
    }
    return requestState;
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 79 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class OAuthUtils method checkRequestURI.

public static boolean checkRequestURI(String servletPath, String uri) {
    boolean wildcard = uri.endsWith("*");
    String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri;
    try {
        URITemplate template = new URITemplate(theURI);
        MultivaluedMap<String, String> map = new MetadataMap<String, String>();
        if (template.match(servletPath, map)) {
            String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
            if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) {
                return true;
            }
        }
    } catch (Exception ex) {
    // ignore
    }
    return false;
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) URITemplate(org.apache.cxf.jaxrs.model.URITemplate) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)

Example 80 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSSamlTest method testGetBookSAMLTokenInForm.

@Test
public void testGetBookSAMLTokenInForm() throws Exception {
    String address = "https://localhost:" + PORT + "/samlform/bookstore/books";
    FormEncodingProvider<Form> formProvider = new FormEncodingProvider<Form>();
    formProvider.setExpectedEncoded(true);
    WebClient wc = createWebClient(address, new SamlFormOutInterceptor(), formProvider);
    wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML);
    try {
        Book book = wc.post(new Form(new MetadataMap<String, String>()).param("name", "CXF").param("id", "125"), Book.class);
        assertEquals(125L, book.getId());
    } catch (WebApplicationException ex) {
        fail(ex.getMessage());
    } catch (ProcessingException ex) {
        if (ex.getCause() != null && ex.getCause().getMessage() != null) {
            fail(ex.getCause().getMessage());
        } else {
            fail(ex.getMessage());
        }
    }
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) WebApplicationException(javax.ws.rs.WebApplicationException) Form(javax.ws.rs.core.Form) Book(org.apache.cxf.systest.jaxrs.security.Book) FormEncodingProvider(org.apache.cxf.jaxrs.provider.FormEncodingProvider) SamlFormOutInterceptor(org.apache.cxf.rs.security.saml.SamlFormOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Aggregations

MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)80 Test (org.junit.Test)43 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)36 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)34 ByteArrayInputStream (java.io.ByteArrayInputStream)25 Message (org.apache.cxf.message.Message)25 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)15 List (java.util.List)13 Method (java.lang.reflect.Method)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Endpoint (org.apache.cxf.endpoint.Endpoint)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 LinkedHashMap (java.util.LinkedHashMap)9 Customer (org.apache.cxf.jaxrs.Customer)9 WebClient (org.apache.cxf.jaxrs.client.WebClient)9 Annotation (java.lang.annotation.Annotation)8 HashMap (java.util.HashMap)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)7