Search in sources :

Example 41 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class PolicyDAOImpl method addApplicationPolicy.

/**
 * Adds an Application Policy
 *
 * @param policy {@link ApplicationPolicy} instance
 * @param connection DB Connection instance
 * @throws SQLException if an error occurs while adding an Application Policy
 */
private static void addApplicationPolicy(ApplicationPolicy policy, Connection connection) throws SQLException {
    final String query = "INSERT INTO AM_APPLICATION_POLICY (UUID, NAME, DISPLAY_NAME, " + "DESCRIPTION, QUOTA_TYPE, QUOTA, QUOTA_UNIT, UNIT_TIME, TIME_UNIT, IS_DEPLOYED, CUSTOM_ATTRIBUTES) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)";
    Limit limit = policy.getDefaultQuotaPolicy().getLimit();
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, policy.getUuid());
        statement.setString(2, policy.getPolicyName());
        statement.setString(3, policy.getDisplayName());
        statement.setString(4, policy.getDescription());
        statement.setString(5, policy.getDefaultQuotaPolicy().getType());
        setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement);
        statement.setInt(8, policy.getDefaultQuotaPolicy().getLimit().getUnitTime());
        statement.setString(9, policy.getDefaultQuotaPolicy().getLimit().getTimeUnit());
        statement.setBoolean(10, policy.isDeployed());
        statement.setBytes(11, policy.getCustomAttributes());
        statement.execute();
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Limit(org.wso2.carbon.apimgt.core.models.policy.Limit) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 42 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class PolicyDAOImpl method setJWTClaimConditions.

/**
 * Add JWT claim conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
 * provided {@link Condition} array
 *
 * @param pipelineId Id of the pipeline
 * @param conditions condition array to populate
 * @throws SQLException
 */
private void setJWTClaimConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
    final String query = "SELECT " + "CLAIM_URI, " + "CLAIM_ATTRIB , IS_CLAIM_MAPPING " + "FROM " + "AM_JWT_CLAIM_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
    try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setInt(1, pipelineId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
                jwtClaimsCondition.setClaimUrl(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_URI));
                jwtClaimsCondition.setAttribute(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_ATTRIBUTE));
                jwtClaimsCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_CLAIM_MAPPING));
                conditions.add(jwtClaimsCondition);
            }
        }
    }
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 43 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class PolicyDAOImpl method setHeaderConditions.

/**
 * Add Header conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
 * provided {@link Condition} array
 *
 * @param connection Connection of the database
 * @param pipelineId Id of the pipeline
 * @param conditions condition array to populate
 * @throws SQLException
 */
private void setHeaderConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
    final String query = "SELECT " + "HEADER_FIELD_NAME, " + "HEADER_FIELD_VALUE , IS_HEADER_FIELD_MAPPING " + " FROM " + "AM_HEADER_FIELD_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
    try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setInt(1, pipelineId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                HeaderCondition headerCondition = new HeaderCondition();
                headerCondition.setHeader(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_HEADER_FIELD_NAME));
                headerCondition.setValue(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_HEADER_FIELD_VALUE));
                headerCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_HEADER_FIELD_MAPPING));
                conditions.add(headerCondition);
            }
        }
    }
}
Also used : HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 44 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method resolveToken.

/**
 * Get the token after decrypting using {@link FileEncryptionUtility#readFromEncryptedFile(java.lang.String)}
 *
 * @return service account token
 * @throws ServiceDiscoveryException if an error occurs while resolving the token
 */
private String resolveToken(String encryptedTokenFileName) throws ServiceDiscoveryException {
    String token;
    try {
        String externalSATokenFilePath = System.getProperty(FileEncryptionUtility.CARBON_HOME) + FileEncryptionUtility.SECURITY_DIR + File.separator + encryptedTokenFileName;
        token = FileEncryptionUtility.getInstance().readFromEncryptedFile(externalSATokenFilePath);
    } catch (APIManagementException e) {
        String msg = "Error occurred while resolving externally stored token";
        throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
    }
    return StringUtils.replace(token, "\n", "");
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException)

Example 45 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getHttpBindingOperations.

/**
 * Retrieves all the operations defined in the provided Binding.
 *
 * @param binding WSDL binding
 * @return a set of {@link WSDLOperation} defined in the provided Binding
 */
private Set<WSDLOperation> getHttpBindingOperations(Binding binding) {
    Set<WSDLOperation> allBindingOperations = new HashSet<>();
    if (binding.getExtensibilityElements() != null && binding.getExtensibilityElements().size() > 0) {
        if (binding.getExtensibilityElements().get(0) instanceof HTTPBinding) {
            HTTPBinding httpBinding = (HTTPBinding) binding.getExtensibilityElements().get(0);
            String verb = httpBinding.getVerb();
            for (Object opObj : binding.getBindingOperations()) {
                if (opObj instanceof BindingOperation) {
                    BindingOperation bindingOperation = (BindingOperation) opObj;
                    WSDLOperation wsdlOperation = getOperation(bindingOperation, verb);
                    if (wsdlOperation != null) {
                        allBindingOperations.add(wsdlOperation);
                    }
                }
            }
        }
    }
    return allBindingOperations;
}
Also used : BindingOperation(javax.wsdl.BindingOperation) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) HashSet(java.util.HashSet)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10