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();
}
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);
}
}
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());
}
}
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);
}
}
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();
}
Aggregations