Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duttarnab you don't need to involve formatter, it's as simple as 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();
}
}