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