use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.
the class ApiXmlPropertiesResult method updatePageInformation.
/**
* Update page information.
*
* @param node Element for the page.
* @param page Page.
* @throws JDOMException Exception from due to the DOM.
*/
public void updatePageInformation(Element node, Page page) throws JDOMException {
// Retrieve basic page information
Attribute attrPageId = node.getAttribute("pageid");
if (attrPageId != null) {
page.setPageId(attrPageId.getValue());
}
Attribute attrTitle = node.getAttribute("title");
if (attrTitle != null) {
page.setTitle(attrTitle.getValue());
}
Optional.ofNullable(node.getAttributeValue("starttimestamp")).ifPresent(timestamp -> page.setStartTimestamp(timestamp));
Attribute attrRedirect = node.getAttribute("redirect");
if (attrRedirect != null) {
page.getRedirects().isRedirect(true);
}
Attribute attrMissing = node.getAttribute("missing");
if (attrMissing != null) {
page.setExisting(Boolean.FALSE);
}
// Retrieve protection information
XPathExpression<Element> xpaProtection = XPathFactory.instance().compile("protection/pr[@type=\"edit\"]", Filters.element());
List<Element> protectionNodes = xpaProtection.evaluate(node);
for (Element protectionNode : protectionNodes) {
if ("edit".equals(protectionNode.getAttributeValue("type"))) {
page.setEditProtectionLevel(protectionNode.getAttributeValue("level"));
}
}
}
use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.
the class ApiJsonResult method getPage.
/**
* Get a page corresponding to a page node.
*
* @param wiki Wiki.
* @param pageNode Page node.
* @param knownPages Already known pages.
* @param useDisambig True if disambiguation property should be used.
* @return Page.
*/
protected static Page getPage(EnumWikipedia wiki, Element pageNode, List<Page> knownPages, boolean useDisambig) {
if (pageNode == null) {
return null;
}
String title = pageNode.getAttributeValue("title");
Attribute pageIdAttr = pageNode.getAttribute("pageid");
Integer pageId = null;
if (pageIdAttr != null) {
try {
String tmp = pageIdAttr.getValue();
pageId = Integer.valueOf(tmp);
} catch (NumberFormatException e) {
//
}
}
String revisionId = pageNode.getAttributeValue("lastrevid");
Page page = DataManager.getPage(wiki, title, pageId, revisionId, knownPages);
page.setNamespace(pageNode.getAttributeValue("ns"));
if (pageNode.getAttribute("missing") != null) {
page.setExisting(Boolean.FALSE);
} else if (pageId != null) {
page.setExisting(Boolean.TRUE);
}
if (pageNode.getAttribute("redirect") != null) {
page.getRedirects().isRedirect(true);
}
if (useDisambig) {
Element pageProps = pageNode.getChild("pageprops");
boolean dabPage = (pageProps != null) && (pageProps.getAttribute("disambiguation") != null);
page.setDisambiguationPage(Boolean.valueOf(dabPage));
}
return page;
}
use of com.mindbright.security.x509.Attribute in project wpcleaner by WPCleaner.
the class ApiXmlResult method shouldContinue.
/**
* Manage query-continue in request.
*
* @param root Root of the DOM tree.
* @param queryContinue XPath query to the query-continue node.
* @param properties Properties defining request.
* @return True if request should be continued.
*/
protected boolean shouldContinue(Element root, String queryContinue, Map<String, String> properties) {
if ((root == null) || (queryContinue == null)) {
return false;
}
boolean result = false;
XPathExpression<Element> xpa = XPathFactory.instance().compile(queryContinue, Filters.element());
List<Element> results = xpa.evaluate(root);
if ((results == null) || (results.isEmpty())) {
xpa = XPathFactory.instance().compile("/api/continue", Filters.element());
results = xpa.evaluate(root);
}
if (results != null) {
for (Object currentNode : results) {
List attributes = ((Element) currentNode).getAttributes();
if (attributes != null) {
for (Object currentAttribute : attributes) {
Attribute attribute = (Attribute) currentAttribute;
properties.put(attribute.getName(), attribute.getValue());
result = true;
}
}
}
}
return result;
}
use of com.mindbright.security.x509.Attribute in project AndroidSampleLibrary by JackChen365.
the class AndroidManifest method parserAndroidManifest.
@Nonnull
private ManifestInformation parserAndroidManifest(File manifestFile) throws JDOMException, IOException {
ManifestInformation manifestInformation = new ManifestInformation();
if (!manifestFile.exists()) {
System.out.println("File:" + manifestFile.getPath() + " not exists!");
} else {
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(manifestFile);
XPathFactory xPathFactory = XPathFactory.instance();
Namespace androidNameSpace = Namespace.getNamespace("android", "http://schemas.android.com/apk/res/android");
XPathExpression<Attribute> applicationExpression = xPathFactory.compile("//application/@android:name", Filters.attribute(), null, androidNameSpace);
Attribute applicationAttribute = applicationExpression.evaluateFirst(document);
if (null != applicationAttribute) {
manifestInformation.application = applicationAttribute.getValue();
}
XPathExpression<Attribute> applicationIdExpression = xPathFactory.compile("/manifest/@package", Filters.attribute(), null, androidNameSpace);
Attribute applicationIdAttribute = applicationIdExpression.evaluateFirst(document);
if (null != applicationIdAttribute) {
manifestInformation.applicationId = applicationIdAttribute.getValue();
}
XPathExpression<Attribute> expression = xPathFactory.compile("//activity/@android:name", Filters.attribute(), null, androidNameSpace);
List<Attribute> attributeList = expression.evaluate(document);
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = attributeList.get(i);
manifestInformation.addActivity(attribute.getValue());
}
}
return manifestInformation;
}
use of com.mindbright.security.x509.Attribute in project core by authzforce.
the class StandardJavaTypeToXacmlAttributeDatatypeConversionTest method test.
@Test
public void test() {
if (rawValues == null || rawValues.isEmpty()) {
try {
attValFactories.newAttributeBag(rawValues);
Assert.fail("Should have raised IllegalArgumentException because of invalid rawValues");
} catch (final Exception e) {
Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
}
return;
}
// rawValues has at least one value
if (rawValues.size() == 1) {
final Serializable rawVal = rawValues.iterator().next();
if (rawVal == null) {
/*
* Instantiate using expected datatype to check if null is spotted as invalid value
*/
try {
attValFactories.newExpression(expectedAttributeDatatypeId, Collections.singletonList(null), null, null);
Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
} catch (final Exception e) {
Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
}
} else {
try {
final AttributeValueFactory<?> attValFactory = attValFactories.getCompatibleFactory(rawVal.getClass());
final String actualDatatypeId = attValFactory.getDatatype().getId();
Assert.assertEquals("Invalid datatype for created attribute value", actualDatatypeId, expectedAttributeDatatypeId);
attValFactories.newAttributeValue(rawVal);
Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
} catch (final Exception e) {
Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
}
}
}
try {
final AttributeBag<?> attBag = attValFactories.newAttributeBag(rawValues);
Assert.assertEquals("Invalid datatype for created attribute values", attBag.getElementDatatype().getId(), expectedAttributeDatatypeId);
/*
* Marshall to XACML and try to unmarshall to original Java value to make sure marshalling is OK
*/
final List<AttributeValueType> outXacmlAttVals = attBag.elements().stream().map(attVal -> new AttributeValueType(attVal.getContent(), attBag.getElementDatatype().getId(), attVal.getXmlAttributes())).collect(Collectors.toList());
final Attribute outXacmlAtt = new Attribute(outXacmlAttVals, testId.toString(), null, false);
final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
final StringWriter strWriter = new StringWriter();
marshaller.marshal(outXacmlAtt, strWriter);
final String outStr = strWriter.toString();
final Unmarshaller unmarshaller = Xacml3JaxbHelper.createXacml3Unmarshaller();
final Attribute inXacmlAtt = (Attribute) unmarshaller.unmarshal(new StringReader(outStr));
final List<AttributeValueType> inXacmlAttVals = inXacmlAtt.getAttributeValues();
if (inXacmlAttVals.isEmpty()) {
Assert.fail("Marshalling/unmarshalling failed: no AttributeValue after unmarshalling: " + outStr);
return;
}
final AttributeValueType inXacmlAttVal0 = inXacmlAttVals.get(0);
final AttributeValueFactory<?> attValFactory = this.attValFactories.getExtension(inXacmlAttVal0.getDataType());
final List<AttributeValue> inAttVals = inXacmlAttVals.stream().map(inputXacmlAttValue -> attValFactory.getInstance(inputXacmlAttValue.getContent(), inputXacmlAttValue.getOtherAttributes(), null)).collect(Collectors.toList());
Assert.assertEquals("AttributeValues after unmarshalling do not match original AttributeValues before marshalling: " + outStr, attBag.elements(), ImmutableMultiset.copyOf(inAttVals));
Assert.assertNull("Parsing raw value into AttributeValue did not throw exception as expected", expectedExceptionClass);
} catch (final Exception e) {
Assert.assertTrue("Unexpected error: " + e, expectedExceptionClass != null && expectedExceptionClass.isInstance(e));
}
}
Aggregations