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: the admin-ui backend issues related to jetty 11 migration #1258 #1259

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
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 @@ -5,6 +5,7 @@
public class AdminPermission {
private String permission;
private String description;
private Boolean defaultPermissionInToken;

public String getPermission() {
return permission;
Expand All @@ -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;
Expand All @@ -40,6 +49,7 @@ public String toString() {
return "AdminPermission{" +
"permission='" + permission + '\'' +
", description='" + description + '\'' +
", defaultPermissionInToken='" + defaultPermissionInToken + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{" +
Expand Down
39 changes: 13 additions & 26 deletions jans-config-api/plugins/admin-ui-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<groupId>io.jans.jans-config-api.plugins</groupId>
<artifactId>admin-ui-plugin</artifactId>

<properties>
<licenseSpring.version>2.4.5</licenseSpring.version>
<jna.version>5.8.0</jna.version>
</properties>

<repositories>
<repository>
<id>jdk-java</id>
Expand All @@ -25,27 +20,6 @@
</repositories>

<dependencies>
<!-- license spring-->
<dependency>
<groupId>com.licensespring</groupId>
<artifactId>licensespring-license-client</artifactId>
<version>${licenseSpring.version}</version>
</dependency>
<dependency>
<groupId>com.licensespring</groupId>
<artifactId>licensespring-license-management</artifactId>
<version>${licenseSpring.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>${jna.version}</version>
</dependency>
<!-- config api -->
<dependency>
<groupId>io.jans</groupId>
Expand Down Expand Up @@ -92,6 +66,19 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- API, java.xml.bind module -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>

<!-- Runtime, com.sun.xml.bind module -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>com.licensespring:licensespring-license-client</include>
<include>com.licensespring:licensespring-core</include>
<include>com.licensespring:licensespring-license-management</include>
<include>io.github.openfeign:feign-core</include>
<include>io.github.openfeign:feign-gson</include>
<include>io.github.openfeign:feign-okhttp</include>
<include>io.github.openfeign:feign-slf4j</include>
<include>net.java.dev.jna:jna</include>
<include>net.java.dev.jna:jna-platform</include>
<include>com.github.oshi:oshi-core</include>
<include>io.jans:jans-auth-model</include>
</includes>
<scope>runtime</scope>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -156,11 +157,10 @@ public UserInfoResponse getUserInfo(UserInfoRequest userInfoRequest) throws Appl
MultivaluedMap<String, String> 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());
Expand All @@ -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;
}
Expand All @@ -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<String, String> body = new MultivaluedHashMap<>();
if (!Strings.isNullOrEmpty(tokenRequest.getCode())) {
body.putSingle("code", tokenRequest.getCode());
Expand All @@ -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));

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading