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


Java Authenticator类代码示例

本文整理汇总了Java中io.dropwizard.auth.Authenticator的典型用法代码示例。如果您正苦于以下问题:Java Authenticator类的具体用法?Java Authenticator怎么用?Java Authenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Authenticator类属于io.dropwizard.auth包,在下文中一共展示了Authenticator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configure

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Override
public boolean configure(final FeatureContext featureContext) {
    final UserRepository userRepo = CDI.current().select(UserRepository.class).get();
    final Authenticator<String, User> authenticator = new GoogleAuthenticator(
            authConfig.getClientId(), userRepo, authConfig.getHostedDomain()
    );

    final Authenticator<String, User> cachingAuthenticator = new CachingAuthenticator<>(
            metricRegistry, authenticator, authConfig.getAuthenticationCachePolicy()
    );

    featureContext.register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<User>()
            .setAuthenticator(cachingAuthenticator)
            .setPrefix("Bearer")
            .buildAuthFilter()));
    featureContext.register(new AuthValueFactoryProvider.Binder<>(User.class));

    return true;
}
 
开发者ID:PaperCutSoftware,项目名称:dust-api,代码行数:21,代码来源:AuthenticatorFeature.java

示例2: getAuthenticator

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@JsonIgnore
public Optional<Authenticator<BasicCredentials, User>> getAuthenticator() {
    final String authType = authenticatorType.toLowerCase();

    if (authType.equals("none")) {
        return Optional.empty();
    } else if (authType.equals("simple")) {
        return Optional.of(new SimpleAuthenticator());
    } else if (authType.equals("ldap")) {
        if (ldapConfiguration == null) {
            throw new IllegalArgumentException("Authenticator type is set to 'ldap' but ldap configuration is empty.");
        }

        return Optional.of(new LDAPAuthenticator(ldapConfiguration));
    } else {
        throw new IllegalArgumentException("Authenticator " + authenticatorType + " is unknow. Use one of ['none', 'simple', 'ldap']");
    }
}
 
开发者ID:voyages-sncf-technologies,项目名称:hesperides,代码行数:19,代码来源:HesperidesConfiguration.java

示例3: JWTAuthTestResourceConfig

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
public JWTAuthTestResourceConfig() {
    super(true, new MetricRegistry());

    final Authenticator<String, String> authenticator = new Authenticator<String, String>() {
        @Override
        public Optional<String> authenticate(String credentials) throws AuthenticationException {
            if ("good-one".equals(credentials)) {
                return Optional.of("good-one");
            }

            if ("bad-one".equals(credentials)) {
                throw new AuthenticationException("server ran out of entropy");
            }

            return Optional.absent();
        }
    };

    register(AuthFactory.binder(new JwtAuthFactory<>(authenticator, REALM, String.class).prefix(PREFIX)));
    register(AuthResource.class);
}
 
开发者ID:andban,项目名称:dropwizard-auth-jwt,代码行数:22,代码来源:JwtAuthFactoryTest.java

示例4: createAuthenticator

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
/**
 * <p>If a credentialFile is provided, this method will use that file to populate the list of Peers the Authenticator
 * checks during request processing.  If instead the "users" and "passwords" Strings are provided, this method will use
 * those to populate the list of Peers.</p>
 * @return An Authenticator appropriate for registering with Jersey as described
 * https://dropwizard.github.io/dropwizard/manual/auth.html
 */
public Authenticator<BasicCredentials, Peer> createAuthenticator() {
    PasswordEncryptor passwordEncryptor = encryptor.getPasswordEncryptor();
    if (this.credentialFile != null) {
        InputStream allowedPeersResource = this.getClass().getClassLoader().getResourceAsStream(this.credentialFile);
        return new AllowedPeerAuthenticator(new FlatFilePeerDAO(allowedPeersResource),
                                            passwordEncryptor);
    }
    else if (this.users != null && this.passwords != null && this.delimiter != null) {
        return new AllowedPeerAuthenticator(new StringPeerDAO(this.users, this.passwords, this.delimiter),
                                            passwordEncryptor);
    }
    else {
        throw new IllegalStateException("Illegal call to createAuthenticator() when no valid configuration was set");
    }
}
 
开发者ID:washingtonpost,项目名称:dropwizard-peer-authenticator,代码行数:23,代码来源:AllowedPeerConfiguration.java

示例5: registerAuthenticator

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
/**
 *
 * @param environment The Dropwizard environment
 * @param authorizer A specific authorizer to use instead of the default PermitAllAuthorizer.  See
 * http://www.dropwizard.io/0.9.1/docs/manual/auth.html for more details
 */
