use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method loadApplicationPermissions.
private void loadApplicationPermissions(String serviceProviderName, ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
try {
ApplicationMgtUtil.startTenantFlow(serviceProvider.getOwner().getTenantDomain());
List<ApplicationPermission> permissionList = ApplicationMgtUtil.loadPermissions(serviceProviderName);
if (permissionList != null) {
PermissionsAndRoleConfig permissionAndRoleConfig;
if (serviceProvider.getPermissionAndRoleConfig() == null) {
permissionAndRoleConfig = new PermissionsAndRoleConfig();
} else {
permissionAndRoleConfig = serviceProvider.getPermissionAndRoleConfig();
}
permissionAndRoleConfig.setPermissions(permissionList.toArray(new ApplicationPermission[0]));
serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig);
}
} finally {
ApplicationMgtUtil.endTenantFlow();
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method createApplication.
/**
* Stores basic application information and meta-data such as the application name, creator and
* tenant.
*
* @param application
* @throws IdentityApplicationManagementException
*/
@Override
public int createApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException {
Connection connection = IdentityDatabaseUtil.getDBConnection(true);
try {
ApplicationCreateResult result = persistBasicApplicationInformation(connection, application, tenantDomain);
IdentityDatabaseUtil.commitTransaction(connection);
return result.getApplicationId();
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
if (isApplicationConflict(e)) {
throw new IdentityApplicationManagementClientException(APPLICATION_ALREADY_EXISTS.getCode(), "Application already exists with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain);
}
throw new IdentityApplicationManagementException("Error while Creating Application", e);
} finally {
IdentityApplicationManagementUtil.closeConnection(connection);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationMgtUtil method getApplicationFromSpFileStream.
/**
* Get Service provider name from XML configuration file
*
* @param spFileStream
* @param tenantDomain
* @return ServiceProvider
* @throws IdentityApplicationManagementException
*/
public static ServiceProvider getApplicationFromSpFileStream(SpFileStream spFileStream, String tenantDomain) throws IdentityApplicationManagementException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(ServiceProvider.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (ServiceProvider) unmarshaller.unmarshal(spFileStream.getFileStream());
} catch (JAXBException e) {
throw new IdentityApplicationManagementException(String.format("Error in reading Service Provider " + "configuration file %s uploaded by tenant: %s", spFileStream.getFileName(), tenantDomain), e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationMgtUtil method isValidApplicationOwner.
/**
* To check whether the application owner is valid by validating user existence and permissions.
*
* @param serviceProvider service provider
* @return true if the application owner is valid.
* @throws IdentityApplicationManagementException when an error occurs while validating the user.
*/
public static boolean isValidApplicationOwner(ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
try {
String userName;
String userNameWithDomain;
if (serviceProvider.getOwner() != null) {
userName = serviceProvider.getOwner().getUserName();
if (StringUtils.isEmpty(userName) || CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(userName)) {
return false;
}
String userStoreDomain = serviceProvider.getOwner().getUserStoreDomain();
userNameWithDomain = IdentityUtil.addDomainToName(userName, userStoreDomain);
org.wso2.carbon.user.api.UserRealm realm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
if (realm == null || StringUtils.isEmpty(userNameWithDomain)) {
return false;
}
boolean isUserExist = realm.getUserStoreManager().isExistingUser(userNameWithDomain);
if (!isUserExist) {
if (log.isDebugEnabled()) {
log.debug("Owner does not exist for application: " + serviceProvider.getApplicationName() + ". Hence making the tenant admin the owner of the application.");
}
// Since the SP owner does not exist, set the tenant admin user as the owner.
User owner = new User();
owner.setUserName(realm.getRealmConfiguration().getAdminUserName());
owner.setUserStoreDomain(realm.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
owner.setTenantDomain(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
serviceProvider.setOwner(owner);
}
} else {
return false;
}
} catch (UserStoreException e) {
throw new IdentityApplicationManagementException("User validation failed for owner update in the " + "application: " + serviceProvider.getApplicationName(), e);
}
return true;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class CacheBackedApplicationDAO method getAllRequestedClaimsByServiceProvider.
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
ServiceProvider applicationFromCache = getApplicationFromCache(serviceProviderName, tenantDomain);
if (applicationFromCache != null) {
List<String> requestedLocalClaims = new ArrayList<>();
ClaimConfig claimConfig = applicationFromCache.getClaimConfig();
ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
for (ClaimMapping claimMapping : claimMappings) {
if (claimMapping.isRequested()) {
requestedLocalClaims.add(claimMapping.getLocalClaim().getClaimUri());
}
}
return requestedLocalClaims;
}
return appDAO.getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
}
Aggregations