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
…6099)

* fix: remove content-type in header from /retrieve GET request #6096

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>

* fix: remove content-type in header from /retrieve GET request #6096

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>

---------

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>
Signed-off-by: Mustafa Baser <mbaser@mail.com>
  • Loading branch information
duttarnab authored and devrimyatar committed Dec 30, 2023
1 parent c4df785 commit ff60c13
Showing 1 changed file with 47 additions and 30 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,13 +149,9 @@ public GenericResponse checkLicense() {
return CommonUtils.createGenericResponse(false, 404, ErrorResponse.LICENSE_NOT_PRESENT.getDescription());

} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return 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);
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 @@ -194,7 +191,6 @@ public GenericResponse retrieveLicense() {

Invocation.Builder request = ClientFactory.instance().getClientBuilder(retriveLicenseUrl);
request.header(AUTHORIZATION, BEARER + tokenResponse.getAccessToken());
request.header(CONTENT_TYPE, APPLICATION_JSON);
response = request.get();

log.info("license request status code: {}", response.getStatus());
Expand All @@ -215,7 +211,7 @@ public GenericResponse retrieveLicense() {

if (response.getStatus() == 402) {
log.error("Payment Required: 402");
return CommonUtils.createGenericResponse(false, 402, "Payment Required.");
return CommonUtils.createGenericResponse(false, 402, "Payment Required. Subscribe Admin UI license on Agama Lab.");
}
if (!Strings.isNullOrEmpty(jsonNode.get(MESSAGE).textValue())) {
log.error("{}: {}", LICENSE_RETRIEVE_ERROR_RESPONSE, jsonData);
Expand All @@ -225,13 +221,9 @@ public GenericResponse retrieveLicense() {
return CommonUtils.createGenericResponse(false, 500, ErrorResponse.RETRIEVE_LICENSE_ERROR.getDescription());

} catch (Exception e) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return 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);
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 @@ -306,13 +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) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return 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);
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 @@ -382,13 +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) {
if (response.getStatus() == 404) {
log.error("{}", LICENSE_APIS_404);
return 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);
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 @@ -481,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 @@ -508,4 +513,16 @@ private io.jans.as.client.TokenResponse generateToken(String opHost, String clie
return null;
}
}

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

0 comments on commit ff60c13

Please sign in to comment.