Faild login return data
This commit is contained in:
parent
d71fffd353
commit
6bde39f254
@ -7,4 +7,27 @@ public class LoginRequest {
|
||||
public String password;
|
||||
public String passwordEnc;
|
||||
public Object btMake; // number or single-char string accepted
|
||||
|
||||
public LoginRequest() {}
|
||||
|
||||
public LoginRequest(String opCard, String btId, String usrId, String password, String passwordEnc, Object btMake) {
|
||||
this.opCard = opCard;
|
||||
this.btId = btId;
|
||||
this.usrId = usrId;
|
||||
this.password = password;
|
||||
this.passwordEnc = passwordEnc;
|
||||
this.btMake = btMake;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LoginRequest{" +
|
||||
"opCard='" + opCard + '\'' +
|
||||
", btId='" + btId + '\'' +
|
||||
", usrId='" + usrId + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", passwordEnc='" + passwordEnc + '\'' +
|
||||
", btMake=" + btMake +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package com.example.cezenBTC.config;
|
||||
|
||||
import com.example.cezenBTC.DAO.UserOpsDAO;
|
||||
import com.example.cezenBTC.DTO.CenteralServerConect.ApiResponse;
|
||||
import com.example.cezenBTC.absbridge.model.LoginRequest;
|
||||
import com.example.cezenBTC.entity.user.UserEntity;
|
||||
import com.example.cezenBTC.service.ABS.ABSServiceForLogIn;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -113,3 +115,120 @@ public class CezenABSAuthenticationProvider implements AuthenticationProvider/*
|
||||
}
|
||||
|
||||
|
||||
//package com.example.cezenBTC.config;
|
||||
//
|
||||
//import com.example.cezenBTC.DAO.UserOpsDAO;
|
||||
//import com.example.cezenBTC.DTO.CenteralServerConect.ApiResponse;
|
||||
//import com.example.cezenBTC.absbridge.model.LoginRequest;
|
||||
//import com.example.cezenBTC.entity.user.UserEntity;
|
||||
//import com.example.cezenBTC.service.ABS.ABSServiceForLogIn;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.security.authentication.AuthenticationProvider;
|
||||
//import org.springframework.security.authentication.BadCredentialsException;
|
||||
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
//import org.springframework.security.core.Authentication;
|
||||
//import org.springframework.security.core.AuthenticationException;
|
||||
//import org.springframework.security.core.GrantedAuthority;
|
||||
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
//import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Component
|
||||
//public class CezenABSAuthenticationProvider implements AuthenticationProvider/* */{
|
||||
//
|
||||
// @Autowired
|
||||
// private UserOpsDAO userOpsDAO;
|
||||
//
|
||||
// @Autowired
|
||||
// private PasswordEncoder passwordEncoder;
|
||||
//
|
||||
// @Autowired
|
||||
// private ABSServiceForLogIn absServiceForLogIn;
|
||||
//
|
||||
// //@Override
|
||||
// public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
//
|
||||
// //get credentials from login form
|
||||
// String[] karthickHamu = authentication.getName().split(",");
|
||||
// String userStringId = karthickHamu[0];
|
||||
// String btId = karthickHamu[1];
|
||||
// String pwd = authentication.getCredentials().toString();
|
||||
//
|
||||
// System.out.println("user Id " + userStringId + " password " + pwd);
|
||||
//
|
||||
//
|
||||
// //sanity check
|
||||
// if (userStringId.isEmpty() || pwd.isEmpty()) return null;
|
||||
//
|
||||
// // validate if the user input consists of only numbers
|
||||
// // and in the number rage is only 12
|
||||
// try{
|
||||
// if(userStringId.length() != 12){
|
||||
// System.out.println("Number not equal to 12");
|
||||
// return null;
|
||||
// }
|
||||
// Double.parseDouble(userStringId);
|
||||
// }catch (Exception e){
|
||||
// System.out.println(e.toString());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //check for employee
|
||||
// ApiResponse user = null;
|
||||
// try {
|
||||
// //check if employee exists if yes then fetch details
|
||||
// user = this.absServiceForLogIn.loginInServiceListener(
|
||||
// new LoginRequest(userStringId, btId, "", pwd, "", ""));
|
||||
// } catch (Exception e) {
|
||||
// System.out.println(e.toString());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// //LoginRequest{opCard='021804111066', btId='0483', usrId='',
|
||||
// //password='0660000', passwordEnc='', btMake=}
|
||||
// if(user == null) return null;
|
||||
//
|
||||
// // this need to change for ABS
|
||||
// if (user.log() == null) {
|
||||
//
|
||||
// //then it is a match a number of springs granted authorities
|
||||
// List<GrantedAuthority> authorities = new ArrayList<>();
|
||||
//
|
||||
// //loop through the users authorities and add each of them to simple granted authority
|
||||
// try {
|
||||
// //check if user is part of permission set for admin signing in
|
||||
// boolean isAdmin = false;
|
||||
// for(var permission : user.getRoles()){
|
||||
// if(permission.getRole().equals("ROLE_admin")) isAdmin = true;
|
||||
// }
|
||||
// if(!isAdmin) throw new BadCredentialsException("no employee permission for given employee");
|
||||
//
|
||||
// user.getRoles().forEach(a -> authorities.add(new SimpleGrantedAuthority(a.getRole())));
|
||||
// } catch (Exception e) {
|
||||
// //use/**/r doesn't have permissions or roles = null
|
||||
// System.out.println(e.toString());
|
||||
// return null;
|
||||
// }
|
||||
// System.out.println("Auth DONE");
|
||||
//
|
||||
// return new UsernamePasswordAuthenticationToken(user.getUserIdNumber()+","+btId, pwd, authorities);
|
||||
// } else {
|
||||
// throw new BadCredentialsException("Invalid password!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean supports(Class<?> authentication) {
|
||||
// //tells spring that i want to support username password style of auth
|
||||
// return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -36,6 +36,12 @@ public class AbsController {
|
||||
@PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ApiResponse login(@RequestBody LoginRequest req) {
|
||||
|
||||
return absServiceForLogIn.loginRewWithFixedResponse(req);
|
||||
return absServiceForLogIn.loginInServiceListener(req);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/logintest", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public Object loginTest(@RequestBody LoginRequest req) {
|
||||
|
||||
return absServiceForLogIn.loginRew(req);
|
||||
}
|
||||
}
|
||||
@ -182,7 +182,35 @@ public class ABSServiceForLogIn {
|
||||
}
|
||||
|
||||
|
||||
public ApiResponse loginRewWithFixedResponse(LoginRequest req){
|
||||
// this will loop until the login is successful
|
||||
// this will mitigate the stability issue
|
||||
public ApiResponse loginInServiceListener(LoginRequest req){
|
||||
|
||||
System.out.println(req.toString());
|
||||
|
||||
ApiResponse apiResponse = this.loginRewWithFixedResponse(req);
|
||||
|
||||
// loop three times and fail if there is no data from the backend
|
||||
for(int i = 0; i < 5; i++){
|
||||
|
||||
if(apiResponse == null){
|
||||
System.out.println("Log in error, trying again");
|
||||
apiResponse = this.loginRewWithFixedResponse(req);
|
||||
System.out.println("The data is "+ apiResponse);
|
||||
}
|
||||
else{
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Log in failed, check server or connection");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private ApiResponse loginRewWithFixedResponse(LoginRequest req){
|
||||
|
||||
|
||||
ApiResponse apiResponse = null;
|
||||
|
||||
@ -324,24 +352,40 @@ public class ABSServiceForLogIn {
|
||||
if(log.cDateTime() != null){
|
||||
// then build the final json response apiResponse
|
||||
|
||||
apiResponse = new ApiResponse(
|
||||
(boolean)json.get("ok"),
|
||||
(String)json.get("target"),
|
||||
(String)json.get("sentHeaderHex"),
|
||||
(String)json.get("sentBodyHex"),
|
||||
(int)json.get("replyBytes"),
|
||||
(String)json.get("replyHexFirst64"),
|
||||
rcvHeaderRawMix,
|
||||
(boolean)json.get("success"),
|
||||
encryption,
|
||||
logDump
|
||||
);
|
||||
|
||||
}
|
||||
apiResponse = new ApiResponse(
|
||||
(boolean)json.get("ok"),
|
||||
(String)json.get("target"),
|
||||
(String)json.get("sentHeaderHex"),
|
||||
(String)json.get("sentBodyHex"),
|
||||
(int)json.get("replyBytes"),
|
||||
(String)json.get("replyHexFirst64"),
|
||||
rcvHeaderRawMix,
|
||||
(boolean)json.get("success"),
|
||||
encryption,
|
||||
logDump
|
||||
);
|
||||
|
||||
System.out.println(apiResponse);
|
||||
|
||||
//json.put("log", log);
|
||||
} catch (Exception ex) {
|
||||
json.put("parseLogError", ex.toString());
|
||||
}
|
||||
}else{
|
||||
apiResponse = new ApiResponse(
|
||||
(boolean)json.get("ok"),
|
||||
(String)json.get("target"),
|
||||
(String)json.get("sentHeaderHex"),
|
||||
(String)json.get("sentBodyHex"),
|
||||
(int)json.get("replyBytes"),
|
||||
(String)json.get("replyHexFirst64"),
|
||||
rcvHeaderRawMix,
|
||||
(boolean)json.get("success"),
|
||||
encryption,
|
||||
logDump
|
||||
);
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user