si.klepra.dropwizardbookmarks.auth.HelloAuthenticator.java Source code

Java tutorial

Introduction

Here is the source code for si.klepra.dropwizardbookmarks.auth.HelloAuthenticator.java

Source

/*
 * 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.klepra.dropwizardbookmarks.auth;

import com.google.common.base.Optional;
import io.dropwizard.Configuration;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;
import si.klepra.dropwizardbookmarks.DropwizardBookmarksConfiguration;
import si.klepra.dropwizardbookmarks.core.User;

/**
 *
 * @author klemen
 */
public class HelloAuthenticator implements Authenticator<BasicCredentials, User> {

    private String password;

    private DropwizardBookmarksConfiguration configuration;

    public HelloAuthenticator(DropwizardBookmarksConfiguration configuration) {
        this.configuration = configuration;
    }

    @Override
    public Optional<User> authenticate(BasicCredentials c) throws AuthenticationException {

        //call db or auth service here!
        if (configuration.getPassword().equals(c.getPassword())) {
            return Optional.of(new User());
        }
        return Optional.absent();
    }

}