use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplicationTemplate.
@Override
public void updateApplicationTemplate(String oldTemplateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
try {
validateSPTemplateExists(oldTemplateName, spTemplate, tenantDomain);
ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
validateUnsupportedTemplateConfigs(serviceProvider);
applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doPreUpdateApplicationTemplate(serviceProvider, tenantDomain);
}
}
doUpdateApplicationTemplate(oldTemplateName, spTemplate, tenantDomain);
} catch (IdentityApplicationManagementValidationException e) {
log.error("Validation error when updating the application template: " + oldTemplateName + " in:" + tenantDomain);
logValidationErrorMessages(e);
throw new IdentityApplicationManagementClientException(e.getValidationMsg());
} catch (IdentityApplicationManagementException e) {
String errorMsg = String.format("Error in updating the application template: %s in tenant: %s", oldTemplateName, tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method unmarshalSPTemplate.
private ServiceProvider unmarshalSPTemplate(String spTemplateXml) throws IdentityApplicationManagementValidationException {
if (StringUtils.isEmpty(spTemplateXml)) {
throw new IdentityApplicationManagementValidationException(new String[] { "Empty SP template configuration" + " is provided." });
}
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setXIncludeAware(false);
try {
spf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false);
spf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false);
spf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false);
spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (SAXException | ParserConfigurationException e) {
log.error("Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE + " or secure-processing.");
}
JAXBContext jc = JAXBContext.newInstance(ServiceProvider.class);
UnmarshallerHandler unmarshallerHandler = jc.createUnmarshaller().getUnmarshallerHandler();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(unmarshallerHandler);
ByteArrayInputStream inputStream = new ByteArrayInputStream(spTemplateXml.getBytes(StandardCharsets.UTF_8));
InputSource inputSource = new InputSource(inputStream);
xr.parse(inputSource);
inputStream.close();
return (ServiceProvider) unmarshallerHandler.getResult();
} catch (JAXBException | SAXException | ParserConfigurationException | IOException e) {
String msg = "Error in reading Service Provider template configuration.";
log.error(msg, e);
throw new IdentityApplicationManagementValidationException(new String[] { msg });
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthApplicationMgtListener method validateOAuthInbound.
/**
* Validate Oauth inbound config.
*
* @param serviceProvider service provider.
* @param isUpdate whether the application update or create
* @throws IdentityApplicationManagementValidationException Identity Application Management Exception
*/
private void validateOAuthInbound(ServiceProvider serviceProvider, boolean isUpdate) throws IdentityApplicationManagementValidationException {
List<String> validationMsg = new ArrayList<>();
if (serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
for (InboundAuthenticationRequestConfig authConfig : serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs()) {
if (OAUTH.equals(authConfig.getInboundAuthType()) || OAUTH2.equals(authConfig.getInboundAuthType())) {
String inboundConfiguration = authConfig.getInboundConfiguration();
if (inboundConfiguration == null) {
return;
}
String inboundAuthKey = authConfig.getInboundAuthKey();
OAuthAppDAO dao = new OAuthAppDAO();
OAuthAppDO oAuthAppDO;
String tenantDomain = serviceProvider.getOwner().getTenantDomain();
String userName = serviceProvider.getOwner().getUserName();
try {
oAuthAppDO = marshelOAuthDO(inboundConfiguration, serviceProvider.getApplicationName(), tenantDomain);
} catch (IdentityApplicationManagementException e) {
validationMsg.add("OAuth inbound configuration in the file is not valid.");
break;
}
if (!inboundAuthKey.equals(oAuthAppDO.getOauthConsumerKey())) {
validationMsg.add(String.format("The Inbound Auth Key of the application name %s " + "is not match with Oauth Consumer Key %s.", authConfig.getInboundAuthKey(), oAuthAppDO.getOauthConsumerKey()));
}
try {
if (!isUpdate) {
if (dao.isDuplicateConsumer(inboundAuthKey)) {
validationMsg.add(String.format("An OAuth application already exists with %s as " + "consumer key", inboundAuthKey));
break;
} else if (dao.isDuplicateApplication(userName, IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain, oAuthAppDO)) {
validationMsg.add(String.format("An OAuth application already exists with %s as " + "consumer key", oAuthAppDO.getApplicationName()));
break;
}
}
} catch (IdentityOAuthAdminException e) {
// Do nothing, the key does exists.
}
if (oAuthAppDO.getGrantTypes() != null && (oAuthAppDO.getGrantTypes().contains(OAuthConstants.GrantTypes.AUTHORIZATION_CODE) || oAuthAppDO.getGrantTypes().contains(OAuthConstants.GrantTypes.IMPLICIT)) && StringUtils.isEmpty(oAuthAppDO.getCallbackUrl())) {
validationMsg.add("Callback Url is required for Code or Implicit grant types");
}
validateScopeValidators(oAuthAppDO.getScopeValidators(), validationMsg);
if (OAuthConstants.OAuthVersions.VERSION_2.equals(oAuthAppDO.getOauthVersion())) {
validateGrants(oAuthAppDO.getGrantTypes().split("\\s"), validationMsg);
}
break;
}
}
}
if (!validationMsg.isEmpty()) {
throw new IdentityApplicationManagementValidationException(validationMsg.toArray(new String[0]));
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method createApplicationTemplateFromSP.
@Override
public void createApplicationTemplateFromSP(ServiceProvider serviceProvider, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
if (serviceProvider != null) {
try {
validateSPTemplateExists(spTemplate, tenantDomain);
ServiceProvider updatedSP = removeUnsupportedTemplateConfigs(serviceProvider);
applicationValidatorManager.validateSPConfigurations(updatedSP, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doPreCreateApplicationTemplate(serviceProvider, tenantDomain);
}
}
String serviceProviderTemplateXml = marshalSPTemplate(updatedSP, tenantDomain);
spTemplate.setContent(serviceProviderTemplateXml);
doAddApplicationTemplate(spTemplate, tenantDomain);
} catch (IdentityApplicationManagementValidationException e) {
log.error("Validation error when creating the application template:" + spTemplate.getName() + "from service provider: " + serviceProvider.getApplicationName() + " in:" + tenantDomain);
logValidationErrorMessages(e);
throw new IdentityApplicationManagementClientException(e.getValidationMsg());
} catch (IdentityApplicationManagementException e) {
String errorMsg = String.format("Error when creating the application template: %s from " + "service provider: %s in: ", spTemplate.getName(), serviceProvider.getApplicationName(), tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
} else {
createApplicationTemplate(spTemplate, tenantDomain);
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method createApplicationTemplate.
@Override
public void createApplicationTemplate(SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
try {
ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
validateSPTemplateExists(spTemplate, tenantDomain);
validateUnsupportedTemplateConfigs(serviceProvider);
applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doPreCreateApplicationTemplate(serviceProvider, tenantDomain);
}
}
doAddApplicationTemplate(spTemplate, tenantDomain);
} catch (IdentityApplicationManagementValidationException e) {
log.error("Validation error when creating the application template: " + spTemplate.getName() + " in:" + tenantDomain);
logValidationErrorMessages(e);
throw new IdentityApplicationManagementClientException(e.getValidationMsg());
} catch (IdentityApplicationManagementException e) {
String errorMsg = String.format("Error when creating the application template: %s in tenant: %s", spTemplate.getName(), tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
Aggregations