public void registerAuthenticator(Environment environment, Authorizer<Peer> authorizer) {
    Preconditions.checkNotNull(environment, "Illegal call to registerAuthenticator with a null Environment object");
    Authenticator<BasicCredentials, Peer> authenticator;
    if (this.cachePolicy != null) {
        authenticator = createCachingAuthenticator(environment.metrics());
    }
    else {
        authenticator = createAuthenticator();
    }
    environment.jersey().register(new AuthDynamicFeature(
        new BasicCredentialAuthFilter.Builder<Peer>()
            .setAuthenticator(authenticator)
            .setAuthorizer(authorizer)
            .setRealm(this.realm)
            .buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Peer.class));
}
 
开发者ID:washingtonpost,项目名称:dropwizard-peer-authenticator,代码行数:25,代码来源:AllowedPeerConfiguration.java

示例6: run

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Override
public void run(ExampleAppConfiguration configuration, Environment environment) throws Exception {
    final LdapConfiguration ldapConfiguration = configuration.getLdapConfiguration();

    Authenticator<BasicCredentials, User> ldapAuthenticator = new CachingAuthenticator<>(
            environment.metrics(),
            new ResourceAuthenticator(new LdapAuthenticator(ldapConfiguration)),
            ldapConfiguration.getCachePolicy());

    environment.jersey().register(new AuthDynamicFeature(
            new BasicCredentialAuthFilter.Builder<User>()
                    .setAuthenticator(ldapAuthenticator)
                    .setRealm("LDAP")
                    .buildAuthFilter()));

    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));

    environment.healthChecks().register("ldap", new LdapHealthCheck<>(
            new ResourceAuthenticator(new LdapCanAuthenticate(ldapConfiguration))));
}
 
开发者ID:yammer,项目名称:dropwizard-auth-ldap,代码行数:21,代码来源:ExampleAppTest.java

示例7: testAuthenticate

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticate() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "secret");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertTrue(res.isPresent());
    res.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu/", p.getName());
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:12,代码来源:BasicAuthenticatorTest.java

示例8: testAuthenticateNoWebid

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateNoWebid() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("other", "pass");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:9,代码来源:BasicAuthenticatorTest.java

示例9: testAuthenticateInvalid

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateInvalid() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "incorrect");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:9,代码来源:BasicAuthenticatorTest.java

示例10: testAuthenticateInvalidFile

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateInvalidFile() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(
            getAuthFile() + "missing");
    final BasicCredentials credentials = new BasicCredentials("acoburn", "incorrect");

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:10,代码来源:BasicAuthenticatorTest.java

示例11: testAuthenticateUnreadableFile

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateUnreadableFile() throws AuthenticationException {
    final Authenticator<BasicCredentials, Principal> authenticator = new BasicAuthenticator(getAuthFile());
    final BasicCredentials credentials = new BasicCredentials("acoburn", "secret");

    final File userFile = new File(getAuthFile());
    assumeTrue(userFile.setReadable(false));

    final Optional<Principal> res = authenticator.authenticate(credentials);
    assertFalse(res.isPresent());
    userFile.setReadable(true);
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:13,代码来源:BasicAuthenticatorTest.java

示例12: testAuthenticate

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticate() throws AuthenticationException {
    final Authenticator<String, Principal> authenticator = new AnonymousAuthenticator();

    final Optional<Principal> res = authenticator.authenticate("blahblah");
    assertTrue(res.isPresent());
    res.ifPresent(p -> {
        assertEquals(Trellis.AnonymousAgent.getIRIString(), p.getName());
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:11,代码来源:AnonymousAuthenticatorTest.java

示例13: testAuthenticate

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticate() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setSubject("https://acoburn.people.amherst.edu")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("https://acoburn.people.amherst.edu", p.getName());
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:15,代码来源:JwtAuthenticatorTest.java

示例14: testAuthenticateNoSub

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateNoSub() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setIssuer("http://localhost")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertFalse(result.isPresent());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:12,代码来源:JwtAuthenticatorTest.java

示例15: testAuthenticateSubIss

import io.dropwizard.auth.Authenticator; //导入依赖的package包/类
@Test
public void testAuthenticateSubIss() throws AuthenticationException {
     final String key = "c2VjcmV0";
     final String token = Jwts.builder().setSubject("acoburn").setIssuer("http://localhost")
         .signWith(SignatureAlgorithm.HS512, key).compact();

    final Authenticator<String, Principal> authenticator = new JwtAuthenticator(key, true);

    final Optional<Principal> result = authenticator.authenticate(token);
    assertTrue(result.isPresent());
    result.ifPresent(p -> {
        assertEquals("http://localhost/acoburn", p.getName());
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:15,代码来源:JwtAuthenticatorTest.java


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