本文整理汇总了Java中io.dropwizard.auth.AuthFilter类的典型用法代码示例。如果您正苦于以下问题:Java AuthFilter类的具体用法?Java AuthFilter怎么用?Java AuthFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthFilter类属于io.dropwizard.auth包,在下文中一共展示了AuthFilter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Test
public void testAuthFilter() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
when(mockContext.getHeaders()).thenReturn(headers);
final AuthFilter<String, Principal> filter = new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator()).buildAuthFilter();
filter.filter(mockContext);
verify(mockContext).setSecurityContext(securityCaptor.capture());
assertEquals(Trellis.AnonymousAgent.getIRIString(), securityCaptor.getValue().getUserPrincipal().getName());
assertFalse(securityCaptor.getValue().isUserInRole("role"));
assertFalse(securityCaptor.getValue().isSecure());
assertEquals("NONE", securityCaptor.getValue().getAuthenticationScheme());
}
示例2: testAuthFilterSecure
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Test
public void testAuthFilterSecure() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
when(mockContext.getHeaders()).thenReturn(headers);
when(mockContext.getSecurityContext()).thenReturn(mockSecurityContext);
when(mockSecurityContext.isSecure()).thenReturn(true);
final AuthFilter<String, Principal> filter = new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator()).buildAuthFilter();
filter.filter(mockContext);
verify(mockContext).setSecurityContext(securityCaptor.capture());
assertEquals(Trellis.AnonymousAgent.getIRIString(), securityCaptor.getValue().getUserPrincipal().getName());
assertFalse(securityCaptor.getValue().isUserInRole("role"));
assertTrue(securityCaptor.getValue().isSecure());
assertEquals("NONE", securityCaptor.getValue().getAuthenticationScheme());
}
示例3: testAuthFilterNotSecure
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Test
public void testAuthFilterNotSecure() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
when(mockContext.getHeaders()).thenReturn(headers);
when(mockContext.getSecurityContext()).thenReturn(mockSecurityContext);
when(mockSecurityContext.isSecure()).thenReturn(false);
final AuthFilter<String, Principal> filter = new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator()).buildAuthFilter();
filter.filter(mockContext);
verify(mockContext).setSecurityContext(securityCaptor.capture());
assertEquals(Trellis.AnonymousAgent.getIRIString(), securityCaptor.getValue().getUserPrincipal().getName());
assertFalse(securityCaptor.getValue().isUserInRole("role"));
assertFalse(securityCaptor.getValue().isSecure());
assertEquals("NONE", securityCaptor.getValue().getAuthenticationScheme());
}
示例4: testGetAuthFilters
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Test
public void testGetAuthFilters() throws Exception {
final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
Validators.newValidator(), Jackson.newObjectMapper(), "")
.build(new File(getClass().getResource("/config1.yml").toURI()));
final Optional<List<AuthFilter>> filters = TrellisUtils.getAuthFilters(config);
assertTrue(filters.isPresent());
filters.ifPresent(f -> assertEquals(3L, f.size()));
config.getAuth().getAnon().setEnabled(false);
config.getAuth().getBasic().setEnabled(false);
config.getAuth().getJwt().setEnabled(false);
assertFalse(TrellisUtils.getAuthFilters(config).isPresent());
}
示例5: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
final ClassLoader classLoader = getClassLoader(classPath);
final Class<?> klass = loadClass(classLoader, className);
final Class<AuthenticationConfig> authConfigClass = toAuthConfigClass(klass);
final AuthenticationConfig loadedConfig = loadAuthenticationConfig(properties, authConfigClass);
return loadedConfig.createAuthFilter(bootstrap);
}
示例6: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
return new GuestAuthFilter.Builder<>()
.setAuthenticator(new GuestAuthenticator(guestUserName))
.setAuthorizer(new PermitAllAuthorizer())
.setRealm(DEFAULT_GUEST_AUTH_REALM)
.buildAuthFilter();
}
示例7: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
return new BasicCredentialAuthFilter.Builder<>()
.setAuthenticator(new BasicAuthenticator(bootstrap.getUserDAO()))
.setAuthorizer(new PermitAllAuthorizer())
.setRealm(realm)
.buildAuthFilter();
}
示例8: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
return new BasicCredentialAuthFilter.Builder<>()
.setAuthenticator(new SpecificUsernamePwAuthenticator(username, password))
.setAuthorizer(new PermitAllAuthorizer())
.buildAuthFilter();
}
示例9: getAuthFilters
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
public static Optional<List<AuthFilter>> getAuthFilters(final TrellisConfiguration config) {
// Authentication
final List<AuthFilter> filters = new ArrayList<>();
final AuthConfiguration auth = config.getAuth();
if (auth.getJwt().getEnabled()) {
filters.add(new OAuthCredentialAuthFilter.Builder<Principal>()
.setAuthenticator(new JwtAuthenticator(auth.getJwt().getKey(), auth.getJwt().getBase64Encoded()))
.setPrefix("Bearer")
.buildAuthFilter());
}
if (auth.getBasic().getEnabled()) {
filters.add(new BasicCredentialAuthFilter.Builder<Principal>()
.setAuthenticator(new BasicAuthenticator(auth.getBasic().getUsersFile()))
.setRealm("Trellis Basic Authentication")
.buildAuthFilter());
}
if (auth.getAnon().getEnabled()) {
filters.add(new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator())
.buildAuthFilter());
}
if (filters.isEmpty()) {
return empty();
}
return of(filters);
}
示例10: testUnauthorized
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Test
public void testUnauthorized() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.add(HttpHeaders.AUTHORIZATION, "Bearer blahblahblah");
when(mockContext.getHeaders()).thenReturn(headers);
final AuthFilter<String, Principal> filter = new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator()).buildAuthFilter();
assertThrows(WebApplicationException.class, () -> filter.filter(mockContext));
}
示例11: run
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public void run(ServerConfiguration configuration, Environment environment) throws Exception {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "sapData");
ObjectMapper objectMapper = environment.getObjectMapper();
SapConfiguration sapConfiguration = configuration.getSapConfig();
JobConfiguration jobConfiguration = configuration.getJobConfig();
NiPingServiceBinder niPingServiceBinder = new NiPingServiceBinder(jdbi, objectMapper, sapConfiguration, jobConfiguration);
ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(niPingServiceBinder);
SapBasicAuthenticator sapBasicAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapBasicAuthenticator.class
.getName());
SapOAuthenticator sapOAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapOAuthenticator.class.getName());
final BasicCredentialAuthFilter basicAuthFilter = new BasicCredentialAuthFilter.Builder<BasicAuthUser>()
.setAuthenticator(sapBasicAuthenticator)
.buildAuthFilter();
final AuthFilter oAuthFilter = new OAuthCredentialAuthFilter.Builder<OAuthUser>()
.setAuthenticator(sapOAuthenticator)
.setPrefix("Bearer")
.buildAuthFilter();
final PolymorphicAuthDynamicFeature feature = new PolymorphicAuthDynamicFeature<UserPrincipal>(ImmutableMap.of(BasicAuthUser
.class, basicAuthFilter, OAuthUser.class, oAuthFilter));
final AbstractBinder binder = new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(BasicAuthUser.class, OAuthUser
.class));
environment.jersey().register(new AuthFilterDynamicBinding());
environment.jersey().register(feature);
environment.jersey().register(binder);
environment.jersey().register(niPingServiceBinder);
environment.jersey().packages("com.cloudwise.sap.niping.auth");
environment.jersey().packages("com.cloudwise.sap.niping.service");
environment.jersey().packages("com.cloudwise.sap.niping.dao");
environment.jersey().packages("com.cloudwise.sap.niping.common.vo.converter");
environment.jersey().packages("com.cloudwise.sap.niping.resource");
environment.jersey().register(SessionFactoryProvider.class);
environment.servlets().setSessionHandler(new SessionHandler());
}
示例12: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
return null;
}
示例13: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
return new GuestAuthenticationConfig().createAuthFilter(bootstrap);
}
示例14: createAuthFilter
import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
AuthFilter createAuthFilter(AuthenticationBootstrap bootstrap);