diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/license/LicenseDetailsService.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/license/LicenseDetailsService.java index b9f22930c26..3aa22ef0e60 100644 --- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/license/LicenseDetailsService.java +++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/license/LicenseDetailsService.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; @Singleton public class LicenseDetailsService extends BaseService { @@ -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 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()); @@ -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()); @@ -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); @@ -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 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()); @@ -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 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()); @@ -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 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()); @@ -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) { @@ -508,4 +513,16 @@ private io.jans.as.client.TokenResponse generateToken(String opHost, String clie return null; } } + + private Optional 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(); + } } \ No newline at end of file