class GrapesAuthenticator implements Authenticator<BasicCredentials, DbCredential> {

    @Override
    public Optional<DbCredential> authenticate(BasicCredentials credentials) throws AuthenticationException {
        if(credentials == null || credentials.getUsername() == null || credentials.getPassword() == null){
            LOG.error("Missing credentials for the authentication");
            return Optional.absent();
        }

        final String encryptedPwd = encrypt(credentials.getPassword());

        final DbCredential dbCredential = repoHandler.getCredential(credentials.getUsername());

        if(dbCredential != null && encryptedPwd.equals(dbCredential.getPassword())){
            return Optional.of(dbCredential);
        }

        return Optional.absent();
    }

    public  GrapesAuthenticator(final RepositoryHandler repoHandler);

}