dropwizard

How to do Basic Authentication of a resource in Dropwizard

折月煮酒 提交于 2019-11-28 05:29:40
I believe I have basic authentication working but I'm not sure how to protect resources so that they can only be accessed when the user is signed in. public class SimpleAuthenticator implements Authenticator<BasicCredentials, User> { UserDAO userDao; public SimpleAuthenticator(UserDAO userDao) {this.userDao = userDao;} @Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { User user = this.userDao.getUserByName(credentials.getUsername()); if (user!=null && user.getName().equalsIgnoreCase(credentials.getUsername()) && BCrypt.checkpw

Spring - Programmatically generate a set of beans

六眼飞鱼酱① 提交于 2019-11-28 03:50:53
I have a Dropwizard application that needs to generate a dozen or so beans for each of the configs in a configuration list. Things like health checks, quartz schedulers, etc. Something like this: @Component class MyModule { @Inject private MyConfiguration configuration; @Bean @Lazy public QuartzModule quartzModule() { return new QuartzModule(quartzConfiguration()); } @Bean @Lazy public QuartzConfiguration quartzConfiguration() { return this.configuration.getQuartzConfiguration(); } @Bean @Lazy public HealthCheck healthCheck() throws SchedulerException { return this.quartzModule()

How to print server responses using LoggingFeature in Dropwizard 1.0.2?

空扰寡人 提交于 2019-11-28 01:47:20
问题 The following code results in JSON server responses being printed in Dropwizard 0.9.2 and 1.0.2: return ClientBuilder .newBuilder() .build() .register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true)) For example: Oct 21, 2016 7:57:42 AM org.glassfish.jersey.filter.LoggingFilter log INFO: 1 * Client response received on thread main 1 < 401 1 < Connection: keep-alive 1 < Content-Length: 49 1 < Content-Type: text/plain 1 < Date: Fri, 21 Oct 2016 07:57:42 GMT 1 < Server:

DropWizard Auth by Example

风流意气都作罢 提交于 2019-11-27 19:24:39
I'm trying to understand how authentication and authorization work in DropWizard . I've read their auth guide as well as the dropwizard-security project on GitHub, but feel like I'm still missing a few important concepts. public class SimpleCredential { private String password; public SimpleCredential(String password) { super(); this.password = password; } } public class SimplePrincipal { pivate String username; public SimplePrincipal(String username) { super(); this.username = username; } } public class SimpleAuthenticator implements Authenticator<SimpleCredential, SimplePrincipal> {

Override DropWizard ConstraintViolation message

泄露秘密 提交于 2019-11-27 06:58:27
问题 So I want to change the validation messages used to validate a model through a DropWizard resource. I'm using java bean validation annotations. For example here is one of the fields I want to validate: @NotEmpty(message = "Password must not be empty.") I can test this works as expected using a validator. However when I use DropWizard to do the validation on the resource it adds some extra stuff to that message. What I see is this - password Password must not be empty. (was null) and I've

Dropwizard doesn't log custom loggers to file

梦想与她 提交于 2019-11-27 04:54:52
I have a dropwizard app, where I configured logger appenders to file as follows: logging: level: INFO loggers: "mylogger": INFO "com.path.to.class": INFO appenders: - type: file currentLogFilename: .logs/mylogs.log archivedLogFilenamePattern: .logs/archive.%d.log.gz archivedFileCount: 14 And, created logger in my app: import org.slf4j.Logger; import org.slf4j.LoggerFactory; private final Logger OpLogger = LoggerFactory.getLogger("mylogger"); (and) private final Logger ClassLogger = LoggerFactory.getLogger(pathToClass.class); Do some test logging in main(): OpLogger.info("test 1"); ClassLogger

How to do Basic Authentication of a resource in Dropwizard

时间秒杀一切 提交于 2019-11-27 01:02:22
问题 I believe I have basic authentication working but I'm not sure how to protect resources so that they can only be accessed when the user is signed in. public class SimpleAuthenticator implements Authenticator<BasicCredentials, User> { UserDAO userDao; public SimpleAuthenticator(UserDAO userDao) {this.userDao = userDao;} @Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { User user = this.userDao.getUserByName(credentials.getUsername());

Spring - Programmatically generate a set of beans

早过忘川 提交于 2019-11-26 22:34:33
问题 I have a Dropwizard application that needs to generate a dozen or so beans for each of the configs in a configuration list. Things like health checks, quartz schedulers, etc. Something like this: @Component class MyModule { @Inject private MyConfiguration configuration; @Bean @Lazy public QuartzModule quartzModule() { return new QuartzModule(quartzConfiguration()); } @Bean @Lazy public QuartzConfiguration quartzConfiguration() { return this.configuration.getQuartzConfiguration(); } @Bean

DropWizard Auth by Example

一笑奈何 提交于 2019-11-26 19:51:57
问题 I'm trying to understand how authentication and authorization work in DropWizard. I've read their auth guide as well as the dropwizard-security project on GitHub, but feel like I'm still missing a few important concepts. public class SimpleCredential { private String password; public SimpleCredential(String password) { super(); this.password = password; } } public class SimplePrincipal { pivate String username; public SimplePrincipal(String username) { super(); this.username = username; } }

Passing custom type query parameter

被刻印的时光 ゝ 提交于 2019-11-26 17:06:15
问题 How can I accept custom type query parameter? public String detail(@QueryParam("request") final MYRequest request) { Above line gives error while starting the server jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. 回答1: Take a look at the @QueryParam documentation, in regards to acceptable types to inject. (The same applies to all the other @XxxParam annotations also) Be a primitive type Have a constructor