Search in sources :

Example 11 with Attributes

use of org.wso2.balana.xacml3.Attributes in project siddhi by wso2.

the class InMemoryTransportTestCase method inMemoryTestCase7.

@Test
public void inMemoryTestCase7() throws InterruptedException {
    log.info("Test inMemory 7");
    String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='test', fail='true', " + "   @map(type='passThrough', @attributes(symbol='trp:symbol'," + "        volume='volume',price='trp:price'))) " + "define stream FooStream (symbol string, price string, volume long); " + "define stream BarStream (symbol string, price string, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            wso2Count.incrementAndGet();
            for (Event event : events) {
                AssertJUnit.assertArrayEquals(event.getData(), new Object[] { "hi", "test", 100L });
            }
        }
    });
    siddhiAppRuntime.start();
    InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "WSO2", "in", 100L }));
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of events", 0, wso2Count.get());
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 12 with Attributes

use of org.wso2.balana.xacml3.Attributes in project siddhi by wso2.

the class DocumentationUtils method addExtensionMetaDataIntoNamespaceList.

/**
 * Generate extension meta data from the annotated data in the class
 *
 * @param namespaceList  The list of namespaces to which the new extension will be added
 * @param extensionClass Class from which meta data should be extracted from
 * @param logger         The maven plugin logger
 */
