本文整理汇总了Java中io.dropwizard.auth.PrincipalImpl类的典型用法代码示例。如果您正苦于以下问题:Java PrincipalImpl类的具体用法?Java PrincipalImpl怎么用?Java PrincipalImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrincipalImpl类属于io.dropwizard.auth包,在下文中一共展示了PrincipalImpl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: authenticate
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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);
}
开发者ID:adamkewley,项目名称:jobson,代码行数:13,代码来源:BasicAuthenticator.java
示例2: authenticate
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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();
}
开发者ID:adamkewley,项目名称:jobson,代码行数:8,代码来源:SpecificUsernamePwAuthenticator.java
示例3: filter
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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";
}
});
}
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:33,代码来源:AnonymousAuthFilter.java
示例4: run
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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();
}
});
}
开发者ID:mokies,项目名称:ratelimitj,代码行数:34,代码来源:RateLimitApplication.java
示例5: authenticate
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@Override
public Optional<PrincipalImpl> authenticate(String credentials) {
if ("secret".equals(credentials)) {
return Optional.of(new PrincipalImpl("elliot"));
}
return Optional.empty();
}
开发者ID:mokies,项目名称:ratelimitj,代码行数:8,代码来源:TestOAuthAuthenticator.java
示例6: getBasicAuthenticator
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
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();
};
}
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:12,代码来源:AuthUtil.java
示例7: getSingleUserOAuthAuthenticator
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
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();
};
}
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:13,代码来源:AuthUtil.java
示例8: getMultiplyUsersOAuthAuthenticator
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
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();
};
}
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:12,代码来源:AuthUtil.java
示例9: cachesTheFirstReturnedPrincipal
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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");
}
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:8,代码来源:CachingAuthenticatorTest.java
示例10: GuestAuthenticator
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
public GuestAuthenticator(String guestUserName) {
this.p = Optional.of(new PrincipalImpl(guestUserName));
}
开发者ID:adamkewley,项目名称:jobson,代码行数:4,代码来源:GuestAuthenticator.java
示例11: authenticate
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@Override
public Optional<Principal> authenticate(final BasicCredentials credentials) throws AuthenticationException {
return lookup(credentials).map(PrincipalImpl::new);
}
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:5,代码来源:BasicAuthenticator.java
示例12: authenticate
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@Override
public Optional<Principal> authenticate(final String credentials) throws AuthenticationException {
return of(new PrincipalImpl(Trellis.AnonymousAgent.getIRIString()));
}
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:5,代码来源:AnonymousAuthenticator.java
示例13: getLimitedByAuthenticatedUser
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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();
}
开发者ID:mokies,项目名称:ratelimitj,代码行数:7,代码来源:UserResource.java
示例14: setUp
import io.dropwizard.auth.PrincipalImpl; //导入依赖的package包/类
@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"));
}
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:7,代码来源:CachingAuthenticatorTest.java
注:本文中的io.dropwizard.auth.PrincipalImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论