当前位置: 首页>>代码示例>>Java>>正文


Java AuthFilter类代码示例

本文整理汇总了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());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:18,代码来源:AnonymousAuthFilterTest.java

示例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());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:20,代码来源:AnonymousAuthFilterTest.java

示例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());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:20,代码来源:AnonymousAuthFilterTest.java

示例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());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:17,代码来源:TrellisUtilsTest.java

示例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);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:11,代码来源:CustomAuthenticatorConfig.java

示例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();
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:9,代码来源:GuestAuthenticationConfig.java

示例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();
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:9,代码来源:BasicAuthenticatorConfig.java

示例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();
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:8,代码来源:SystemtestCustomAuthConfig.java

示例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);
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:31,代码来源:TrellisUtils.java

示例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));
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:13,代码来源:AnonymousAuthFilterTest.java

示例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());
}
 
开发者ID:CloudWise-OpenSource,项目名称:SAPNetworkMonitor,代码行数:43,代码来源:NiPingMonitorApplication.java

示例12: createAuthFilter

import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
    return null;
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:5,代码来源:CustomAuthConfigWithProperties.java

示例13: createAuthFilter

import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
@Override
public AuthFilter<?, Principal> createAuthFilter(AuthenticationBootstrap bootstrap) {
    return new GuestAuthenticationConfig().createAuthFilter(bootstrap);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:5,代码来源:NullCustomAuthConfig.java

示例14: createAuthFilter

import io.dropwizard.auth.AuthFilter; //导入依赖的package包/类
AuthFilter createAuthFilter(AuthenticationBootstrap bootstrap); 
开发者ID:adamkewley,项目名称:jobson,代码行数:2,代码来源:AuthenticationConfig.java


注:本文中的io.dropwizard.auth.AuthFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。