/*
 * Created on 31. 7. 2017 16:49:36
 *
 */
package com.jh.radegast.security;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jh.common.security.AuthService;
import com.jh.common.security.ResetPassword;
import com.jh.common.security.Signup;
import com.jh.common.security.controller.AuthError;
import com.jh.common.utils.Utils;

/**
 * The Class AppUserAuthService.
 *
 * @author Jan Hrabal
 */
@Service
public class AppUserAuthService implements AuthService {

	/** The sleep. */
	@Value("${auth.login.sleep:250}")
	private Integer sleep;
	
    /**
     * @param username
     * @param password
     * @return
     * @throws BadCredentialsException
     * @see com.jh.common.security.AuthService#authenticate(java.lang.String, java.lang.String)
     */
    @Override
	public Authentication authenticate(String username, String password) throws BadCredentialsException {
    	Utils.sleep(sleep);
        throw new BadCredentialsException("Bad username or password");
    }



	@Override
	public void generateResetToken(String login) {
	}


	@Override
	@Transactional
	public List<AuthError> resetPassword(ResetPassword signup) {
		Objects.requireNonNull(signup);
		List<AuthError> errors = new ArrayList<>();
		return errors;
	}



	@Override
	public List<AuthError> register(Signup signup) {
		return Collections.emptyList();
	}
    
}
