Search in sources :

Example 1 with AUIConfiguration

use of io.jans.ca.plugin.adminui.model.config.AUIConfiguration in project jans by JanssenProject.

the class OAuth2Resource method getOAuth2Config.

@GET
@Path(OAUTH2_CONFIG)
@Produces(MediaType.APPLICATION_JSON)
@ProtectedApi(scopes = { SCOPE_OPENID })
public Response getOAuth2Config() {
    AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
    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("simple_password_auth");
    oauth2Config.setFrontChannelLogoutUrl(auiConfiguration.getAuthServerFrontChannelLogoutUrl());
    oauth2Config.setPostLogoutRedirectUri(auiConfiguration.getAuthServerPostLogoutRedirectUri());
    oauth2Config.setEndSessionEndpoint(auiConfiguration.getAuthServerEndSessionEndpoint());
    return Response.ok(oauth2Config).build();
}
Also used : OAuth2ConfigResponse(io.jans.ca.plugin.adminui.model.auth.OAuth2ConfigResponse) AUIConfiguration(io.jans.ca.plugin.adminui.model.config.AUIConfiguration) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 2 with AUIConfiguration

use of io.jans.ca.plugin.adminui.model.config.AUIConfiguration 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 AUIConfiguration

use of io.jans.ca.plugin.adminui.model.config.AUIConfiguration 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 AUIConfiguration

use of io.jans.ca.plugin.adminui.model.config.AUIConfiguration in project jans by JanssenProject.

the class LicenseDetailsService method checkLicense.

public Boolean checkLicense() {
    try {
        AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
        Boolean isLicenseCheckEnabled = auiConfiguration.getLicenseConfiguration().getEnabled();
        if (!Boolean.TRUE.equals(isLicenseCheckEnabled)) {
            log.debug("License configuration is disabled. ");
            return true;
        }
        License activeLicense = auiConfiguration.getLicenseConfiguration().getLicenseManager().getCurrent();
        if (activeLicense == null) {
            log.info("Active license for admin-ui not present ");
            return false;
        } else {
            log.debug("Active license for admin-ui found : {} ", activeLicense.getProduct());
            License updatedLicense = auiConfiguration.getLicenseConfiguration().getLicenseManager().checkLicense(activeLicense);
            return updatedLicense != null && !activeLicense.getData().isExpired();
        }
    } catch (Exception e) {
        log.error(ErrorResponse.CHECK_LICENSE_ERROR.getDescription(), e);
        return false;
    }
}
Also used : 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 5 with AUIConfiguration

use of io.jans.ca.plugin.adminui.model.config.AUIConfiguration in project jans by JanssenProject.

the class AUIConfigurationService method addPropertiesToAUIConfiguration.

