Search in sources :

Example 1 with HandleURL

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;
}
Also used : HandleURL(com.vmware.flowgate.util.HandleURL) RestTemplate(org.springframework.web.client.RestTemplate) BasicAuthorizationInterceptor(org.springframework.http.client.support.BasicAuthorizationInterceptor)

Example 2 with HandleURL

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);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) HandleURL(com.vmware.flowgate.util.HandleURL) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HandleURL (com.vmware.flowgate.util.HandleURL)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)1 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)1 BasicAuthorizationInterceptor (org.springframework.http.client.support.BasicAuthorizationInterceptor)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 RestTemplate (org.springframework.web.client.RestTemplate)1