use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method updateEndpointsOfSingleWSDL.
/**
* Update the endpoint information of the provided WSDL definition when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @param wsdlDefinition WSDL 1.1 definition
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Definition wsdlDefinition) throws APIMgtWSDLException {
Map serviceMap = wsdlDefinition.getAllServices();
URL addressURI;
String organization = api.getOrganization();
for (Object entry : serviceMap.entrySet()) {
Map.Entry svcEntry = (Map.Entry) entry;
Service svc = (Service) svcEntry.getValue();
Map portMap = svc.getPorts();
for (Object o : portMap.entrySet()) {
Map.Entry portEntry = (Map.Entry) o;
Port port = (Port) portEntry.getValue();
List<ExtensibilityElement> extensibilityElementList = port.getExtensibilityElements();
String endpointTransport;
for (ExtensibilityElement extensibilityElement : extensibilityElementList) {
try {
addressURI = new URL(getAddressUrl(extensibilityElement));
endpointTransport = determineURLTransport(addressURI.getProtocol(), api.getTransports());
if (log.isDebugEnabled()) {
log.debug("Address URI for the port:" + port.getName() + " is " + addressURI.toString());
}
} catch (MalformedURLException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while getting the wsdl address location [" + getAddressUrl(extensibilityElement) + "]");
}
endpointTransport = determineURLTransport("https", api.getTransports());
// This string to URL conversion done in order to identify URL transport eg - http or https.
// Here if there is a conversion failure , consider "https" as default protocol
}
try {
setAddressUrl(extensibilityElement, endpointTransport, api.getContext(), environmentName, environmentType, organization);
} catch (APIManagementException e) {
throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
}
}
}
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method updateEndpointsOfSingleWSDL.
/**
* Update the endpoint information of the provided WSDL definition when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @param wsdlDescription WSDL 2.0 definition
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Description wsdlDescription) throws APIMgtWSDLException {
Service[] serviceMap = wsdlDescription.getServices();
String organization = api.getOrganization();
try {
for (Service svc : serviceMap) {
Endpoint[] portMap = svc.getEndpoints();
for (Endpoint endpoint : portMap) {
EndpointElement element = endpoint.toElement();
String endpointTransport = determineURLTransport(endpoint.getAddress().getScheme(), api.getTransports());
setAddressUrl(element, new URI(APIUtil.getGatewayEndpoint(endpointTransport, environmentName, environmentType, organization) + api.getContext()));
}
}
} catch (URISyntaxException | APIManagementException e) {
throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method isIDPExistInOrg.
public boolean isIDPExistInOrg(String organization, String resourceId) throws APIManagementException {
final String query = "SELECT 1 FROM AM_KEY_MANAGER WHERE EXTERNAL_REFERENCE_ID = ? AND ORGANIZATION = ?";
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
preparedStatement.setString(1, resourceId);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
return true;
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while checking key manager for " + resourceId + " in organization " + organization, e);
}
return false;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getCommonOperationPolicyByPolicyID.
private OperationPolicyData getCommonOperationPolicyByPolicyID(Connection connection, String policyId, String organization, boolean isWithPolicyDefinition) throws SQLException {
String dbQuery = SQLConstants.OperationPolicyConstants.GET_COMMON_OPERATION_POLICY_WITH_OUT_DEFINITION_FROM_POLICY_ID;
PreparedStatement statement = connection.prepareStatement(dbQuery);
statement.setString(1, policyId);
statement.setString(2, organization);
ResultSet rs = statement.executeQuery();
OperationPolicyData policyData = null;
if (rs.next()) {
policyData = new OperationPolicyData();
policyData.setPolicyId(policyId);
policyData.setOrganization(organization);
policyData.setMd5Hash(rs.getString("POLICY_MD5"));
policyData.setSpecification(populatePolicySpecificationFromRS(rs));
}
rs.close();
statement.close();
if (isWithPolicyDefinition && policyData != null) {
populatePolicyDefinitions(connection, policyId, policyData);
}
return policyData;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method isApplicationExist.
/**
* Check whether given application name is available under current subscriber or group
*
* @param appName application name
* @param username subscriber
* @param groupId group of the subscriber
* @param organization identifier of the organization
* @return true if application is available for the subscriber
* @throws APIManagementException if failed to get applications for given subscriber
*/
public boolean isApplicationExist(String appName, String username, String groupId, String organization) throws APIManagementException {
if (username == null) {
return false;
}
Subscriber subscriber = getSubscriber(username);
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
int appId = 0;
String sqlQuery = SQLConstants.GET_APPLICATION_ID_PREFIX;
String whereClauseWithGroupId = " AND (APP.GROUP_ID = ? OR ((APP.GROUP_ID='' OR APP.GROUP_ID IS NULL)" + " AND SUB.USER_ID = ?))";
String whereClauseWithGroupIdCaseInsensitive = " AND (APP.GROUP_ID = ? " + "OR ((APP.GROUP_ID='' OR APP.GROUP_ID IS NULL) AND LOWER(SUB.USER_ID) = LOWER(?)))";
String whereClauseWithMultiGroupId = " AND ( (APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM " + "AM_APPLICATION_GROUP_MAPPING WHERE GROUP_ID IN ($params) AND TENANT = ?)) OR ( SUB.USER_ID = ? ) " + "OR (APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM AM_APPLICATION WHERE GROUP_ID = ?)))";
String whereClauseWithMultiGroupIdCaseInsensitive = " AND ( (APP.APPLICATION_ID IN (SELECT APPLICATION_ID " + "FROM AM_APPLICATION_GROUP_MAPPING WHERE GROUP_ID IN ($params) AND TENANT = ?)) " + "OR (LOWER(SUB.USER_ID) = LOWER(?))" + "OR (APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM AM_APPLICATION WHERE GROUP_ID = ?)))";
String whereClause = " AND SUB.USER_ID = ? ";
String whereClauseCaseInsensitive = " AND LOWER(SUB.USER_ID) = LOWER(?) ";
try {
connection = APIMgtDBUtil.getConnection();
if (!StringUtils.isEmpty(groupId)) {
if (multiGroupAppSharingEnabled) {
if (forceCaseInsensitiveComparisons) {
sqlQuery += whereClauseWithMultiGroupIdCaseInsensitive;
} else {
sqlQuery += whereClauseWithMultiGroupId;
}
String tenantDomain = MultitenantUtils.getTenantDomain(subscriber.getName());
String[] grpIdArray = groupId.split(",");
int noOfParams = grpIdArray.length;
preparedStatement = fillQueryParams(connection, sqlQuery, grpIdArray, 3);
preparedStatement.setString(1, appName);
preparedStatement.setString(2, organization);
int paramIndex = noOfParams + 2;
preparedStatement.setString(++paramIndex, tenantDomain);
preparedStatement.setString(++paramIndex, subscriber.getName());
preparedStatement.setString(++paramIndex, tenantDomain + '/' + groupId);
} else {
if (forceCaseInsensitiveComparisons) {
sqlQuery += whereClauseWithGroupIdCaseInsensitive;
} else {
sqlQuery += whereClauseWithGroupId;
}
preparedStatement = connection.prepareStatement(sqlQuery);
preparedStatement.setString(1, appName);
preparedStatement.setString(2, organization);
preparedStatement.setString(3, groupId);
preparedStatement.setString(4, subscriber.getName());
}
} else {
if (forceCaseInsensitiveComparisons) {
sqlQuery += whereClauseCaseInsensitive;
} else {
sqlQuery += whereClause;
}
preparedStatement = connection.prepareStatement(sqlQuery);
preparedStatement.setString(1, appName);
preparedStatement.setString(2, organization);
preparedStatement.setString(3, subscriber.getName());
}
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
appId = resultSet.getInt("APPLICATION_ID");
}
if (appId > 0) {
return true;
}
} catch (SQLException e) {
handleException("Error while getting the id of " + appName + " from the persistence store.", e);
} finally {
APIMgtDBUtil.closeAllConnections(preparedStatement, connection, resultSet);
}
return false;
}
Aggregations