This repository has been archived on 2022-07-05. You can view files and clone it, but cannot push or open issues/pull-requests.
steleks_backend/users/src/main/java/ba/steleks/controller/AuthenticationController.java

37 lines
1.2 KiB
Java

package ba.steleks.controller;
import ba.steleks.model.AuthRequest;
import ba.steleks.repository.UsersJpaRepository;
import org.bouncycastle.crypto.tls.HashAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by admin on 13/05/2017.
*/
@RestController
public class AuthenticationController {
private UsersJpaRepository usersJpaRepository;
private PasswordEncoder passwordEncoder;
@Autowired
public AuthenticationController(UsersJpaRepository usersJpaRepository, PasswordEncoder passwordEncoder) {
this.passwordEncoder=passwordEncoder;
this.usersJpaRepository = usersJpaRepository;
}
@RequestMapping(path = "/accesstoken" , method = RequestMethod.POST)
public String generateToken(@RequestBody AuthRequest body){
return passwordEncoder.matches(body.getPassword(),usersJpaRepository.findByUsername(body.getUsername()).getPasswordHash()) ? "true" : "false";
}
}