From d61be0bf633020c6bd989e603bb983dc7a45b78b Mon Sep 17 00:00:00 2001
From: Arnab Dutta <32794267+duttarnab@users.noreply.github.com>
Date: Tue, 26 Apr 2022 18:14:02 +0530
Subject: [PATCH] fix(admin-ui): the backend issues related to jetty 11
migration #1258 (#1259)
---
.../model/config/adminui/AdminPermission.java | 10 +
.../adminui/LicenseSpringCredentials.java | 18 ++
.../plugins/admin-ui-plugin/pom.xml | 39 +--
.../src/main/assembly/assembly.xml | 10 -
.../model/config/LicenseConfiguration.java | 66 +----
.../adminui/rest/license/LicenseResource.java | 18 --
.../adminui/service/auth/OAuth2Service.java | 26 +-
.../config/AUIConfigurationService.java | 5 +-
.../license/LicenseDetailsService.java | 272 +++++++++---------
.../ca/plugin/adminui/utils/AppConstants.java | 1 +
.../plugin/adminui/utils/ClientFactory.java | 43 +++
.../ca/plugin/adminui/utils/CommonUtils.java | 33 +++
12 files changed, 276 insertions(+), 265 deletions(-)
create mode 100644 jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/ClientFactory.java
diff --git a/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/AdminPermission.java b/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/AdminPermission.java
index cfc3a073ca1..66d979541ca 100644
--- a/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/AdminPermission.java
+++ b/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/AdminPermission.java
@@ -5,6 +5,7 @@
public class AdminPermission {
private String permission;
private String description;
+ private Boolean defaultPermissionInToken;
public String getPermission() {
return permission;
@@ -22,6 +23,14 @@ public void setDescription(String description) {
this.description = description;
}
+ public Boolean getDefaultPermissionInToken() {
+ return defaultPermissionInToken;
+ }
+
+ public void setDefaultPermissionInToken(Boolean defaultPermissionInToken) {
+ this.defaultPermissionInToken = defaultPermissionInToken;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -40,6 +49,7 @@ public String toString() {
return "AdminPermission{" +
"permission='" + permission + '\'' +
", description='" + description + '\'' +
+ ", defaultPermissionInToken='" + defaultPermissionInToken + '\'' +
'}';
}
}
diff --git a/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/LicenseSpringCredentials.java b/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/LicenseSpringCredentials.java
index 09e1ff11c72..1a3e42cec40 100644
--- a/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/LicenseSpringCredentials.java
+++ b/jans-auth-server/model/src/main/java/io/jans/as/model/config/adminui/LicenseSpringCredentials.java
@@ -5,6 +5,8 @@ public class LicenseSpringCredentials {
private String productCode;
private String sharedKey;
private String managementKey;
+ private String hardwareId;
+ private String licenseKey;
public String getApiKey() {
return apiKey;
@@ -38,6 +40,22 @@ public void setManagementKey(String managementKey) {
this.managementKey = managementKey;
}
+ public String getHardwareId() {
+ return hardwareId;
+ }
+
+ public void setHardwareId(String hardwareId) {
+ this.hardwareId = hardwareId;
+ }
+
+ public String getLicenseKey() {
+ return licenseKey;
+ }
+
+ public void setLicenseKey(String licenseKey) {
+ this.licenseKey = licenseKey;
+ }
+
@Override
public String toString() {
return "LicenseSpringCredentials{" +
diff --git a/jans-config-api/plugins/admin-ui-plugin/pom.xml b/jans-config-api/plugins/admin-ui-plugin/pom.xml
index cf97399ab7c..73eaaed9ad6 100644
--- a/jans-config-api/plugins/admin-ui-plugin/pom.xml
+++ b/jans-config-api/plugins/admin-ui-plugin/pom.xml
@@ -12,11 +12,6 @@
io.jans.jans-config-api.plugins
admin-ui-plugin
-
- 2.4.5
- 5.8.0
-
-
jdk-java
@@ -25,27 +20,6 @@
-
-
- com.licensespring
- licensespring-license-client
- ${licenseSpring.version}
-
-
- com.licensespring
- licensespring-license-management
- ${licenseSpring.version}
-
-
- net.java.dev.jna
- jna
- ${jna.version}
-
-
- net.java.dev.jna
- jna-platform
- ${jna.version}
-
io.jans
@@ -92,6 +66,19 @@
junit
junit
+
+
+ jakarta.xml.bind
+ jakarta.xml.bind-api
+ 2.3.2
+
+
+
+
+ org.glassfish.jaxb
+ jaxb-runtime
+ 2.3.2
+
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/assembly/assembly.xml b/jans-config-api/plugins/admin-ui-plugin/src/main/assembly/assembly.xml
index e263f8ae345..4334dfdd196 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/assembly/assembly.xml
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/assembly/assembly.xml
@@ -12,16 +12,6 @@
/
false
- com.licensespring:licensespring-license-client
- com.licensespring:licensespring-core
- com.licensespring:licensespring-license-management
- io.github.openfeign:feign-core
- io.github.openfeign:feign-gson
- io.github.openfeign:feign-okhttp
- io.github.openfeign:feign-slf4j
- net.java.dev.jna:jna
- net.java.dev.jna:jna-platform
- com.github.oshi:oshi-core
io.jans:jans-auth-model
runtime
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/model/config/LicenseConfiguration.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/model/config/LicenseConfiguration.java
index 3101f669a0f..378c91e065d 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/model/config/LicenseConfiguration.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/model/config/LicenseConfiguration.java
@@ -1,8 +1,5 @@
package io.jans.ca.plugin.adminui.model.config;
-import com.licensespring.LicenseManager;
-import com.licensespring.LicenseSpringConfiguration;
-import com.licensespring.model.exceptions.LicenseSpringException;
import org.slf4j.Logger;
import jakarta.inject.Inject;
@@ -16,42 +13,17 @@ public class LicenseConfiguration {
private String productCode;
private String sharedKey;
private String managementKey;
- private Boolean enabled = Boolean.TRUE;
- LicenseSpringConfiguration licenseSpringConfiguration;
- LicenseManager licenseManager;
+ private String hardwareId;
+ private String licenseKey;
public LicenseConfiguration() {
}
- public LicenseConfiguration(String apiKey, String productCode, String sharedKey, String managementKey, Boolean enabled) {
+ public LicenseConfiguration(String apiKey, String productCode, String sharedKey, String managementKey) {
this.apiKey = apiKey;
this.productCode = productCode;
this.sharedKey = sharedKey;
- this.enabled = enabled;
this.managementKey = managementKey;
-
- if (Boolean.TRUE.equals(this.enabled)) {
- initializeLicenseManager();
- }
- }
-
- public void initializeLicenseManager() {
- try {
- this.licenseSpringConfiguration = LicenseSpringConfiguration.builder()
- .apiKey(apiKey)
- .productCode(productCode)
- .sharedKey(sharedKey)
- .build();
-
- this.licenseManager = LicenseManager.getInstance();
-
- if (!licenseManager.isInitialized()) {
- licenseManager.initialize(licenseSpringConfiguration);
- }
- } catch (LicenseSpringException e) {
- log.error("Error in initializing LicenseManager. ");
- throw e;
- }
}
public String getApiKey() {
@@ -78,35 +50,27 @@ public void setSharedKey(String sharedKey) {
this.sharedKey = sharedKey;
}
- public Boolean getEnabled() {
- return enabled;
- }
-
- public void setEnabled(Boolean enabled) {
- this.enabled = enabled;
- }
-
- public LicenseSpringConfiguration getLicenseSpringConfiguration() {
- return licenseSpringConfiguration;
+ public String getManagementKey() {
+ return managementKey;
}
- public void setLicenseSpringConfiguration(LicenseSpringConfiguration licenseSpringConfiguration) {
- this.licenseSpringConfiguration = licenseSpringConfiguration;
+ public void setManagementKey(String managementKey) {
+ this.managementKey = managementKey;
}
- public LicenseManager getLicenseManager() {
- return licenseManager;
+ public String getHardwareId() {
+ return hardwareId;
}
- public void setLicenseManager(LicenseManager licenseManager) {
- this.licenseManager = licenseManager;
+ public void setHardwareId(String hardwareId) {
+ this.hardwareId = hardwareId;
}
- public String getManagementKey() {
- return managementKey;
+ public String getLicenseKey() {
+ return licenseKey;
}
- public void setManagementKey(String managementKey) {
- this.managementKey = managementKey;
+ public void setLicenseKey(String licenseKey) {
+ this.licenseKey = licenseKey;
}
}
\ No newline at end of file
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/rest/license/LicenseResource.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/rest/license/LicenseResource.java
index f2ebc9306f4..b30491f9e0f 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/rest/license/LicenseResource.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/rest/license/LicenseResource.java
@@ -100,22 +100,4 @@ public Response getLicenseDetails() {
return Response.serverError().entity(ErrorResponse.GET_LICENSE_DETAILS_ERROR.getDescription()).build();
}
}
-
- @PUT
- @Path(LICENSE_DETAILS)
- @ProtectedApi(scopes={SCOPE_LICENSE_WRITE})
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateLicenseDetails(@Valid @NotNull LicenseRequest licenseRequest) {
- try {
- log.info("Trying to update license details.");
- LicenseResponse licenseResponse = licenseDetailsService.updateLicenseDetails(licenseRequest);
- return Response.ok(licenseResponse).build();
- } catch (ApplicationException e) {
- log.error(ErrorResponse.UPDATE_LICENSE_DETAILS_ERROR.getDescription(), e);
- return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
- } catch (Exception e) {
- log.error(ErrorResponse.UPDATE_LICENSE_DETAILS_ERROR.getDescription(), e);
- return Response.serverError().entity(ErrorResponse.UPDATE_LICENSE_DETAILS_ERROR.getDescription()).build();
- }
- }
}
\ No newline at end of file
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/auth/OAuth2Service.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/auth/OAuth2Service.java
index 53f5b022289..a7d492fa0a6 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/auth/OAuth2Service.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/auth/OAuth2Service.java
@@ -14,8 +14,10 @@
import io.jans.ca.plugin.adminui.model.auth.UserInfoResponse;
import io.jans.ca.plugin.adminui.rest.auth.OAuth2Resource;
import io.jans.ca.plugin.adminui.service.config.AUIConfigurationService;
+import io.jans.ca.plugin.adminui.utils.ClientFactory;
import io.jans.ca.plugin.adminui.utils.CommonUtils;
import io.jans.ca.plugin.adminui.utils.ErrorResponse;
+import jakarta.ws.rs.client.Invocation;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
@@ -136,7 +138,6 @@ public TokenResponse getApiProtectionToken(String userInfoJwt) throws Applicatio
}
public UserInfoResponse getUserInfo(UserInfoRequest userInfoRequest) throws ApplicationException {
- ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
try {
log.debug("Getting User-Info from auth-server: {}", userInfoRequest.getAccessToken());
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
@@ -156,11 +157,10 @@ public UserInfoResponse getUserInfo(UserInfoRequest userInfoRequest) throws Appl
MultivaluedMap body = new MultivaluedHashMap<>();
body.putSingle("access_token", accessToken);
- ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).httpEngine(engine).build();
- ResteasyWebTarget target = client.target(UriBuilder.fromPath(auiConfiguration.getAuthServerUserInfoEndpoint()));
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(auiConfiguration.getAuthServerUserInfoEndpoint());
+ request.header("Authorization", "Bearer " + accessToken);
- Response response = target.request()
- .header("Authorization", "Bearer " + accessToken)
+ Response response = request
.post(Entity.form(body));
log.debug("User-Info response status code: {}", response.getStatus());
@@ -187,10 +187,6 @@ public UserInfoResponse getUserInfo(UserInfoRequest userInfoRequest) throws Appl
} catch (Exception e) {
log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.GET_USER_INFO_ERROR.getDescription());
- } finally {
- if (engine != null) {
- engine.close();
- }
}
return null;
}
@@ -204,10 +200,8 @@ public io.jans.as.client.TokenResponse getToken(TokenRequest tokenRequest, Strin
}
public io.jans.as.client.TokenResponse getToken(TokenRequest tokenRequest, String tokenEndpoint, String userInfoJwt) {
- ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
- try {
- engine.setFollowRedirects(false);
+ try {
MultivaluedMap body = new MultivaluedHashMap<>();
if (!Strings.isNullOrEmpty(tokenRequest.getCode())) {
body.putSingle("code", tokenRequest.getCode());
@@ -225,10 +219,8 @@ public io.jans.as.client.TokenResponse getToken(TokenRequest tokenRequest, Strin
body.putSingle("redirect_uri", tokenRequest.getRedirectUri());
body.putSingle("client_id", tokenRequest.getAuthUsername());
- ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).httpEngine(engine).build();
- ResteasyWebTarget target = client.target(UriBuilder.fromPath(tokenEndpoint));
-
- Response response = target.request()
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(tokenEndpoint);
+ Response response = request
.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials())
.post(Entity.form(body));
@@ -247,8 +239,6 @@ public io.jans.as.client.TokenResponse getToken(TokenRequest tokenRequest, Strin
log.error("Problems processing token call");
throw e;
- } finally {
- engine.close();
}
return null;
}
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/config/AUIConfigurationService.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/config/AUIConfigurationService.java
index b83c497b564..914450eb4c9 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/config/AUIConfigurationService.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/service/config/AUIConfigurationService.java
@@ -80,14 +80,15 @@ private AUIConfiguration addPropertiesToAUIConfiguration(Properties props) {
LicenseConfiguration licenseConfiguration = new LicenseConfiguration();
AdminConf adminConf = entryManager.find(AdminConf.class, AppConstants.CONFIG_DN);
LicenseSpringCredentials licenseSpringCredentials = adminConf.getDynamic().getLicenseSpringCredentials();
+
if(licenseSpringCredentials != null)
{
licenseConfiguration.setApiKey(licenseSpringCredentials.getApiKey());
licenseConfiguration.setProductCode(licenseSpringCredentials.getProductCode());
licenseConfiguration.setSharedKey(licenseSpringCredentials.getSharedKey());
licenseConfiguration.setManagementKey(licenseSpringCredentials.getManagementKey());
- licenseConfiguration.setEnabled(Boolean.TRUE);
- licenseConfiguration.initializeLicenseManager();
+ licenseConfiguration.setHardwareId(licenseSpringCredentials.getHardwareId());
+ licenseConfiguration.setLicenseKey(licenseSpringCredentials.getLicenseKey());
}
auiConfig.setLicenseConfiguration(licenseConfiguration);
return auiConfig;
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 9709d2e429c..523b95e3544 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
@@ -1,15 +1,6 @@
package io.jans.ca.plugin.adminui.service.license;
import com.google.common.base.Strings;
-import com.licensespring.License;
-import com.licensespring.LicenseManager;
-import com.licensespring.internal.services.NowDateProvider;
-import com.licensespring.management.ManagementConfiguration;
-import com.licensespring.management.dto.SearchResult;
-import com.licensespring.management.dto.request.SearchLicensesRequest;
-import com.licensespring.management.dto.request.UpdateLicenseRequest;
-import com.licensespring.management.model.BackOfficeLicense;
-import com.licensespring.model.ActivationLicense;
import io.jans.as.model.config.adminui.AdminConf;
import io.jans.as.model.config.adminui.LicenseSpringCredentials;
import io.jans.ca.plugin.adminui.model.auth.LicenseApiResponse;
@@ -17,30 +8,31 @@
import io.jans.ca.plugin.adminui.model.auth.LicenseResponse;
import io.jans.ca.plugin.adminui.model.config.AUIConfiguration;
import io.jans.ca.plugin.adminui.model.config.LicenseConfiguration;
-import io.jans.ca.plugin.adminui.model.exception.ApplicationException;
import io.jans.ca.plugin.adminui.service.config.AUIConfigurationService;
import io.jans.ca.plugin.adminui.utils.AppConstants;
+import io.jans.ca.plugin.adminui.utils.ClientFactory;
+import io.jans.ca.plugin.adminui.utils.CommonUtils;
import io.jans.ca.plugin.adminui.utils.ErrorResponse;
import io.jans.orm.PersistenceEntryManager;
-import org.jboss.resteasy.client.jaxrs.ResteasyClient;
-import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
-import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
-import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine;
-import org.slf4j.Logger;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import jakarta.json.JsonObject;
-import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.slf4j.Logger;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
+import java.util.UUID;
@Singleton
public class LicenseDetailsService {
@@ -56,7 +48,14 @@ public class LicenseDetailsService {
public LicenseApiResponse saveLicenseSpringCredentials(LicenseSpringCredentials licenseSpringCredentials) {
try {
- if (!licenseCredentialsValid(licenseSpringCredentials)) {
+ String hardwareId = UUID.randomUUID().toString();
+ LicenseConfiguration licenseConfiguration = new LicenseConfiguration(licenseSpringCredentials.getApiKey(),
+ licenseSpringCredentials.getProductCode(),
+ licenseSpringCredentials.getSharedKey(),
+ licenseSpringCredentials.getManagementKey());
+ licenseConfiguration.setHardwareId(hardwareId);
+
+ if (!licenseCredentialsValid(licenseConfiguration)) {
return createLicenseResponse(false, 400, "The license credentials are not valid.");
}
//check is license is already active
@@ -64,15 +63,11 @@ public LicenseApiResponse saveLicenseSpringCredentials(LicenseSpringCredentials
if (licenseApiResponse.isApiResult()) {
return createLicenseResponse(false, 500, "The license has been already activated.");
}
+
+ licenseSpringCredentials.setHardwareId(hardwareId);
//set license-spring configuration
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
- LicenseConfiguration licenseConfiguration = new LicenseConfiguration(licenseSpringCredentials.getApiKey(),
- licenseSpringCredentials.getProductCode(),
- licenseSpringCredentials.getSharedKey(),
- licenseSpringCredentials.getManagementKey(),
- Boolean.TRUE);
-
auiConfiguration.setLicenseConfiguration(licenseConfiguration);
auiConfigurationService.setAuiConfiguration(auiConfiguration);
@@ -91,18 +86,38 @@ public LicenseApiResponse saveLicenseSpringCredentials(LicenseSpringCredentials
public LicenseApiResponse checkLicense() {
try {
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
-
- License activeLicense = auiConfiguration.getLicenseConfiguration().getLicenseManager().getCurrent();
- if (activeLicense == null) {
+ LicenseConfiguration licenseConfiguration = auiConfiguration.getLicenseConfiguration();
+ if (licenseConfiguration == null || Strings.isNullOrEmpty(licenseConfiguration.getApiKey())) {
+ log.info("License api-keys not present ");
+ return createLicenseResponse(false, 500, "License api-keys not present.");
+ }
+ if (Strings.isNullOrEmpty(licenseConfiguration.getLicenseKey())) {
log.info("Active license for admin-ui not present ");
return createLicenseResponse(false, 500, "Active license not present.");
- } else {
- log.debug("Active license for admin-ui found : {} ", activeLicense.getProduct());
- License updatedLicense = auiConfiguration.getLicenseConfiguration()
- .getLicenseManager()
- .checkLicense(activeLicense);
- return createLicenseResponse(updatedLicense != null && !activeLicense.getData().isExpired(), 200, "");
}
+ //check license-key
+ String checkLicenseUrl = (new StringBuffer()).append(AppConstants.LICENSE_SPRING_API_URL)
+ .append("check_license?license_key=")
+ .append(licenseConfiguration.getLicenseKey())
+ .append("&product=")
+ .append(licenseConfiguration.getProductCode())
+ .append("&hardware_id=")
+ .append(licenseConfiguration.getHardwareId()).toString();
+
+ MultivaluedMap headers = createHeaderMap(licenseConfiguration);
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(checkLicenseUrl);
+ request.headers(headers);
+ Response response = request.get();
+
+ log.info("license Credentials request status code: {}", response.getStatus());
+ if (response.getStatus() == 200) {
+ JsonObject entity = response.readEntity(JsonObject.class);
+ if (entity.getBoolean("license_active") && !entity.getBoolean("is_expired")) {
+ return createLicenseResponse(true, 200, "Valid license present.");
+ }
+ }
+ return createLicenseResponse(false, 500, "Active license not present.");
+
} catch (Exception e) {
log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
return createLicenseResponse(false, 500, ErrorResponse.CHECK_LICENSE_ERROR.getDescription());
@@ -116,14 +131,43 @@ public LicenseApiResponse activateLicense(LicenseRequest licenseRequest) {
return createLicenseResponse(false, 500, "The license has been already activated.");
}
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
+ LicenseConfiguration licenseConfiguration = auiConfiguration.getLicenseConfiguration();
- LicenseManager licenseManager = auiConfiguration.getLicenseConfiguration().getLicenseManager();
try {
log.debug("Trying to activate License.");
- ActivationLicense keyBased = ActivationLicense.fromKey(licenseRequest.getLicenseKey());
- License license = licenseManager.activateLicense(keyBased);
- log.debug("License activated : {} ", license.getProduct());
- return createLicenseResponse(!license.getData().isExpired(), 200, "");
+ String activateLicenseUrl = (new StringBuffer()).append(AppConstants.LICENSE_SPRING_API_URL)
+ .append("activate_license").toString();
+
+ MultivaluedMap headers = createHeaderMap(licenseConfiguration);
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(activateLicenseUrl);
+ request.headers(headers);
+
+ MultivaluedMap body = new MultivaluedHashMap<>();
+ body.putSingle("license_key", licenseRequest.getLicenseKey());
+ body.putSingle("hardware_id", licenseConfiguration.getHardwareId());
+ body.putSingle("product", licenseConfiguration.getProductCode());
+
+ Response response = request
+ .post(Entity.entity(body, MediaType.APPLICATION_JSON));
+ log.info("license Activation request status code: {}", response.getStatus());
+ if (response.getStatus() == 200) {
+ JsonObject entity = response.readEntity(JsonObject.class);
+ if (entity.getString("license_key").equals(licenseRequest.getLicenseKey())) {
+ //save license spring credentials
+ AdminConf adminConf = entryManager.find(AdminConf.class, AppConstants.CONFIG_DN);
+ LicenseSpringCredentials licenseSpringCredentials = adminConf.getDynamic().getLicenseSpringCredentials();
+ licenseSpringCredentials.setLicenseKey(licenseRequest.getLicenseKey());
+ adminConf.getDynamic().setLicenseSpringCredentials(licenseSpringCredentials);
+ entryManager.merge(adminConf);
+ //save in license configuration
+ licenseConfiguration.setLicenseKey(licenseRequest.getLicenseKey());
+ auiConfiguration.setLicenseConfiguration(licenseConfiguration);
+ auiConfigurationService.setAuiConfiguration(auiConfiguration);
+
+ return createLicenseResponse(true, 200, "License have been activated.");
+ }
+ }
+ return createLicenseResponse(false, response.getStatus(), "License is not activated.");
} catch (Exception e) {
log.error(ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription(), e);
return createLicenseResponse(false, 500, ErrorResponse.ACTIVATE_LICENSE_ERROR.getDescription());
@@ -134,28 +178,46 @@ public LicenseResponse getLicenseDetails() {
LicenseResponse licenseResponse = new LicenseResponse();
try {
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
-
- License activeLicense = auiConfiguration.getLicenseConfiguration().getLicenseManager().getCurrent();
- if (activeLicense == null) {
- log.debug("Active license for admin-ui not present ");
- licenseResponse.setLicenseEnabled(false);
- return licenseResponse;
- } else {
- log.debug("Active license for admin-ui found : {}", activeLicense.getProduct());
- licenseResponse.setLicenseEnabled(true);
- licenseResponse.setProductName(activeLicense.getProduct().getProductName());
- licenseResponse.setProductCode(activeLicense.getProduct().getShortCode());
- licenseResponse.setLicenseType(activeLicense.getData().getLicenseType().name());
- licenseResponse.setMaxActivations(activeLicense.getData().getMaxActivations());
- licenseResponse.setLicenseKey(activeLicense.getIdentity().getLicenseKey());
- licenseResponse.setValidityPeriod(activeLicense.getData().getValidityPeriod().toString());
- licenseResponse.setCompanyName(activeLicense.getData().getCustomer().getCompanyName());
- licenseResponse.setCustomerEmail(activeLicense.getData().getCustomer().getEmail());
- licenseResponse.setCustomerFirstName(activeLicense.getData().getCustomer().getFirstName());
- licenseResponse.setCustomerLastName(activeLicense.getData().getCustomer().getLastName());
- licenseResponse.setLicenseActive(!activeLicense.getData().isExpired());
- return licenseResponse;
+ LicenseConfiguration licenseConfiguration = auiConfiguration.getLicenseConfiguration();
+
+ //check license-key
+ String checkLicenseUrl = (new StringBuffer()).append(AppConstants.LICENSE_SPRING_API_URL)
+ .append("check_license?license_key=")
+ .append(licenseConfiguration.getLicenseKey())
+ .append("&product=")
+ .append(licenseConfiguration.getProductCode())
+ .append("&hardware_id=")
+ .append(licenseConfiguration.getHardwareId()).toString();
+
+ MultivaluedMap headers = createHeaderMap(licenseConfiguration);
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(checkLicenseUrl);
+ request.headers(headers);
+
+ Response response = request.get();
+
+ log.info("license Credentials request status code: {}", response.getStatus());
+ if (response.getStatus() == 200) {
+ JsonObject entity = response.readEntity(JsonObject.class);
+ if (entity.getBoolean("license_active") && !entity.getBoolean("is_expired")) {
+ log.debug("Active license for admin-ui found : {}", entity.getJsonObject("product_details").getString("product_name"));
+ licenseResponse.setLicenseEnabled(true);
+ licenseResponse.setProductName(entity.getJsonObject("product_details").getString("product_name"));
+ licenseResponse.setProductCode(entity.getJsonObject("product_details").getString("short_code"));
+ licenseResponse.setLicenseType(entity.getString("license_type"));
+ licenseResponse.setMaxActivations(entity.getInt("max_activations"));
+ licenseResponse.setLicenseKey(entity.getString("license_key"));
+ licenseResponse.setValidityPeriod(entity.getString("validity_period"));
+ licenseResponse.setCompanyName(entity.getJsonObject("customer").getString("company_name"));
+ licenseResponse.setCustomerEmail(entity.getJsonObject("customer").getString("email"));
+ licenseResponse.setCustomerFirstName(entity.getJsonObject("customer").getString("first_name"));
+ licenseResponse.setCustomerLastName(entity.getJsonObject("customer").getString("last_name"));
+ licenseResponse.setLicenseActive(entity.getBoolean("license_active"));
+ return licenseResponse;
+ }
}
+ log.debug("Active license for admin-ui not present ");
+ licenseResponse.setLicenseEnabled(false);
+ return licenseResponse;
} catch (Exception e) {
log.error(ErrorResponse.GET_LICENSE_DETAILS_ERROR.getDescription(), e);
licenseResponse.setLicenseEnabled(false);
@@ -164,87 +226,20 @@ public LicenseResponse getLicenseDetails() {
}
- public LicenseResponse updateLicenseDetails(LicenseRequest licenseRequest) throws ApplicationException {
- LicenseResponse licenseResponse = new LicenseResponse();
- log.debug("LicenseRequest params: {}", licenseRequest);
- try {
- if (Strings.isNullOrEmpty(licenseRequest.getValidityPeriod())) {
- log.error(ErrorResponse.LICENSE_VALIDITY_PERIOD_NOT_FOUND.getDescription());
- throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.LICENSE_VALIDITY_PERIOD_NOT_FOUND.getDescription());
- }
- if (licenseRequest.getMaxActivations() < 1) {
- log.error(ErrorResponse.INVALID_MAXIMUM_ACTIVATIONS.getDescription());
- throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.INVALID_MAXIMUM_ACTIVATIONS.getDescription());
- }
- if (licenseRequest.getValidityPeriod().length() > 10) {
- licenseRequest.setValidityPeriod(licenseRequest.getValidityPeriod().substring(0, 10));
- }
- AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
-
- ManagementConfiguration configuration = ManagementConfiguration.builder()
- .managementKey(auiConfiguration.getLicenseConfiguration().getManagementKey())
- .requestLogging(feign.Logger.Level.FULL)
- .build();
- //search license by license-key
- License activeLicense = auiConfiguration.getLicenseConfiguration().getLicenseManager().getCurrent();
- if (activeLicense == null) {
- licenseResponse.setLicenseEnabled(false);
- return licenseResponse;
- }
- SearchLicensesRequest request = SearchLicensesRequest.builder()
- .licenseKey(activeLicense.getIdentity().getLicenseKey())
- .limit(1)
- .build();
-
- com.licensespring.management.LicenseService licenseService = new com.licensespring.management.LicenseService(configuration);
- SearchResult response = licenseService.searchLicenses(request);
- //update license details
- UpdateLicenseRequest update = UpdateLicenseRequest.builder()
- .isTrial(false)
- .validityPeriod(licenseRequest.getValidityPeriod())
- .maxActivations(licenseRequest.getMaxActivations())
- .enabled(licenseRequest.getLicenseActive())
- .build();
-
- BackOfficeLicense updated = licenseService.updateLicense(response.getResults().get(0).getId(), update);
-
- //create LicenseResponse
- licenseResponse.setLicenseEnabled(true);
- licenseResponse.setProductName(activeLicense.getProduct().getProductName());
- licenseResponse.setProductCode(activeLicense.getProduct().getShortCode());
- licenseResponse.setLicenseType(activeLicense.getData().getLicenseType().name());
- licenseResponse.setLicenseKey(activeLicense.getIdentity().getLicenseKey());
- licenseResponse.setCompanyName(activeLicense.getData().getCustomer().getCompanyName());
- licenseResponse.setCustomerEmail(activeLicense.getData().getCustomer().getEmail());
- licenseResponse.setCustomerFirstName(activeLicense.getData().getCustomer().getFirstName());
- licenseResponse.setCustomerLastName(activeLicense.getData().getCustomer().getLastName());
-
- licenseResponse.setMaxActivations(updated.getMaxActivations());
- licenseResponse.setLicenseActive(updated.getActive());
- licenseResponse.setValidityPeriod(updated.getValidityPeriod());
- return licenseResponse;
-
- } catch (Exception e) {
- log.error(ErrorResponse.UPDATE_LICENSE_DETAILS_ERROR.getDescription(), e);
- throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.UPDATE_LICENSE_DETAILS_ERROR.getDescription());
- }
- }
-
- private MultivaluedMap createHeaderMap(LicenseSpringCredentials licenseSpringCredentials) {
- NowDateProvider provider = new NowDateProvider();
- String formattedDate = provider.getFormattedDate();
+ private MultivaluedMap createHeaderMap(LicenseConfiguration licenseConfiguration) {
+ String formattedDate = CommonUtils.getFormattedDate();
String signing_string = "licenseSpring\ndate: " + formattedDate;
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
- SecretKeySpec secret_key = new SecretKeySpec(licenseSpringCredentials.getSharedKey().getBytes(StandardCharsets.UTF_8), "HmacSHA256");
+ SecretKeySpec secret_key = new SecretKeySpec(licenseConfiguration.getSharedKey().getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256_HMAC.init(secret_key);
String signature = Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(signing_string.getBytes(StandardCharsets.UTF_8)));
MultivaluedMap headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Type", "application/json");
headers.putSingle("Date", formattedDate);
- headers.putSingle("Authorization", "algorithm=\"hmac-sha256\",headers=\"date\",signature=\"" + signature + "\",apiKey=\"" + licenseSpringCredentials.getApiKey() + "\"");
+ headers.putSingle("Authorization", "algorithm=\"hmac-sha256\",headers=\"date\",signature=\"" + signature + "\",apiKey=\"" + licenseConfiguration.getApiKey() + "\"");
return headers;
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
log.error("Error in generating authorization header", e);
@@ -253,16 +248,13 @@ private MultivaluedMap createHeaderMap(LicenseSpringCredentials
}
- private boolean licenseCredentialsValid(LicenseSpringCredentials licenseSpringCredentials) {
- ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
+ private boolean licenseCredentialsValid(LicenseConfiguration licenseConfiguration) {
+ MultivaluedMap headers = createHeaderMap(licenseConfiguration);
- ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).httpEngine(engine).build();
- ResteasyWebTarget target = client.target("https://api.licensespring.com/api/v4/product_details?product=" + licenseSpringCredentials.getProductCode());
- MultivaluedMap headers = createHeaderMap(licenseSpringCredentials);
+ Invocation.Builder request = ClientFactory.instance().getClientBuilder(AppConstants.LICENSE_SPRING_API_URL + "product_details?product=" + licenseConfiguration.getProductCode());
+ request.headers(headers);
- Response response = target.request()
- .headers(headers)
- .get();
+ Response response = request.get();
log.info("license Credentials request status code: {}", response.getStatus());
if (response.getStatus() == 200) {
JsonObject entity = response.readEntity(JsonObject.class);
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/AppConstants.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/AppConstants.java
index da6e76bcf5b..b19437ba2f4 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/AppConstants.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/AppConstants.java
@@ -2,4 +2,5 @@
public interface AppConstants {
public static final String CONFIG_DN = "ou=admin-ui,ou=configuration,o=jans";
+ public static final String LICENSE_SPRING_API_URL = "https://api.licensespring.com/api/v4/";
}
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/ClientFactory.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/ClientFactory.java
new file mode 100644
index 00000000000..f6549e035c3
--- /dev/null
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/ClientFactory.java
@@ -0,0 +1,43 @@
+package io.jans.ca.plugin.adminui.utils;
+
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.UriBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine;
+import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl;
+
+public class ClientFactory {
+ private final static ClientFactory INSTANCE = new ClientFactory();
+
+ private ClientFactory() {
+ }
+
+ public static ClientFactory instance() {
+ return INSTANCE;
+ }
+
+ /* public ResteasyWebTarget createResteasyWebTargetWithCompleteUrl(String url) {
+ ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
+
+ ResteasyClient client = ((ResteasyClientBuilderImpl) ClientBuilder.newBuilder()).httpEngine(engine).build();
+ ResteasyWebTarget target = client.target(url);
+
+ return target;
+ }
+
+ public ResteasyWebTarget createResteasyWebTarget(String url) {
+ ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
+
+ ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).httpEngine(engine).build();
+ ResteasyWebTarget target = client.target(UriBuilder.fromPath(url));
+
+ return target;
+ }*/
+
+ public static Invocation.Builder getClientBuilder(String url) {
+ return ClientBuilder.newClient().target(url).request();
+ }
+}
diff --git a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/CommonUtils.java b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/CommonUtils.java
index da94bbf3fae..82472620d85 100644
--- a/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/CommonUtils.java
+++ b/jans-config-api/plugins/admin-ui-plugin/src/main/java/io/jans/ca/plugin/adminui/utils/CommonUtils.java
@@ -1,12 +1,39 @@
package io.jans.ca.plugin.adminui.utils;
import com.google.common.base.Joiner;
+import io.jans.ca.plugin.adminui.model.config.LicenseConfiguration;
+import jakarta.inject.Inject;
+import jakarta.json.JsonObject;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.*;
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine;
+import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl;
+import org.slf4j.Logger;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Base64;
import java.util.Collection;
+import java.util.Locale;
public class CommonUtils {
+ @Inject
+ Logger log;
+ public static final DateTimeFormatter LS_DATE_FORMAT = DateTimeFormatter.ofPattern("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
+
+
public static String joinAndUrlEncode(Collection list) throws UnsupportedEncodingException {
if (list == null || list.isEmpty()) {
return "";
@@ -18,4 +45,10 @@ public static String encode(String str) throws UnsupportedEncodingException {
return URLEncoder.encode(str, "UTF-8");
}
+ public static String getFormattedDate() {
+ ZonedDateTime currentDateTime = ZonedDateTime.now();
+ ZonedDateTime gmtTime = currentDateTime.withZoneSameInstant(ZoneId.of("GMT"));
+ DateTimeFormatter currentTimeFormatter = LS_DATE_FORMAT;
+ return gmtTime.format(currentTimeFormatter);
+ }
}
\ No newline at end of file