private void addConsent(String consent, String tenantDomain) throws ConsentManagementException, IdentityRecoveryServerException { Gson gson = new Gson(); ReceiptInput receiptInput = gson.fromJson(consent, ReceiptInput.class); ConsentManager consentManager = IdentityRecoveryServiceDataHolder.getInstance().getConsentManager(); if (receiptInput.getServices().size() < 0) { throw new IdentityRecoveryServerException("A service should be available in a receipt"); } // There should be a one receipt ReceiptServiceInput receiptServiceInput = receiptInput.getServices().get(0); receiptServiceInput.setTenantDomain(tenantDomain); try { setIDPData(tenantDomain, receiptServiceInput); } catch (IdentityProviderManagementException e) { throw new ConsentManagementException("Error while retrieving identity provider data", "Error while " + "setting IDP data", e); } receiptInput.setTenantDomain(tenantDomain); consentManager.addConsent(receiptInput); }
private void validateInputParameters(ReceiptInput receiptInput) throws ConsentManagementException { //Set authenticated user. if (isBlank(receiptInput.getPiiPrincipalId())) { receiptInput.setPiiPrincipalId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); } // Set authenticated user's tenant id if it is not set. if (isBlank(receiptInput.getTenantDomain())) { receiptInput.setTenantId(getTenantIdFromCarbonContext()); receiptInput.setTenantDomain(getTenantDomainFromCarbonContext()); } else { receiptInput.setTenantId(getTenantId(realmService, receiptInput.getTenantDomain())); } validateRequiredParametersInConsent(receiptInput); receiptInput.getServices().forEach(rethrowConsumer(receiptServiceInput -> { validateRequiredParametersInService(receiptServiceInput); receiptServiceInput.getPurposes().forEach(rethrowConsumer(receiptPurposeInput -> validateRequiredParametersInPurpose(receiptServiceInput, receiptPurposeInput))); })); if (log.isDebugEnabled()) { log.debug("Consent adding request validation success"); } }
/** * Persist the consents received from the user, while user creation. * * @param receiptInput Relevant receipt input representing consent data. * @param tenantDomain Relevant tenant domain. * @throws PostAuthenticationFailedException Post Authentication Failed Exception. */ private void addConsent(ReceiptInput receiptInput, String tenantDomain) throws PostAuthenticationFailedException { ConsentManager consentManager = FrameworkServiceDataHolder.getInstance().getConsentManager(); if (receiptInput.getServices().size() == 0) { throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain)); } // There should be one receipt ReceiptServiceInput receiptServiceInput = receiptInput.getServices().get(0); receiptServiceInput.setTenantDomain(tenantDomain); try { setIDPData(tenantDomain, receiptServiceInput); receiptInput.setTenantDomain(tenantDomain); consentManager.addConsent(receiptInput); } catch (ConsentManagementException e) { handleExceptions(String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), e); } }
/** * Persist the consents received from the user, while user creation. * * @param receiptInput Relevant receipt input representing consent data. * @param tenantDomain Relevant tenant domain. * @throws PostAuthenticationFailedException Post Authentication Failed Exception. */ private void addConsent(ReceiptInput receiptInput, String tenantDomain) throws PostAuthenticationFailedException { ConsentManager consentManager = FrameworkServiceDataHolder.getInstance().getConsentManager(); if (receiptInput.getServices().size() == 0) { throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain)); } // There should be one receipt ReceiptServiceInput receiptServiceInput = receiptInput.getServices().get(0); receiptServiceInput.setTenantDomain(tenantDomain); try { setIDPData(tenantDomain, receiptServiceInput); receiptInput.setTenantDomain(tenantDomain); consentManager.addConsent(receiptInput); } catch (ConsentManagementException e) { handleExceptions(String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), e); } }