use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getServiceProvider.
/**
* @param serviceProviderName
* @param tenantDomain
* @return
* @throws IdentityApplicationManagementException
*/
@Override
public ServiceProvider getServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
// invoking the listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPreGetServiceProvider(serviceProviderName, tenantDomain)) {
return null;
}
}
ServiceProvider serviceProvider = null;
try {
startTenantFlow(tenantDomain);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
serviceProvider = appDAO.getApplication(serviceProviderName, tenantDomain);
if (serviceProvider == null && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
}
} finally {
endTenantFlow();
}
// invoking the listeners
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain)) {
return null;
}
}
return serviceProvider;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getServiceProvider.
/**
* @param appId
* @return
* @throws IdentityApplicationManagementException
*/
@Override
public ServiceProvider getServiceProvider(int appId) throws IdentityApplicationManagementException {
// TODO: Need to have pre listeners. Don't have them because we didn't want to add listener methods to the
// TODO: ApplicationMgtListener interface since we didn't want to change APIs. Also pre listener aren't vital
// TODO: for getters. Mostly post listeners are enough.
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ServiceProvider serviceProvider = appDAO.getApplication(appId);
String serviceProviderName = serviceProvider.getApplicationName();
String tenantDomain = serviceProvider.getOwner().getTenantDomain();
// TODO: Since we didn't add post listener methods to the ApplicationMgtListener API to avoid API changes, we
// TODO: are invoking doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain) listener
// TODO: method here as well.
// invoking the post listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain)) {
return null;
}
}
return serviceProvider;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider 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.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplication.
@Override
public void updateApplication(ServiceProvider serviceProvider, String tenantDomain, String username) throws IdentityApplicationManagementException {
validateApplicationConfigurations(serviceProvider, tenantDomain, username);
// invoking the listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPreUpdateApplication(serviceProvider, tenantDomain, username)) {
throw buildServerException("Pre Update application failed");
}
}
String applicationName = serviceProvider.getApplicationName();
try {
// check whether user is authorized to update the application.
startTenantFlow(tenantDomain, username);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
String storedAppName = appDAO.getApplicationName(serviceProvider.getApplicationID());
if (StringUtils.isBlank(storedAppName)) {
// This means the application is not a valid one.
String msg = "Cannot find application with id: " + serviceProvider.getApplicationID() + " in " + "tenantDomain: " + tenantDomain;
throw buildClientException(APPLICATION_NOT_FOUND, msg);
}
doPreUpdateChecks(storedAppName, serviceProvider, tenantDomain, username);
appDAO.updateApplication(serviceProvider, tenantDomain);
if (isOwnerUpdatedInRequest(serviceProvider)) {
// It is not required to validate the user here, as the user is validating inside the updateApplication
// method above. Hence assign application role to the app owner.
assignApplicationRole(serviceProvider.getApplicationName(), MultitenantUtils.getTenantAwareUsername(serviceProvider.getOwner().toFullQualifiedUsername()));
}
updateApplicationPermissions(serviceProvider, applicationName, storedAppName);
} catch (Exception e) {
String error = "Error occurred while updating the application: " + applicationName + ". " + e.getMessage();
throw new IdentityApplicationManagementException(error, e);
} finally {
endTenantFlow();
}
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostUpdateApplication(serviceProvider, tenantDomain, username)) {
return;
}
}
triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.UPDATE_APPLICATION.getEventId(), getAppId(serviceProvider), getApplicationName(serviceProvider), TARGET_APPLICATION, buildSPData(serviceProvider));
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getApplicationByResourceId.
@Override
public ServiceProvider getApplicationByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreGetApplicationByResourceId(resourceId, tenantDomain)) {
throw buildServerException("Pre Get application operation of " + "listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
}
}
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ServiceProvider application = appDAO.getApplicationByResourceId(resourceId, tenantDomain);
if (application == null) {
if (log.isDebugEnabled()) {
log.debug("Cannot find an application for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain);
}
return null;
}
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostGetApplicationByResourceId(application, resourceId, tenantDomain)) {
log.error("Post Get application operation of " + "listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
break;
}
}
return application;
}
Aggregations