yammer / dropwizard-auth-ldap

Dropwizard Authentication Module for LDAP using JNDI.
Apache License 2.0
36 stars 17 forks source link

Dropwizard 1.0.x support #14

Closed DOSarrest closed 7 years ago

DOSarrest commented 7 years ago

Please update for dropwizard 1.x. Current instructions appear to be for 0.x. After some work I have been able to get it to work for logging in, but the @Auth annotation does not provide access to the User object.

The current instructions do not appear to work at all with 1.x and results in various errors.

DOSarrest commented 7 years ago

Here is the run initialization code so far

` LdapConfiguration ldapConfiguration = configuration.getLdapConfiguration();

    Authenticator<BasicCredentials, User> ldapAuthenticator = new CachingAuthenticator<>(
        environment.metrics(),
        new UserResourceAuthenticator(new LdapAuthenticator(ldapConfiguration)),
        ldapConfiguration.getCachePolicy()
    );
    BasicCredentialAuthFilter<User> basicCredentialAuthFilter = new BasicCredentialAuthFilter.Builder<User>()
        .setAuthenticator(ldapAuthenticator)
        .setAuthorizer(new LdapAuthorizer())
        .setRealm("MetricEngine")
        .buildAuthFilter();
    environment.jersey().register(new AuthDynamicFeature(basicCredentialAuthFilter));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    //If you want to use @Auth to inject a custom Principal type into your resource
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
    environment.healthChecks().register("ldap", new LdapHealthCheck<>(new UserResourceAuthenticator(new LdapCanAuthenticate(ldapConfiguration))));`
DOSarrest commented 7 years ago

Got it working by changing AuthValueFactoryProvider to this...

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

Documentation should probably be updated to reflect 1.x changes though.

chrisgray commented 7 years ago

Agreed, I'll update the usage doc to reflect the 1.x release of Dropwizard Auth.

chrisgray commented 7 years ago

Made the changes here: https://github.com/yammer/dropwizard-auth-ldap/commit/539aa7979b65f585437d346f81a40c84d3cb6503