Skip to content

Commit

Permalink
fix: remove content-type in header from /retrieve GET request #6096
Browse files Browse the repository at this point in the history
Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>
  • Loading branch information
duttarnab committed Sep 21, 2023
1 parent 6a6718d commit 56e14c8
Showing 1 changed file with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Singleton
public class LicenseDetailsService extends BaseService {
Expand Down Expand Up @@ -148,9 +149,9 @@ public GenericResponse checkLicense() {
return CommonUtils.createGenericResponse(false, 404, ErrorResponse.LICENSE_NOT_PRESENT.getDescription());

} catch (Exception e) {
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
Optional<GenericResponse> genericResOptional = handleLicenseApiNotAccessible(response);
if (genericResOptional.isPresent()) {
return genericResOptional.get();
}
log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.CHECK_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -220,9 +221,9 @@ public GenericResponse retrieveLicense() {
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.RETRIEVE_LICENSE_ERROR.getDescription());

} catch (Exception e) {
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
Optional<GenericResponse> genericResOptional = handleLicenseApiNotAccessible(response);
if (genericResOptional.isPresent()) {
return genericResOptional.get();
}
log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.RETRIEVE_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -297,9 +298,9 @@ public GenericResponse activateLicense(LicenseRequest licenseRequest) {
log.error("{}: {}", LICENSE_ACTIVATE_ERROR_RESPONSE, jsonData);
return CommonUtils.createGenericResponse(false, response.getStatus(), "License is not activated.");
} catch (Exception e) {
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
Optional<GenericResponse> genericResOptional = handleLicenseApiNotAccessible(response);
if (genericResOptional.isPresent()) {
return genericResOptional.get();
}
log.error(ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription());
Expand Down Expand Up @@ -369,9 +370,9 @@ public GenericResponse generateTrialLicense() {
log.error("{}: {}", TRIAL_GENERATE_ERROR_RESPONSE, jsonData);
return CommonUtils.createGenericResponse(false, response.getStatus(), "Error in generating trial license.");
} catch (Exception e) {
GenericResponse genericResponse = handleLicenseApiNotAccessible(response);
if (genericResponse == null) {
return genericResponse;
Optional<GenericResponse> genericResOptional = handleLicenseApiNotAccessible(response);
if (genericResOptional.isPresent()) {
return genericResOptional.get();
}
log.error(ErrorResponse.ERROR_IN_TRIAL_LICENSE.getDescription(), e);
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.ERROR_IN_TRIAL_LICENSE.getDescription());
Expand Down Expand Up @@ -464,6 +465,27 @@ public GenericResponse postSSA(SSARequest ssaRequest) {
licenseConfig.setOidcClient(oidcClient);
appConf.getMainSettings().setLicenseConfig(licenseConfig);
entryManager.merge(appConf);

// The above code is setting various properties of the `LicenseConfiguration` object obtained from the
// `AUIConfiguration` object. These properties include the scan authentication server hostname, scan API client
// ID, scan API client secret, hardware ID, and scan API hostname. After setting these properties, the
// `LicenseConfiguration` object is set back to the `AUIConfiguration` object, and the updated
// `AUIConfiguration` object is set back to the `auiConfigurationService`.
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
LicenseConfiguration licenseConfiguration = auiConfiguration.getLicenseConfiguration();

if(licenseConfiguration == null){
licenseConfiguration = new LicenseConfiguration();
}

licenseConfiguration.setScanAuthServerHostname(dcrResponse.getOpHost());
licenseConfiguration.setScanApiClientId(dcrResponse.getClientId());
licenseConfiguration.setScanApiClientSecret(dcrResponse.getClientSecret());
licenseConfiguration.setHardwareId(dcrResponse.getHardwareId());
licenseConfiguration.setScanApiHostname(dcrResponse.getScanHostname());
auiConfiguration.setLicenseConfiguration(licenseConfiguration);
auiConfigurationService.setAuiConfiguration(auiConfiguration);

return CommonUtils.createGenericResponse(true, 201, "SSA saved successfully.");

} catch (Exception e) {
Expand Down Expand Up @@ -492,15 +514,15 @@ private io.jans.as.client.TokenResponse generateToken(String opHost, String clie
}
}

private GenericResponse handleLicenseApiNotAccessible(Response response) {
private Optional<GenericResponse> handleLicenseApiNotAccessible(Response response) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404);
return Optional.of(CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_404));
}
if (response.getStatus() == 503) {
log.error("{}", LICENSE_APIS_503);
return CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503);
return Optional.of(CommonUtils.createGenericResponse(false, response.getStatus(), LICENSE_APIS_503));
}
return null;
return Optional.empty();
}
}

0 comments on commit 56e14c8

Please sign in to comment.