com.rentmycourt.api.core.helpers.SimpleAuthenticator.java Source code

Java tutorial

Introduction

Here is the source code for com.rentmycourt.api.core.helpers.SimpleAuthenticator.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 com.rentmycourt.api.core.helpers;

import com.rentmycourt.api.core.User;
import com.google.common.base.Optional;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials;

/**
 *
 * @author yenox
 */
public class SimpleAuthenticator implements Authenticator<BasicCredentials, User> {

    /**
     *
     * @param credentials
     * @return
     * @throws io.dropwizard.auth.AuthenticationException.<error>
     */
    @Override
    public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
        if ("secret".equals(credentials.getPassword())) {
            return Optional.of(new User(credentials.getUsername()));
        }
        return Optional.absent();
    }
}