Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public SignInWrapper call(SignInInput input) throws MpxConnectorException{
- LOGGER.debug("START - AbstractMpxConnector.SingInConnector.call");
- RestTemplate restTemplate = new RestTemplate();
- ObjectMapper mapper = new ObjectMapper();
- byte[] sessionKeyEncrypted = null;
- byte[] userInfoEncrypted = null;
- try{
- String userJson = mapper.writeValueAsString(input.getUserInfo());
- sessionKeyEncrypted = encrypt(input.getRandomSymmetricSessionKey(), ENCRYPT_ALGORITHM.RSA);
- userInfoEncrypted = encrypt(userJson, input.getRandomSymmetricSessionKey(), ENCRYPT_ALGORITHM.RC4);
- }catch(Exception e){
- LOGGER.error("Error encrypt: ", e);
- }
- String username = MPX_SIGNIN_PID + "/" + input.getUserInfo().getUserName();
- String password = Base64Utils.encodeToString(sessionKeyEncrypted) + "|" + Base64Utils.encodeToString(userInfoEncrypted);
- HttpEntity<String> entity = new HttpEntity<String>(getUserProperty(this.duration, this.idleTimeout), configureBasicAuthorization(username, password));
- UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(MPX_SIGNIN).queryParam("account", MPX_SIGNIN_ACCOUNT);
- ResponseEntity<SignInWrapper> response = restTemplate.exchange(builder.build().toString(), HttpMethod.POST, entity, SignInWrapper.class);
- super.exceptionManager(response);
- super.exceptionManager(response.getBody().getAdditionalProperties());
- LOGGER.debug("STOP - AbstractMpxConnector.SingInConnector.call");
- return response.getBody();
- }
- protected HttpHeaders configureBasicAuthorization(String username, String password) {
- return new HttpHeaders() {
- private static final long serialVersionUID = 1L;
- {
- if(username != null && password != null) {
- String auth = username + ":" + password;
- String authHeader = "Basic " + Base64Utils.encodeToString(auth.getBytes());
- LOGGER.debug("USERNAME: {} HEADER: {}", username, authHeader);
- set("Authorization", authHeader);
- }
- }
- };
- }
Add Comment
Please, Sign In to add comment