Java 类io.dropwizard.auth.PrincipalImpl 实例源码

项目:jobson    文件:BasicAuthenticator.java   
@Override
public Optional<Principal> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    final UserId id = new UserId(basicCredentials.getUsername());

    return readonlyUserDAO
            .getUserCredentialsById(id)
            .filter(BasicAuthenticator::hasCorrectAuthType)
            .filter(credentials -> matchesTheCredentialsSuppliedByTheClient(credentials, basicCredentials))
            .map(UserCredentials::getId)
            .map(UserId::toString)
            .map(PrincipalImpl::new);
}
项目:jobson    文件:SpecificUsernamePwAuthenticator.java   
@Override
public Optional<Principal> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    if (basicCredentials.getUsername().equals(username) &&
            basicCredentials.getPassword().equals(password)) {
        return Optional.of(new PrincipalImpl(username));
    } else return Optional.empty();
}
项目:trellis-rosid    文件:AnonymousAuthFilter.java   
@Override
public void filter(final ContainerRequestContext ctx) throws IOException {

    if (nonNull(ctx.getHeaders().getFirst(HttpHeaders.AUTHORIZATION))) {
        throw new WebApplicationException(unauthorizedHandler.buildResponse(prefix, realm));
    }

    final SecurityContext securityContext = ctx.getSecurityContext();
    final boolean secure = securityContext != null && securityContext.isSecure();

    ctx.setSecurityContext(new SecurityContext() {
        @Override
        public Principal getUserPrincipal() {
            return new PrincipalImpl(Trellis.AnonymousAgent.getIRIString());
        }

        @Override
        public boolean isUserInRole(final String role) {
            return false;
        }

        @Override
        public boolean isSecure() {
            return secure;
        }

        @Override
        public String getAuthenticationScheme() {
            return "NONE";
        }
    });
}
项目:ratelimitj    文件:RateLimitApplication.java   
@Override
public void run(Configuration configuration, Environment environment) {

    environment.jersey().register(new LoginResource());
    environment.jersey().register(new UserResource());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<PrincipalImpl>()
                    .setAuthenticator(new TestOAuthAuthenticator()).setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));

    //TODO move this cleanup into the tests
    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() {
            flushRedis();
        }

        private void flushRedis() {
            try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
                connection.sync().flushdb();
            }
            redisClient.shutdownAsync();
        }
    });

}
项目:ratelimitj    文件:TestOAuthAuthenticator.java   
@Override
public Optional<PrincipalImpl> authenticate(String credentials) {
    if ("secret".equals(credentials)) {
        return Optional.of(new PrincipalImpl("elliot"));
    }
    return Optional.empty();
}
项目:dropwizard-java8    文件:AuthUtil.java   
public static Authenticator<BasicCredentials, Principal> getBasicAuthenticator(final List<String> validUsers) {
    return credentials -> {
        if (validUsers.contains(credentials.getUsername()) && "secret".equals(credentials.getPassword())) {
            return Optional.<Principal>of(new PrincipalImpl(credentials.getUsername()));
        }
        if ("bad-guy".equals(credentials.getUsername())) {
            throw new AuthenticationException("CRAP");
        }
        return Optional.empty();
    };
}
项目:dropwizard-java8    文件:AuthUtil.java   
public static Authenticator<String, Principal> getSingleUserOAuthAuthenticator(final String presented,
                                                                               final String returned) {
    return user -> {
        if (presented.equals(user)) {
            return Optional.<Principal>of(new PrincipalImpl(returned));
        }
        if ("bad-guy".equals(user)) {
            throw new AuthenticationException("CRAP");
        }
        return Optional.empty();
    };
}
项目:dropwizard-java8    文件:AuthUtil.java   
public static Authenticator<String, Principal> getMultiplyUsersOAuthAuthenticator(final List<String> validUsers) {
    return credentials -> {
        if (validUsers.contains(credentials)) {
            return Optional.<Principal>of(new PrincipalImpl(credentials));
        }
        if (credentials.equals("bad-guy")) {
            throw new AuthenticationException("CRAP");
        }
        return Optional.empty();
    };
}
项目:dropwizard-java8    文件:CachingAuthenticatorTest.java   
@Test
public void cachesTheFirstReturnedPrincipal() throws Exception {
    assertThat(cached.authenticate("credentials")).isEqualTo(Optional.<Principal>of(new PrincipalImpl("principal")));
    assertThat(cached.authenticate("credentials")).isEqualTo(Optional.<Principal>of(new PrincipalImpl("principal")));

    verify(underlying, times(1)).authenticate("credentials");
}
项目:jobson    文件:GuestAuthenticator.java   
public GuestAuthenticator(String guestUserName) {
    this.p = Optional.of(new PrincipalImpl(guestUserName));
}
项目:trellis-rosid    文件:BasicAuthenticator.java   
@Override
public Optional<Principal> authenticate(final BasicCredentials credentials) throws AuthenticationException {
    return lookup(credentials).map(PrincipalImpl::new);
}
项目:trellis-rosid    文件:AnonymousAuthenticator.java   
@Override
public Optional<Principal> authenticate(final String credentials) throws AuthenticationException {
    return of(new PrincipalImpl(Trellis.AnonymousAgent.getIRIString()));
}
项目:ratelimitj    文件:UserResource.java   
@GET
@Path("/{id}/authenticated")
@RateLimited(key = Key.AUTHENTICATED, rates = {@Rate(duration = 10, timeUnit = TimeUnit.HOURS, limit = 10)})
public Response getLimitedByAuthenticatedUser(@Auth PrincipalImpl principle, @PathParam("id") final Integer id) {
    return Response.ok().build();
}
项目:dropwizard-java8    文件:CachingAuthenticatorTest.java   
@Before
public void setUp() throws Exception {
    when(underlying.authenticate(anyString())).thenReturn(Optional.<Principal>of(new PrincipalImpl("principal")));
    cached = new CachingAuthenticator<>(new MetricRegistry(), underlying, CacheBuilderSpec.parse("maximumSize=1"));

}