Guest User

Untitled

a guest
Jan 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public SignInWrapper call(SignInInput input) throws MpxConnectorException{
  2. LOGGER.debug("START - AbstractMpxConnector.SingInConnector.call");
  3.  
  4. RestTemplate restTemplate = new RestTemplate();
  5. ObjectMapper mapper = new ObjectMapper();
  6.  
  7. byte[] sessionKeyEncrypted = null;
  8. byte[] userInfoEncrypted = null;
  9.  
  10. try{
  11. String userJson = mapper.writeValueAsString(input.getUserInfo());
  12.  
  13. sessionKeyEncrypted = encrypt(input.getRandomSymmetricSessionKey(), ENCRYPT_ALGORITHM.RSA);
  14. userInfoEncrypted = encrypt(userJson, input.getRandomSymmetricSessionKey(), ENCRYPT_ALGORITHM.RC4);
  15. }catch(Exception e){
  16. LOGGER.error("Error encrypt: ", e);
  17. }
  18.  
  19. String username = MPX_SIGNIN_PID + "/" + input.getUserInfo().getUserName();
  20. String password = Base64Utils.encodeToString(sessionKeyEncrypted) + "|" + Base64Utils.encodeToString(userInfoEncrypted);
  21.  
  22. HttpEntity<String> entity = new HttpEntity<String>(getUserProperty(this.duration, this.idleTimeout), configureBasicAuthorization(username, password));
  23.  
  24. UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(MPX_SIGNIN).queryParam("account", MPX_SIGNIN_ACCOUNT);
  25.  
  26. ResponseEntity<SignInWrapper> response = restTemplate.exchange(builder.build().toString(), HttpMethod.POST, entity, SignInWrapper.class);
  27.  
  28. super.exceptionManager(response);
  29. super.exceptionManager(response.getBody().getAdditionalProperties());
  30.  
  31. LOGGER.debug("STOP - AbstractMpxConnector.SingInConnector.call");
  32.  
  33. return response.getBody();
  34. }
  35.  
  36. protected HttpHeaders configureBasicAuthorization(String username, String password) {
  37. return new HttpHeaders() {
  38. private static final long serialVersionUID = 1L;
  39. {
  40. if(username != null && password != null) {
  41. String auth = username + ":" + password;
  42. String authHeader = "Basic " + Base64Utils.encodeToString(auth.getBytes());
  43. LOGGER.debug("USERNAME: {} HEADER: {}", username, authHeader);
  44. set("Authorization", authHeader);
  45. }
  46. }
  47. };
  48. }
Add Comment
Please, Sign In to add comment