Search in sources :

Example 36 with Configuration

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

the class JacksonFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
        return false;
    }
    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
    // Register Jackson.
    if (!config.isRegistered(JacksonJaxbJsonProvider.class)) {
        // add the default Jackson exception mappers
        context.register(JsonParseExceptionMapper.class);
        context.register(JsonMappingExceptionMapper.class);
        if (EntityFilteringFeature.enabled(config)) {
            context.register(JacksonFilteringFeature.class);
            context.register(FilteringJacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
        } else {
            context.register(JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
        }
    }
    return true;
}
Also used : Configuration(javax.ws.rs.core.Configuration) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) FilteringJacksonJaxbJsonProvider(org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider)

Example 37 with Configuration

use of javax.ws.rs.core.Configuration in project minijax by minijax.

the class SecurityTest method testAnonymousLogout.

@Test
public void testAnonymousLogout() {
    final SecurityDao dao = mock(SecurityDao.class);
    final Configuration config = mock(Configuration.class);
    final Security<User> security = new Security<>(dao, config, null, null);
    final NewCookie cookie = security.logout();
    assertNotNull(cookie);
    assertEquals("", cookie.getValue());
}
Also used : Configuration(javax.ws.rs.core.Configuration) NewCookie(javax.ws.rs.core.NewCookie) MinijaxTest(org.minijax.test.MinijaxTest) Test(org.junit.Test)

Example 38 with Configuration

use of javax.ws.rs.core.Configuration in project minijax by minijax.

the class SecurityTest method testAnonymous.

@Test
public void testAnonymous() {
    final SecurityDao dao = mock(SecurityDao.class);
    final Configuration config = mock(Configuration.class);
    final Security<User> security = new Security<>(dao, config, null, null);
    assertFalse(security.isLoggedIn());
    assertNull(security.getUserPrincipal());
    assertNull(security.getUserPrincipal());
    assertNull(security.getAuthenticationScheme());
    assertFalse(security.isUserInRole("user"));
    assertTrue(security.isSecure());
}
Also used : Configuration(javax.ws.rs.core.Configuration) MinijaxTest(org.minijax.test.MinijaxTest) Test(org.junit.Test)

Example 39 with Configuration

use of javax.ws.rs.core.Configuration in project minijax by minijax.

the class SecurityTest method testInvalidSessionToken.

@Test(expected = BadRequestException.class)
public void testInvalidSessionToken() {
    final User user = new User();
    final UserSession session = new UserSession();
    session.setUser(user);
    final String cookie = session.getId().toString();
    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.read(eq(UserSession.class), eq(session.getId()))).thenReturn(session);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);
    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);
    final Security<User> security = new Security<>(dao, config, null, cookie);
    security.validateSession("not-the-right-token");
}
Also used : Configuration(javax.ws.rs.core.Configuration) MinijaxTest(org.minijax.test.MinijaxTest) Test(org.junit.Test)

Example 40 with Configuration

use of javax.ws.rs.core.Configuration in project minijax by minijax.

the class SecurityTest method testAnonymousRequireLogin.

@Test(expected = NotAuthorizedException.class)
public void testAnonymousRequireLogin() {
    final SecurityDao dao = mock(SecurityDao.class);
    final Configuration config = mock(Configuration.class);
    final Security<User> security = new Security<>(dao, config, null, null);
    security.requireLogin();
}
Also used : Configuration(javax.ws.rs.core.Configuration) MinijaxTest(org.minijax.test.MinijaxTest) Test(org.junit.Test)

Aggregations

Configuration (javax.ws.rs.core.Configuration)56 Test (org.junit.Test)28 MinijaxTest (org.minijax.test.MinijaxTest)17 FeatureContext (javax.ws.rs.core.FeatureContext)7 Client (javax.ws.rs.client.Client)5 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)4 Map (java.util.Map)3 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)3 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)3 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)3 Feature (javax.ws.rs.core.Feature)3 NewCookie (javax.ws.rs.core.NewCookie)3 List (java.util.List)2 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)2 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)2 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)2 LocalResteasyProviderFactory (org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)2 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)2 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1