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

Jans config api issue 3991 #4052

Merged
merged 6 commits into from
Mar 7, 2023
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
@@ -0,0 +1,44 @@
package io.jans.as.model.config.adminui;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CredentialsEncryptionKeyDetails {

private String alg;
private String publicKey;
private String privateKey;

public String getAlg() {
return alg;
}

public void setAlg(String alg) {
this.alg = alg;
}

public String getPublicKey() {
return publicKey;
}

public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}

public String getPrivateKey() {
return privateKey;
}

public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}

@Override
public String toString() {
return "CredentialsEncryptionKeyDetails{" +
"alg='" + alg + '\'' +
", publicKey='" + publicKey + '\'' +
", privateKey='" + privateKey + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class DynamicConfig {
private List<AdminRole> roles;
private List<AdminPermission> permissions;
private List<RolePermissionMapping> rolePermissionMapping;
private LicenseSpringCredentials licenseSpringCredentials;

public List<AdminRole> getRoles() {
return roles;
Expand All @@ -32,12 +31,4 @@ public List<RolePermissionMapping> getRolePermissionMapping() {
public void setRolePermissionMapping(List<RolePermissionMapping> rolePermissionMapping) {
this.rolePermissionMapping = rolePermissionMapping;
}

public LicenseSpringCredentials getLicenseSpringCredentials() {
return licenseSpringCredentials;
}

public void setLicenseSpringCredentials(LicenseSpringCredentials licenseSpringCredentials) {
this.licenseSpringCredentials = licenseSpringCredentials;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.jans.as.model.config.adminui;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class LicenseConfig {

private String scanLicenseApiHostname;
private String scanLicenseAuthServerHostname;
private String licenseKey;
private String licenseHardwareKey;
private CredentialsEncryptionKeyDetails credentialsEncryptionKey;
private OIDCClientSettings oidcClient;

public CredentialsEncryptionKeyDetails getCredentialsEncryptionKey() {
return credentialsEncryptionKey;
}

public void setCredentialsEncryptionKey(CredentialsEncryptionKeyDetails credentialsEncryptionKey) {
this.credentialsEncryptionKey = credentialsEncryptionKey;
}

public OIDCClientSettings getOidcClient() {
return oidcClient;
}

public void setOidcClient(OIDCClientSettings oidcClient) {
this.oidcClient = oidcClient;
}

public String getScanLicenseApiHostname() {
return scanLicenseApiHostname;
}

public void setScanLicenseApiHostname(String scanLicenseApiHostname) {
this.scanLicenseApiHostname = scanLicenseApiHostname;
}

public String getLicenseHardwareKey() {
return licenseHardwareKey;
}

public void setLicenseHardwareKey(String licenseHardwareKey) {
this.licenseHardwareKey = licenseHardwareKey;
}

public String getLicenseKey() {
return licenseKey;
}

public void setLicenseKey(String licenseKey) {
this.licenseKey = licenseKey;
}

public String getScanLicenseAuthServerHostname() {
return scanLicenseAuthServerHostname;
}

public void setScanLicenseAuthServerHostname(String scanLicenseAuthServerHostname) {
this.scanLicenseAuthServerHostname = scanLicenseAuthServerHostname;
}

@Override
public String toString() {
return "LicenseConfig{" +
"scanLicenseApiHostname='" + scanLicenseApiHostname + '\'' +
"scanLicenseAuthServerHostname='" + scanLicenseAuthServerHostname + '\'' +
", licenseKey='" + licenseKey + '\'' +
", licenseHardwareKey='" + licenseHardwareKey + '\'' +
", credentialsEncryptionKey=" + credentialsEncryptionKey.toString() +
", oidcClient=" + oidcClient.toString() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class MainSettings {

private OIDCSettings oidcConfig;
private LicenseConfig licenseConfig;

public OIDCSettings getOidcConfig() {
return oidcConfig;
Expand All @@ -15,4 +16,12 @@ public OIDCSettings getOidcConfig() {
public void setOidcConfig(OIDCSettings oidcConfig) {
this.oidcConfig = oidcConfig;
}

public LicenseConfig getLicenseConfig() {
return licenseConfig;
}

public void setLicenseConfig(LicenseConfig licenseConfig) {
this.licenseConfig = licenseConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,19 @@ public String getFrontchannelLogoutUri() {
public void setFrontchannelLogoutUri(String frontchannelLogoutUri) {
this.frontchannelLogoutUri = frontchannelLogoutUri;
}

@Override
public String toString() {
return "OIDCClientSettings{" +
"opHost='" + opHost + '\'' +
", clientId='" + clientId + '\'' +
", clientSecret='" + clientSecret + '\'' +
", tokenEndpoint='" + tokenEndpoint + '\'' +
", redirectUri='" + redirectUri + '\'' +
", postLogoutUri='" + postLogoutUri + '\'' +
", frontchannelLogoutUri='" + frontchannelLogoutUri + '\'' +
", scopes=" + scopes +
", acrValues=" + acrValues +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.jans.ca.plugin.adminui.model.config;

import org.slf4j.Logger;

import jakarta.inject.Inject;
import org.slf4j.Logger;

public class LicenseConfiguration {

Expand All @@ -12,18 +11,16 @@ public class LicenseConfiguration {
private String apiKey;
private String productCode;
private String sharedKey;
private String managementKey;
private String hardwareId;
private String licenseKey;

public LicenseConfiguration() {
}

public LicenseConfiguration(String apiKey, String productCode, String sharedKey, String managementKey) {
public LicenseConfiguration(String apiKey, String productCode, String sharedKey) {
this.apiKey = apiKey;
this.productCode = productCode;
this.sharedKey = sharedKey;
this.managementKey = managementKey;
}

public String getApiKey() {
Expand All @@ -50,14 +47,6 @@ public void setSharedKey(String sharedKey) {
this.sharedKey = sharedKey;
}

public String getManagementKey() {
return managementKey;
}

public void setManagementKey(String managementKey) {
this.managementKey = managementKey;
}

public String getHardwareId() {
return hardwareId;
}
Expand All @@ -73,4 +62,5 @@ public String getLicenseKey() {
public void setLicenseKey(String licenseKey) {
this.licenseKey = licenseKey;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.jans.as.model.config.adminui;
package io.jans.ca.plugin.adminui.model.config;

public class LicenseSpringCredentials {
private String apiKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,28 @@ public class OAuth2Resource {
@Produces(MediaType.APPLICATION_JSON)
@ProtectedApi(scopes = {SCOPE_OPENID})
public Response getOAuth2Config(@PathParam("appType") String appType) {

AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration(appType);

OAuth2ConfigResponse oauth2Config = new OAuth2ConfigResponse();
oauth2Config.setAuthzBaseUrl(auiConfiguration.getAuthServerAuthzBaseUrl());
oauth2Config.setClientId(auiConfiguration.getAuthServerClientId());
oauth2Config.setResponseType("code");
oauth2Config.setScope(auiConfiguration.getAuthServerScope());
oauth2Config.setRedirectUrl(auiConfiguration.getAuthServerRedirectUrl());
oauth2Config.setAcrValues(auiConfiguration.getAuthServerAcrValues());
oauth2Config.setFrontChannelLogoutUrl(auiConfiguration.getAuthServerFrontChannelLogoutUrl());
oauth2Config.setPostLogoutRedirectUri(auiConfiguration.getAuthServerPostLogoutRedirectUri());
oauth2Config.setEndSessionEndpoint(auiConfiguration.getAuthServerEndSessionEndpoint());

return Response.ok(oauth2Config).build();
try {
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration(appType);

OAuth2ConfigResponse oauth2Config = new OAuth2ConfigResponse();
oauth2Config.setAuthzBaseUrl(auiConfiguration.getAuthServerAuthzBaseUrl());
oauth2Config.setClientId(auiConfiguration.getAuthServerClientId());
oauth2Config.setResponseType("code");
oauth2Config.setScope(auiConfiguration.getAuthServerScope());
oauth2Config.setRedirectUrl(auiConfiguration.getAuthServerRedirectUrl());
oauth2Config.setAcrValues(auiConfiguration.getAuthServerAcrValues());
oauth2Config.setFrontChannelLogoutUrl(auiConfiguration.getAuthServerFrontChannelLogoutUrl());
oauth2Config.setPostLogoutRedirectUri(auiConfiguration.getAuthServerPostLogoutRedirectUri());
oauth2Config.setEndSessionEndpoint(auiConfiguration.getAuthServerEndSessionEndpoint());

return Response.ok(oauth2Config).build();
} catch (ApplicationException e) {
log.error(ErrorResponse.ERROR_IN_READING_CONFIGURATION.getDescription(), e);
return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
} catch (Exception e) {
log.error(ErrorResponse.ERROR_IN_READING_CONFIGURATION.getDescription(), e);
return Response.serverError().entity(e.getMessage()).build();
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package io.jans.ca.plugin.adminui.rest.license;

import io.jans.as.model.config.adminui.LicenseSpringCredentials;
import io.jans.ca.plugin.adminui.model.auth.LicenseApiResponse;
import io.jans.ca.plugin.adminui.model.auth.LicenseRequest;
import io.jans.ca.plugin.adminui.model.auth.LicenseResponse;
import io.jans.ca.plugin.adminui.service.license.LicenseDetailsService;
import io.jans.ca.plugin.adminui.utils.AppConstants;
import io.jans.ca.plugin.adminui.utils.ErrorResponse;
import io.jans.configapi.core.rest.ProtectedApi;

import io.jans.configapi.util.ApiAccessConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.*;

import org.slf4j.Logger;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.*;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.slf4j.Logger;

@Path("/admin-ui/license")
public class LicenseResource {
Expand All @@ -36,7 +34,7 @@ public class LicenseResource {
static final String LICENSE_DETAILS = "/licenseDetails";

public static final String SCOPE_OPENID = "openid";
static final String SCOPE_LICENSE_READ = "https://jans.io/oauth/jans-auth-server/config/adminui/license.readonly";
public static final String SCOPE_LICENSE_READ = "https://jans.io/oauth/jans-auth-server/config/adminui/license.readonly";
static final String SCOPE_LICENSE_WRITE = "https://jans.io/oauth/jans-auth-server/config/adminui/license.write";

@Inject
Expand All @@ -55,7 +53,7 @@ public class LicenseResource {
@ApiResponse(responseCode = "500", description = "InternalServerError", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseApiResponse.class, description = "License response")))})
@GET
@Path(IS_ACTIVE)
@ProtectedApi(scopes = {SCOPE_LICENSE_READ}, groupScopes = {SCOPE_LICENSE_WRITE}, superScopes = { AppConstants.SCOPE_ADMINUI_READ })
@ProtectedApi(scopes = {SCOPE_LICENSE_READ}, groupScopes = {SCOPE_LICENSE_WRITE}, superScopes = {AppConstants.SCOPE_ADMINUI_READ})
@Produces(MediaType.APPLICATION_JSON)
public Response isActive() {
LicenseApiResponse licenseResponse = null;
Expand All @@ -81,7 +79,7 @@ public Response isActive() {
@ApiResponse(responseCode = "500", description = "InternalServerError", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseApiResponse.class, description = "License response")))})
@POST
@Path(ACTIVATE_LICENSE)
@ProtectedApi(scopes = {SCOPE_LICENSE_WRITE}, superScopes = { AppConstants.SCOPE_ADMINUI_WRITE })
@ProtectedApi(scopes = {SCOPE_LICENSE_WRITE}, superScopes = {AppConstants.SCOPE_ADMINUI_WRITE})
@Produces(MediaType.APPLICATION_JSON)
public Response activateLicense(@Valid @NotNull LicenseRequest licenseRequest) {
LicenseApiResponse licenseResponse = null;
Expand All @@ -96,32 +94,6 @@ public Response activateLicense(@Valid @NotNull LicenseRequest licenseRequest) {
}
}

@Operation(summary = "Save license api credentials", description = "Save license api credentials", operationId = "save-license-api-credentials", tags = {
"Admin UI - License"}, security = @SecurityRequirement(name = "oauth2", scopes = {
SCOPE_LICENSE_WRITE}))
@RequestBody(description = "LicenseSpringCredentials object", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseSpringCredentials.class)))
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Ok", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseApiResponse.class, description = "License response"))),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseApiResponse.class, description = "License response"))),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "500", description = "InternalServerError", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = LicenseApiResponse.class, description = "License response")))})
@POST
@Path(SAVE_API_CREDENTIALS)
@ProtectedApi(scopes = {SCOPE_LICENSE_WRITE}, superScopes = { AppConstants.SCOPE_ADMINUI_WRITE })
@Produces(MediaType.APPLICATION_JSON)
public Response saveLicenseCredentials(@Valid @NotNull LicenseSpringCredentials licenseSpringCredentials) {
LicenseApiResponse licenseResponse = null;
try {
log.info("Trying to save license-spring credentials.");
licenseResponse = licenseDetailsService.saveLicenseSpringCredentials(licenseSpringCredentials);
log.info("License saved (true/false): {}", licenseResponse.isApiResult());
return Response.ok(licenseResponse).build();
} catch (Exception e) {
log.error(ErrorResponse.SAVE_LICENSE_SPRING_CREDENTIALS_ERROR.getDescription(), e);
return Response.serverError().entity(licenseResponse).build();
}
}

@Operation(summary = "Get admin ui license details", description = "Get admin ui license details", operationId = "get-adminui-license", tags = {
"Admin UI - License"}, security = @SecurityRequirement(name = "oauth2", scopes = {
SCOPE_LICENSE_READ}))
Expand All @@ -132,7 +104,7 @@ public Response saveLicenseCredentials(@Valid @NotNull LicenseSpringCredentials
@ApiResponse(responseCode = "500", description = "InternalServerError")})
@GET
@Path(LICENSE_DETAILS)
@ProtectedApi(scopes = {SCOPE_LICENSE_READ}, groupScopes = {SCOPE_LICENSE_WRITE}, superScopes = { AppConstants.SCOPE_ADMINUI_READ })
@ProtectedApi(scopes = {SCOPE_LICENSE_READ}, groupScopes = {SCOPE_LICENSE_WRITE}, superScopes = {AppConstants.SCOPE_ADMINUI_READ})
@Produces(MediaType.APPLICATION_JSON)
public Response getLicenseDetails() {
try {
Expand Down
Loading