Search in sources :

Example 1 with LicenseResponse

use of io.jans.ca.plugin.adminui.model.auth.LicenseResponse in project jans by JanssenProject.

the class LicenseResource method getLicenseDetails.

@GET
@Path(LICENSE_DETAILS)
@ProtectedApi(scopes = { SCOPE_LICENSE_READ })
@Produces(MediaType.APPLICATION_JSON)
public Response getLicenseDetails() {
    try {
        log.info("Trying to fetch license details.");
        LicenseResponse licenseResponse = licenseDetailsService.getLicenseDetails();
        return Response.ok(licenseResponse).build();
    } catch (Exception e) {
        log.error(ErrorResponse.GET_LICENSE_DETAILS_ERROR.getDescription(), e);
        return Response.serverError().entity(ErrorResponse.GET_LICENSE_DETAILS_ERROR.getDescription()).build();
    }
}
Also used : LicenseResponse(io.jans.ca.plugin.adminui.model.auth.LicenseResponse) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 2 with LicenseResponse

use of io.jans.ca.plugin.adminui.model.auth.LicenseResponse in project jans by JanssenProject.

the class LicenseDetailsService method getLicenseDetails.

public LicenseResponse getLicenseDetails() {
    LicenseResponse licenseResponse = new LicenseResponse();
    try {
        AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
        Boolean isLicenseCheckEnabled = auiConfiguration.getLicenseConfiguration().getEnabled();
        if (!Boolean.TRUE.equals(isLicenseCheckEnabled)) {
            log.debug("License configuration is disabled.");
            licenseResponse.setLicenseEnabled(false);
            return licenseResponse;
        }
        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;
        }
    } catch (Exception e) {
        log.error(ErrorResponse.GET_LICENSE_DETAILS_ERROR.getDescription(), e);
        licenseResponse.setLicenseEnabled(false);
        return licenseResponse;
    }
}
Also used : LicenseResponse(io.jans.ca.plugin.adminui.model.auth.LicenseResponse) AUIConfiguration(io.jans.ca.plugin.adminui.model.config.AUIConfiguration) BackOfficeLicense(com.licensespring.management.model.BackOfficeLicense) ActivationLicense(com.licensespring.model.ActivationLicense) License(com.licensespring.License) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Example 3 with LicenseResponse

use of io.jans.ca.plugin.adminui.model.auth.LicenseResponse in project jans by JanssenProject.

the class LicenseDetailsService method updateLicenseDetails.

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<BackOfficeLicense> 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());
    }
}
Also used : UpdateLicenseRequest(com.licensespring.management.dto.request.UpdateLicenseRequest) ManagementConfiguration(com.licensespring.management.ManagementConfiguration) BackOfficeLicense(com.licensespring.management.model.BackOfficeLicense) ActivationLicense(com.licensespring.model.ActivationLicense) License(com.licensespring.License) SearchLicensesRequest(com.licensespring.management.dto.request.SearchLicensesRequest) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) LicenseResponse(io.jans.ca.plugin.adminui.model.auth.LicenseResponse) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) AUIConfiguration(io.jans.ca.plugin.adminui.model.config.AUIConfiguration) BackOfficeLicense(com.licensespring.management.model.BackOfficeLicense)

Example 4 with LicenseResponse

use of io.jans.ca.plugin.adminui.model.auth.LicenseResponse in project jans by JanssenProject.

the class LicenseResource method updateLicenseDetails.

@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();
    }
}
Also used : LicenseResponse(io.jans.ca.plugin.adminui.model.auth.LicenseResponse) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Aggregations

LicenseResponse (io.jans.ca.plugin.adminui.model.auth.LicenseResponse)4 ApplicationException (io.jans.ca.plugin.adminui.model.exception.ApplicationException)4 License (com.licensespring.License)2 BackOfficeLicense (com.licensespring.management.model.BackOfficeLicense)2 ActivationLicense (com.licensespring.model.ActivationLicense)2 AUIConfiguration (io.jans.ca.plugin.adminui.model.config.AUIConfiguration)2 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)2 ManagementConfiguration (com.licensespring.management.ManagementConfiguration)1 SearchLicensesRequest (com.licensespring.management.dto.request.SearchLicensesRequest)1 UpdateLicenseRequest (com.licensespring.management.dto.request.UpdateLicenseRequest)1