use of com.vmware.flowgate.util.HandleURL in project flowgate by vmware.
the class PowerIQAuth method auth.
public boolean auth(FacilitySoftwareConfig softwareConfig) throws KeyManagementException, SSLException, UnknownHostException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
RestTemplate restTemplate = getConnection(softwareConfig);
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(softwareConfig.getUserName(), softwareConfig.getPassword()));
ResponseEntity<String> resp = restTemplate.getForEntity(String.format(authUrl, softwareConfig.getServerURL()), String.class);
if (HttpStatus.MOVED_PERMANENTLY.equals(resp.getStatusCode())) {
HandleURL handleURL = new HandleURL();
String url = resp.getHeaders().get("Location").get(0);
ResponseEntity<String> response = restTemplate.getForEntity(String.format(url, authUrl), String.class);
if (HttpStatus.OK.equals(response.getStatusCode())) {
softwareConfig.setServerURL(handleURL.formatURL(url));
return true;
}
return false;
} else if (HttpStatus.OK.equals(resp.getStatusCode())) {
return true;
}
return false;
}
use of com.vmware.flowgate.util.HandleURL in project flowgate by vmware.
the class FacilitySoftwareController method createServer.
// create a new facilitySoftwareConfig
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createServer(@RequestBody FacilitySoftwareConfig config, HttpServletRequest request) {
HandleURL handleURL = new HandleURL();
config.setServerURL(handleURL.formatURL(config.getServerURL()));
if (repository.findOneByServerURL(config.getServerURL()) != null) {
String message = String.format("The server %s is already exsit.", config.getServerURL());
throw new WormholeRequestException(message);
}
serverValidationService.validateFacilityServer(config);
IntegrationStatus integrationStatus = new IntegrationStatus();
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
config.setIntegrationStatus(integrationStatus);
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
config.setUserId(user.getUserId());
encryptServerPassword(config);
BaseDocumentUtil.generateID(config);
repository.save(config);
decryptServerPassword(config);
notifyFacilityWorker(config);
}
Aggregations