private static void addExtensionMetaDataIntoNamespaceList(List<NamespaceMetaData> namespaceList, Class<?> extensionClass, Log logger) {
    Extension extensionAnnotation = extensionClass.getAnnotation(Extension.class);
    if (extensionAnnotation != null) {
        // Discarding extension classes without annotation
        ExtensionMetaData extensionMetaData = new ExtensionMetaData();
        // Finding extension type
        String extensionType = null;
        for (Map.Entry<ExtensionType, Class<?>> entry : ExtensionType.getSuperClassMap().entrySet()) {
            Class<?> superClass = entry.getValue();
            if (superClass.isAssignableFrom(extensionClass) && superClass != extensionClass) {
                extensionType = entry.getKey().getValue();
                break;
            }
        }
        // Discarding the extension if it belongs to an unknown type
        if (extensionType == null) {
            logger.warn("Discarding extension (belonging to an unknown extension type): " + extensionClass.getCanonicalName());
            return;
        }
        extensionMetaData.setName(extensionAnnotation.name());
        extensionMetaData.setDescription(extensionAnnotation.description());
        // Adding query parameters
        ParameterMetaData[] parameters = new ParameterMetaData[extensionAnnotation.parameters().length];
        for (int i = 0; i < extensionAnnotation.parameters().length; i++) {
            Parameter parameterAnnotation = extensionAnnotation.parameters()[i];
            ParameterMetaData parameter = new ParameterMetaData();
            parameter.setName(parameterAnnotation.name());
            parameter.setType(Arrays.asList(parameterAnnotation.type()));
            parameter.setDescription(parameterAnnotation.description());
            parameter.setOptional(parameterAnnotation.optional());
            parameter.setDynamic(parameterAnnotation.dynamic());
            parameter.setDefaultValue(parameterAnnotation.defaultValue());
            parameters[i] = parameter;
        }
        extensionMetaData.setParameters(Arrays.asList(parameters));
        // Adding system parameters
        SystemParameterMetaData[] systemParameters = new SystemParameterMetaData[extensionAnnotation.systemParameter().length];
        for (int i = 0; i < extensionAnnotation.systemParameter().length; i++) {
            SystemParameter systemParameterAnnotation = extensionAnnotation.systemParameter()[i];
            SystemParameterMetaData systemParameter = new SystemParameterMetaData();
            systemParameter.setName(systemParameterAnnotation.name());
            systemParameter.setDescription(systemParameterAnnotation.description());
            systemParameter.setDefaultValue(systemParameterAnnotation.defaultValue());
            systemParameter.setPossibleParameters(Arrays.asList(systemParameterAnnotation.possibleParameters()));
            systemParameters[i] = systemParameter;
        }
        extensionMetaData.setSystemParameters(Arrays.asList(systemParameters));
        // Adding return attributes
        ReturnAttributeMetaData[] returnAttributes = new ReturnAttributeMetaData[extensionAnnotation.returnAttributes().length];
        for (int i = 0; i < extensionAnnotation.returnAttributes().length; i++) {
            ReturnAttribute parameterAnnotation = extensionAnnotation.returnAttributes()[i];
            ReturnAttributeMetaData returnAttribute = new ReturnAttributeMetaData();
            returnAttribute.setName(parameterAnnotation.name());
            returnAttribute.setType(Arrays.asList(parameterAnnotation.type()));
            returnAttribute.setDescription(parameterAnnotation.description());
            returnAttributes[i] = returnAttribute;
        }
        extensionMetaData.setReturnAttributes(Arrays.asList(returnAttributes));
        // Adding examples
        ExampleMetaData[] examples = new ExampleMetaData[extensionAnnotation.examples().length];
        for (int i = 0; i < extensionAnnotation.examples().length; i++) {
            Example exampleAnnotation = extensionAnnotation.examples()[i];
            ExampleMetaData exampleMetaData = new ExampleMetaData();
            exampleMetaData.setSyntax(exampleAnnotation.syntax());
            exampleMetaData.setDescription(exampleAnnotation.description());
            examples[i] = exampleMetaData;
        }
        extensionMetaData.setExamples(Arrays.asList(examples));
        // Finding the namespace
        String namespaceName = extensionAnnotation.namespace();
        if (Objects.equals(namespaceName, "")) {
            namespaceName = Constants.CORE_NAMESPACE;
        }
        // Finding the relevant namespace in the namespace list
        NamespaceMetaData namespace = null;
        for (NamespaceMetaData existingNamespace : namespaceList) {
            if (Objects.equals(existingNamespace.getName(), namespaceName)) {
                namespace = existingNamespace;
                break;
            }
        }
        // Creating namespace if it doesn't exist
        if (namespace == null) {
            namespace = new NamespaceMetaData();
            namespace.setName(namespaceName);
            namespace.setExtensionMap(new TreeMap<>());
            namespaceList.add(namespace);
        }
        // Adding to the relevant extension metadata list in the namespace
        List<ExtensionMetaData> extensionMetaDataList = namespace.getExtensionMap().computeIfAbsent(extensionType, k -> new ArrayList<>());
        extensionMetaDataList.add(extensionMetaData);
    }
}
Also used : ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Example(org.wso2.siddhi.annotation.Example) SystemParameter(org.wso2.siddhi.annotation.SystemParameter) ExampleMetaData(org.wso2.siddhi.doc.gen.commons.metadata.ExampleMetaData) NamespaceMetaData(org.wso2.siddhi.doc.gen.commons.metadata.NamespaceMetaData) Extension(org.wso2.siddhi.annotation.Extension) ReturnAttributeMetaData(org.wso2.siddhi.doc.gen.commons.metadata.ReturnAttributeMetaData) ExtensionType(org.wso2.siddhi.doc.gen.commons.metadata.ExtensionType) ExtensionMetaData(org.wso2.siddhi.doc.gen.commons.metadata.ExtensionMetaData) SystemParameterMetaData(org.wso2.siddhi.doc.gen.commons.metadata.SystemParameterMetaData) SystemParameter(org.wso2.siddhi.annotation.SystemParameter) Parameter(org.wso2.siddhi.annotation.Parameter) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ParameterMetaData(org.wso2.siddhi.doc.gen.commons.metadata.ParameterMetaData) SystemParameterMetaData(org.wso2.siddhi.doc.gen.commons.metadata.SystemParameterMetaData)

Example 13 with Attributes