private AUIConfiguration addPropertiesToAUIConfiguration(Properties props) {
    AUIConfiguration auiConfig = new AUIConfiguration();
    auiConfig.setAuthServerHost(props.getProperty("authserver.host"));
    auiConfig.setAuthServerClientId(props.getProperty("authserver.clientId"));
    auiConfig.setAuthServerClientSecret(props.getProperty("authserver.clientSecret"));
    auiConfig.setAuthServerScope(props.getProperty("authserver.scope"));
    auiConfig.setAuthServerRedirectUrl(props.getProperty("authserver.redirectUrl"));
    auiConfig.setAuthServerFrontChannelLogoutUrl(props.getProperty("authserver.frontChannelLogoutUrl"));
    auiConfig.setAuthServerPostLogoutRedirectUri(props.getProperty("authserver.postLogoutRedirectUri"));
    auiConfig.setAuthServerAuthzBaseUrl(props.getProperty("authserver.authzBaseUrl"));
    auiConfig.setAuthServerTokenEndpoint(props.getProperty("authserver.tokenEndpoint"));
    auiConfig.setAuthServerIntrospectionEndpoint(props.getProperty("authserver.introspectionEndpoint"));
    auiConfig.setAuthServerUserInfoEndpoint(props.getProperty("authserver.userInfoEndpoint"));
    auiConfig.setAuthServerEndSessionEndpoint(props.getProperty("authserver.endSessionEndpoint"));
    auiConfig.setTokenServerClientId(props.getProperty("tokenServer.clientId"));
    auiConfig.setTokenServerClientSecret(props.getProperty("tokenServer.clientSecret"));
    auiConfig.setTokenServerScope(props.getProperty("tokenServer.scope"));
    auiConfig.setTokenServerRedirectUrl(props.getProperty("tokenServer.redirectUrl"));
    auiConfig.setTokenServerFrontChannelLogoutUrl(props.getProperty("tokenServer.frontChannelLogoutUrl"));
    auiConfig.setTokenServerPostLogoutRedirectUri(props.getProperty("tokenServer.postLogoutRedirectUri"));
    auiConfig.setTokenServerAuthzBaseUrl(props.getProperty("tokenServer.authzBaseUrl"));
    auiConfig.setTokenServerTokenEndpoint(props.getProperty("tokenServer.tokenEndpoint"));
    auiConfig.setTokenServerIntrospectionEndpoint(props.getProperty("tokenServer.introspectionEndpoint"));
    auiConfig.setTokenServerUserInfoEndpoint(props.getProperty("tokenServer.userInfoEndpoint"));
    auiConfig.setTokenServerEndSessionEndpoint(props.getProperty("tokenServer.endSessionEndpoint"));
    LicenseConfiguration licenseConfiguration = new LicenseConfiguration();
    licenseConfiguration.setApiKey(props.getProperty("licenseSpring.apiKey"));
    licenseConfiguration.setProductCode(props.getProperty("licenseSpring.productCode"));
    licenseConfiguration.setSharedKey(props.getProperty("licenseSpring.sharedKey"));
    licenseConfiguration.setEnabled(Boolean.valueOf(props.getProperty("licenseSpring.enabled")));
    licenseConfiguration.setManagementKey(props.getProperty("licenseSpring.managementKey"));
    licenseConfiguration.initializeLicenseManager();
    auiConfig.setLicenseConfiguration(licenseConfiguration);
    return auiConfig;
}
Also used : AUIConfiguration(io.jans.ca.plugin.adminui.model.config.AUIConfiguration) LicenseConfiguration(io.jans.ca.plugin.adminui.model.config.LicenseConfiguration)

Aggregations

AUIConfiguration (io.jans.ca.plugin.adminui.model.config.AUIConfiguration)9 ApplicationException (io.jans.ca.plugin.adminui.model.exception.ApplicationException)7 License (com.licensespring.License)4 BackOfficeLicense (com.licensespring.management.model.BackOfficeLicense)4 ActivationLicense (com.licensespring.model.ActivationLicense)4 TokenResponse (io.jans.ca.plugin.adminui.model.auth.TokenResponse)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 TokenRequest (io.jans.as.client.TokenRequest)2 Jwt (io.jans.as.model.jwt.Jwt)2 LicenseResponse (io.jans.ca.plugin.adminui.model.auth.LicenseResponse)2 LicenseManager (com.licensespring.LicenseManager)1 ManagementConfiguration (com.licensespring.management.ManagementConfiguration)1 SearchLicensesRequest (com.licensespring.management.dto.request.SearchLicensesRequest)1 UpdateLicenseRequest (com.licensespring.management.dto.request.UpdateLicenseRequest)1 OAuth2ConfigResponse (io.jans.ca.plugin.adminui.model.auth.OAuth2ConfigResponse)1 UserInfoResponse (io.jans.ca.plugin.adminui.model.auth.UserInfoResponse)1 LicenseConfiguration (io.jans.ca.plugin.adminui.model.config.LicenseConfiguration)1 ErrorResponse (io.jans.ca.plugin.adminui.utils.ErrorResponse)1 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)1 List (java.util.List)1