Commit c3f9c20c by Yashvant Kantival

Token Verification On Based Of User ID

parent 0d7c4c38
...@@ -25,10 +25,11 @@ import lombok.Setter; ...@@ -25,10 +25,11 @@ import lombok.Setter;
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class User { public class User {
@Id //@Id
@Column(length=10) //@Column(length=10)
private String id; //private String id;
@Id
@Column(length=11) @Column(length=11)
private String userId; private String userId;
@Column(length=200) @Column(length=200)
......
...@@ -52,7 +52,7 @@ public class UserDto { ...@@ -52,7 +52,7 @@ public class UserDto {
private int failedAttemptLogin = 0; private int failedAttemptLogin = 0;
public UserDto(User user) { public UserDto(User user) {
this.id = user.getId(); this.id = user.getUserId();
// this.status = user.getStatus(); // this.status = user.getStatus();
this.name = user.getFirstName(); this.name = user.getFirstName();
this.mobileNumber = user.getMobileNo(); this.mobileNumber = user.getMobileNo();
......
...@@ -12,6 +12,6 @@ public interface UserRepository extends JpaRepository<User, String>{ ...@@ -12,6 +12,6 @@ public interface UserRepository extends JpaRepository<User, String>{
// List<User> findAll(); // List<User> findAll();
/*List<User> findByName(String name);*/ /*List<User> findByName(String name);*/
Optional<User> findById(String id); Optional<User> findByUserId(String id);
List<User> findByIdIn(List<Long> ids); List<User> findByUserIdIn(List<Long> ids);
} }
...@@ -41,7 +41,7 @@ public class UserServiceImpl implements UserService { ...@@ -41,7 +41,7 @@ public class UserServiceImpl implements UserService {
public User save(UserDto userDto) { public User save(UserDto userDto) {
User user = new User(); User user = new User();
if(userDto.getId() != null) { 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.setFirstName(userDto.getName());
user.setEmailId(userDto.getEmail()); user.setEmailId(userDto.getEmail());
...@@ -57,7 +57,7 @@ public class UserServiceImpl implements UserService { ...@@ -57,7 +57,7 @@ public class UserServiceImpl implements UserService {
public List<User> findByIds(List<Long> userIds){ public List<User> findByIds(List<Long> userIds){
return userRepository.findByIdIn(userIds); return userRepository.findByUserIdIn(userIds);
} }
@Override @Override
...@@ -68,7 +68,7 @@ public class UserServiceImpl implements UserService { ...@@ -68,7 +68,7 @@ public class UserServiceImpl implements UserService {
@Override @Override
public User findById(String id) { public User findById(String id) {
Optional<User> user = userRepository.findById(id); Optional<User> user = userRepository.findByUserId(id);
LOG.info("user---user----user"+user.toString()); LOG.info("user---user----user"+user.toString());
...@@ -76,7 +76,7 @@ public class UserServiceImpl implements UserService { ...@@ -76,7 +76,7 @@ public class UserServiceImpl implements UserService {
return null; return null;
} }
else { 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)); //return userRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("User", "id", id));
......
...@@ -51,36 +51,40 @@ public class AuthProvider implements AuthenticationProvider { ...@@ -51,36 +51,40 @@ public class AuthProvider implements AuthenticationProvider {
LOG.info("login request for user "+username); LOG.info("login request for user "+username);
// LDAP Service Call // LDAP Service Call
User user = null; User user = null;
user = new User(); user = new User();
try {
// user = userService.findById(username); user = userService.findById(username);
LOG.info("---------"+user); // LOG.info("---------"+user);
//
//
//
user.setId("1"); // user.setId("1");
user.setBranchCode("abc"); // user.setBranchCode("abc");
user.setFirstName("xyz"); // user.setFirstName("xyz");
user.setLastName("abc"); // user.setLastName("abc");
user.setGender("m"); // user.setGender("m");
user.setMobileNo("8238284225"); // user.setMobileNo("8238284225");
user.setBranchName("abc"); // user.setBranchName("abc");
user.setMiddleName("pqr"); // user.setMiddleName("pqr");
user.setEmailId("gosranineel4@gmail.com"); // user.setEmailId("gosranineel4@gmail.com");
user.setDesignation("PBA"); // user.setDesignation("PBA");
user.setPan("pan"); // user.setPan("pan");
user.setAgentStatus("1"); // user.setAgentStatus("1");
user.setRole(RolesConstant.LEADER); // user.setRole(RolesConstant.LEADER);
//
userService.save(user); userService.save(user);
LOG.info("user-----"+user); LOG.info("user-----"+user);
List<String> roles = new ArrayList<String>(); List<String> roles = new ArrayList<String>();
roles.add("leader"); roles.add("leader");
return new UsernamePasswordAuthenticationToken(UserPrincipal.create(user,(LoginRequest)authentication.getDetails()), password,roles.stream().map(x -> new SimpleGrantedAuthority("ROLE_"+x)).collect(Collectors.toList())); 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 { ...@@ -76,7 +76,7 @@ public class UserPrincipal implements UserDetails {
).collect(Collectors.toList()); ).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