use of org.wso2.balana.xacml3.Attributes in project carbon-apimgt by wso2.

the class APIPublisherImpl method searchAPIs.

/**
 * @param limit  Limit
 * @param offset Offset
 * @param query  Search query
 * @return List of APIS.
 * @throws APIManagementException If failed to formatApiSearch APIs.
 */
@Override
public List<API> searchAPIs(Integer limit, Integer offset, String query) throws APIManagementException {
    List<API> apiResults;
    String user = getUsername();
    Set<String> roles = new HashSet<>();
    try {
        // TODO: Need to validate users roles against results returned
        if (!"admin".equals(user)) {
            // Whenever call identity provider should convert pseudo name to actual name
            String userId = getIdentityProvider().getIdOfUser(user);
            roles = new HashSet<>(getIdentityProvider().getRoleIdsOfUser(userId));
        }
        if (query != null && !query.isEmpty()) {
            String[] attributes = query.split(ATTRIBUTE_DELIMITER);
            Map<String, String> attributeMap = new HashMap<>();
            boolean isFullTextSearch = false;
            String searchAttribute, searchValue;
            if (!query.contains(KEY_VALUE_DELIMITER)) {
                isFullTextSearch = true;
            } else {
                log.debug("Search query: " + query);
                for (String attribute : attributes) {
                    searchAttribute = attribute.split(KEY_VALUE_DELIMITER)[0];
                    searchValue = attribute.split(KEY_VALUE_DELIMITER)[1];
                    log.debug(searchAttribute + KEY_VALUE_DELIMITER + searchValue);
                    attributeMap.put(searchAttribute, searchValue);
                }
            }
            if (isFullTextSearch) {
                apiResults = getApiDAO().searchAPIs(roles, user, query, offset, limit);
            } else {
                log.debug("Attributes:", attributeMap.toString());
                apiResults = getApiDAO().attributeSearchAPIs(roles, user, attributeMap, offset, limit);
            }
        } else {
            apiResults = getApiDAO().getAPIs(roles, user);
        }
        return apiResults;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while Searching the API with query " + query;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    } catch (IdentityProviderException e) {
        String errorMsg = "Error occurred while calling SCIM endpoint to retrieve user " + user + "'s information";
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) HashMap(java.util.HashMap) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) API(org.wso2.carbon.apimgt.core.models.API) IdentityProviderException(org.wso2.carbon.apimgt.core.exception.IdentityProviderException) HashSet(java.util.HashSet)

Example 14 with Attributes

use of org.wso2.balana.xacml3.Attributes in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testAttributeSearchAPIsStore.

