Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package si.arnes.dropbookmarks.auth; import com.google.common.base.Optional; import io.dropwizard.auth.AuthenticationException; import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.basic.BasicCredentials; import si.arnes.dropbookmarks.core.User; /** * * @author klemen <klemen.pravdic@arnes.si> */ public class HelloAuthenticator implements Authenticator<BasicCredentials, User> { private String password; public HelloAuthenticator(String password) { this.password = password; } @Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { if (password.equals(credentials.getPassword())) { return Optional.of(new User(0, credentials.getUsername(), credentials.getPassword())); } return Optional.absent(); } }