當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。