@Test
public void testAttributeSearchAPIsStore() throws Exception {
    // Add few APIs with different attributes.
    List<String> apiIDList = createAPIsAndGetIDsOfAddedAPIs();
    List<String> userRoles = new ArrayList<>();
    Map<String, String> attributeMap = new HashMap<>();
    String[] expectedAPINames;
    // Asserting results for different search queries
    // Attribute search for "provider", for "admin" role
    userRoles.add(ADMIN);
    attributeMap.put("provider", "a");
    expectedAPINames = new String[] { "PublicAPI", "AdminManagerAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // Attribute search for "version", for "manager" role
    userRoles.add(MANAGER_ROLE);
    attributeMap.put("version", "2.3");
    expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // Attribute search for "context", for "manager", "employee" and "customer" roles
    userRoles.add(MANAGER_ROLE);
    userRoles.add(EMPLOYEE_ROLE);
    userRoles.add(CUSTOMER_ROLE);
    attributeMap.put("context", "Man");
    expectedAPINames = new String[] { "ManagerOnlyAPI", "AdminManagerAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // Attribute search for "description", for "admin" role
    userRoles.add(ADMIN);
    attributeMap.put("description", "Admin and manager");
    expectedAPINames = new String[] { "AdminManagerAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // Attribute search for "tags", for "manager", "employee" and "customer" roles
    userRoles.add(MANAGER_ROLE);
    userRoles.add(EMPLOYEE_ROLE);
    userRoles.add(CUSTOMER_ROLE);
    attributeMap.put("tags", "E");
    expectedAPINames = new String[] { "ManagerOnlyAPI", "NonAdminAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // Attribute search for "subcontext", for "manager", "employee" and "customer" roles
    userRoles.add(MANAGER_ROLE);
    userRoles.add(EMPLOYEE_ROLE);
    userRoles.add(CUSTOMER_ROLE);
    attributeMap.put("subcontext", "C");
    expectedAPINames = new String[] { "AdminManagerAPI", "EmployeeAPI", "NonAdminAPI" };
    Assert.assertTrue(compareResults(userRoles, new ArrayList<>(), attributeMap, expectedAPINames));
    userRoles.clear();
    attributeMap.clear();
    // cleanup added APIs
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    for (String apiID : apiIDList) {
        apiDAO.deleteAPI(apiID);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 15 with Attributes

use of org.wso2.balana.xacml3.Attributes in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testGetAPIsByStatusStore.

@Test
public void testGetAPIsByStatusStore() throws Exception {
    // Add few APIs with different attributes.
    List<String> apiIDList = createAPIsAndGetIDsOfAddedAPIs();
    Set<String> userRoles = new HashSet<>();
    List<String> statuses = new ArrayList<>();
    statuses.add(APIStatus.PUBLISHED.getStatus());
    statuses.add(APIStatus.PROTOTYPED.getStatus());
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    String[] expectedAPINames;
    List<API> apiResults;
    // Asserting results for different search queries
    // Role based API retrieval for a user with "admin" role
    userRoles.add(ADMIN);
    apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
    List<String> resultAPINameList = new ArrayList<>();
    for (API api : apiResults) {
        resultAPINameList.add(api.getName());
    }
    expectedAPINames = new String[] { "PublicAPI", "AdminManagerAPI" };
    Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
    userRoles.clear();
    apiResults.clear();
    resultAPINameList.clear();
    // Role based API retrieval for a user with "manager" role
    userRoles.add(MANAGER_ROLE);
    apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
    for (API api : apiResults) {
        resultAPINameList.add(api.getName());
    }
    expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI", "AdminManagerAPI", "NonAdminAPI" };
    Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
    userRoles.clear();
    apiResults.clear();
    resultAPINameList.clear();
    // Role based API retrieval for a user with "manager", "employee" and "customer" roles
    userRoles.add(MANAGER_ROLE);
    userRoles.add(EMPLOYEE_ROLE);
    userRoles.add(CUSTOMER_ROLE);
    apiResults = apiDAO.getAPIsByStatus(userRoles, statuses, new ArrayList<>());
    for (API api : apiResults) {
        resultAPINameList.add(api.getName());
    }
    expectedAPINames = new String[] { "PublicAPI", "ManagerOnlyAPI", "AdminManagerAPI", "EmployeeAPI", "NonAdminAPI" };
    Assert.assertTrue(resultAPINameList.containsAll(Arrays.asList(expectedAPINames)) && Arrays.asList(expectedAPINames).containsAll(resultAPINameList));
    userRoles.clear();
    apiResults.clear();
    resultAPINameList.clear();
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)111 ArrayList (java.util.ArrayList)110 Test (org.testng.annotations.Test)106 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)83 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)76 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)64 Map (java.util.Map)55 CharonException (org.wso2.charon3.core.exceptions.CharonException)54 User (org.wso2.charon3.core.objects.User)53 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)43 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)39 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)39 List (java.util.List)35 Group (org.wso2.charon3.core.objects.Group)33 JSONObject (org.json.JSONObject)32 Attribute (org.wso2.charon3.core.attributes.Attribute)32 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)32 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)30 UserStoreException (org.wso2.carbon.user.api.UserStoreException)26 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)26