conorH22/bike-rental

View on GitHub
src/main/java/com/csharp/bikerental/config/CustomerAuthenticationProvider.java

Summary

Maintainability
A
0 mins
Test Coverage
package com.csharp.bikerental.config;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class CustomerAuthenticationProvider implements AuthenticationProvider {


    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        String name = authentication.getName();
        String password = authentication.getCredentials().toString();
        if(true) {
            //TODO check if user is valid in the repo
            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
                    name, password, new ArrayList<>());
            return token;
        }
        return null;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return authentication.equals(
                UsernamePasswordAuthenticationToken.class);
    }
}