Commit c3f9c20c by Yashvant Kantival

Token Verification On Based Of User ID

parent 0d7c4c38
......@@ -25,10 +25,11 @@ import lombok.Setter;
@EntityListeners(AuditingEntityListener.class)
public class User {
@Id
@Column(length=10)
private String id;
//@Id
//@Column(length=10)
//private String id;
@Id
@Column(length=11)
private String userId;
@Column(length=200)
......
......@@ -52,7 +52,7 @@ public class UserDto {
private int failedAttemptLogin = 0;
public UserDto(User user) {
this.id = user.getId();
this.id = user.getUserId();
// this.status = user.getStatus();
this.name = user.getFirstName();
this.mobileNumber = user.getMobileNo();
......
......@@ -12,6 +12,6 @@ public interface UserRepository extends JpaRepository<User, String>{
// List<User> findAll();
/*List<User> findByName(String name);*/
Optional<User> findById(String id);
List<User> findByIdIn(List<Long> ids);
Optional<User> findByUserId(String id);
List<User> findByUserIdIn(List<Long> ids);
}
......@@ -41,7 +41,7 @@ public class UserServiceImpl implements UserService {
public User save(UserDto userDto) {
User user = new User();
if(userDto.getId() != null) {
user = userRepository.findById(userDto.getId()).orElseThrow(()-> new ResourceNotFoundException("User", "id", userDto.getId()));
user = userRepository.findByUserId(userDto.getId()).orElseThrow(()-> new ResourceNotFoundException("User", "id", userDto.getId()));
}
user.setFirstName(userDto.getName());
user.setEmailId(userDto.getEmail());
......@@ -57,7 +57,7 @@ public class UserServiceImpl implements UserService {
public List<User> findByIds(List<Long> userIds){
return userRepository.findByIdIn(userIds);
return userRepository.findByUserIdIn(userIds);
}
@Override
......@@ -68,7 +68,7 @@ public class UserServiceImpl implements UserService {
@Override
public User findById(String id) {
Optional<User> user = userRepository.findById(id);
Optional<User> user = userRepository.findByUserId(id);
LOG.info("user---user----user"+user.toString());
......@@ -76,7 +76,7 @@ public class UserServiceImpl implements UserService {
return null;
}
else {
return userRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("User", "id", id));
return userRepository.findByUserId(id).orElseThrow(()->new ResourceNotFoundException("User", "id", id));
}
//return userRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("User", "id", id));
......
......@@ -51,36 +51,40 @@ public class AuthProvider implements AuthenticationProvider {
LOG.info("login request for user "+username);
// LDAP Service Call
User user = null;
user = new User();
// user = userService.findById(username);
LOG.info("---------"+user);
user.setId("1");
user.setBranchCode("abc");
user.setFirstName("xyz");
user.setLastName("abc");
user.setGender("m");
user.setMobileNo("8238284225");
user.setBranchName("abc");
user.setMiddleName("pqr");
user.setEmailId("gosranineel4@gmail.com");
user.setDesignation("PBA");
user.setPan("pan");
user.setAgentStatus("1");
user.setRole(RolesConstant.LEADER);
try {
user = userService.findById(username);
// LOG.info("---------"+user);
//
//
//
// user.setId("1");
// user.setBranchCode("abc");
// user.setFirstName("xyz");
// user.setLastName("abc");
// user.setGender("m");
// user.setMobileNo("8238284225");
// user.setBranchName("abc");
// user.setMiddleName("pqr");
// user.setEmailId("gosranineel4@gmail.com");
// user.setDesignation("PBA");
// user.setPan("pan");
// user.setAgentStatus("1");
// user.setRole(RolesConstant.LEADER);
//
userService.save(user);
LOG.info("user-----"+user);
List<String> roles = new ArrayList<String>();
roles.add("leader");
return new UsernamePasswordAuthenticationToken(UserPrincipal.create(user,(LoginRequest)authentication.getDetails()), password,roles.stream().map(x -> new SimpleGrantedAuthority("ROLE_"+x)).collect(Collectors.toList()));
}
catch (Exception e) {
throw new BadCredentialsException(""+StatusCode.INVALID_CREDENTIAL);
}
}
......
......@@ -76,7 +76,7 @@ public class UserPrincipal implements UserDetails {
).collect(Collectors.toList());
return new UserPrincipal(user.getFirstName(), user.getId(), user.getEmailId(),loginRequest.getDeviceInfo(),loginRequest.getOS(),loginRequest.getBrowserInfo(), user.getMobileNo(), authorities);
return new UserPrincipal(user.getFirstName(), user.getUserId(), user.getEmailId(),loginRequest.getDeviceInfo(),loginRequest.getOS(),loginRequest.getBrowserInfo(), user.getMobileNo(), authorities);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment