@Test void testGetAuthFilters() throws Exception { final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class, Validators.newValidator(), Jackson.newMinimalObjectMapper(), "") .build(new File(getClass().getResource("/config1.yml").toURI())); config.getAuth().getJwt().setKeyStore(null); final List<ContainerRequestFilter> filters = TrellisUtils.getAuthFilters(config); assertFalse(filters.isEmpty(), "Auth filters are missing!"); assertEquals(2L, filters.size(), "Incorrect auth filter count!"); config.getAuth().getBasic().setEnabled(false); config.getAuth().getJwt().setEnabled(false); assertTrue(TrellisUtils.getAuthFilters(config).isEmpty(), "Auth filters should have been disabled!"); }
public static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config) { final List<ContainerRequestFilter> filters = new ArrayList<>(); final AuthConfiguration auth = config.getAuth(); final String realm = config.getAuth().getRealm(); final Set<String> admins = new HashSet<>(config.getAuth().getAdminUsers()); if (auth.getJwt().getEnabled()) { final OAuthFilter filter = new OAuthFilter(); filter.setAuthenticator(getJwtAuthenticator(auth.getJwt())); filter.setChallenge("Bearer realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } if (auth.getBasic().getEnabled() && auth.getBasic().getUsersFile() != null) { final BasicAuthFilter filter = new BasicAuthFilter(); filter.setFile(new File(auth.getBasic().getUsersFile())); filter.setChallenge("Basic realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } return filters; }
TrellisUtils { public static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config) { final List<ContainerRequestFilter> filters = new ArrayList<>(); final AuthConfiguration auth = config.getAuth(); final String realm = config.getAuth().getRealm(); final Set<String> admins = new HashSet<>(config.getAuth().getAdminUsers()); if (auth.getJwt().getEnabled()) { final OAuthFilter filter = new OAuthFilter(); filter.setAuthenticator(getJwtAuthenticator(auth.getJwt())); filter.setChallenge("Bearer realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } if (auth.getBasic().getEnabled() && auth.getBasic().getUsersFile() != null) { final BasicAuthFilter filter = new BasicAuthFilter(); filter.setFile(new File(auth.getBasic().getUsersFile())); filter.setChallenge("Basic realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } return filters; } }
TrellisUtils { public static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config) { final List<ContainerRequestFilter> filters = new ArrayList<>(); final AuthConfiguration auth = config.getAuth(); final String realm = config.getAuth().getRealm(); final Set<String> admins = new HashSet<>(config.getAuth().getAdminUsers()); if (auth.getJwt().getEnabled()) { final OAuthFilter filter = new OAuthFilter(); filter.setAuthenticator(getJwtAuthenticator(auth.getJwt())); filter.setChallenge("Bearer realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } if (auth.getBasic().getEnabled() && auth.getBasic().getUsersFile() != null) { final BasicAuthFilter filter = new BasicAuthFilter(); filter.setFile(new File(auth.getBasic().getUsersFile())); filter.setChallenge("Basic realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } return filters; } private  TrellisUtils(); }
TrellisUtils { public static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config) { final List<ContainerRequestFilter> filters = new ArrayList<>(); final AuthConfiguration auth = config.getAuth(); final String realm = config.getAuth().getRealm(); final Set<String> admins = new HashSet<>(config.getAuth().getAdminUsers()); if (auth.getJwt().getEnabled()) { final OAuthFilter filter = new OAuthFilter(); filter.setAuthenticator(getJwtAuthenticator(auth.getJwt())); filter.setChallenge("Bearer realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } if (auth.getBasic().getEnabled() && auth.getBasic().getUsersFile() != null) { final BasicAuthFilter filter = new BasicAuthFilter(); filter.setFile(new File(auth.getBasic().getUsersFile())); filter.setChallenge("Basic realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } return filters; } private  TrellisUtils(); static Authenticator getJwtAuthenticator(final JwtAuthConfiguration config); static WebAcService getWebacService(final TrellisConfiguration config,
            final ResourceService resourceService); static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config); static String buildChallenge(final String scheme, final String realm, final String scope); static CORSConfiguration getCorsConfiguration(final TrellisConfiguration config); }
TrellisUtils { public static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config) { final List<ContainerRequestFilter> filters = new ArrayList<>(); final AuthConfiguration auth = config.getAuth(); final String realm = config.getAuth().getRealm(); final Set<String> admins = new HashSet<>(config.getAuth().getAdminUsers()); if (auth.getJwt().getEnabled()) { final OAuthFilter filter = new OAuthFilter(); filter.setAuthenticator(getJwtAuthenticator(auth.getJwt())); filter.setChallenge("Bearer realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } if (auth.getBasic().getEnabled() && auth.getBasic().getUsersFile() != null) { final BasicAuthFilter filter = new BasicAuthFilter(); filter.setFile(new File(auth.getBasic().getUsersFile())); filter.setChallenge("Basic realm=\"" + realm + "\""); filter.setAdmins(admins); filters.add(filter); } return filters; } private  TrellisUtils(); static Authenticator getJwtAuthenticator(final JwtAuthConfiguration config); static WebAcService getWebacService(final TrellisConfiguration config,
            final ResourceService resourceService); static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config); static String buildChallenge(final String scheme, final String realm, final String scope); static CORSConfiguration getCorsConfiguration(final TrellisConfiguration config);  }