/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/// Represents one category of a classification policy. class SfxClassificationCategory
{ public: /// PROP_BACNAME() is stored separately for easier lookup.
OUString m_aName;
OUString m_aAbbreviatedName; //< An abbreviation to display instead of m_aName.
OUString m_aIdentifier; //< The Identifier of this entry.
size_t m_nConfidentiality; //< 0 is the lowest (least-sensitive).
std::map<OUString, OUString> m_aLabels;
};
/// Parses a policy XML conforming to the TSCP BAF schema. class SfxClassificationParser : public cppu::WeakImplHelper<xml::sax::XDocumentHandler>
{ public:
std::vector<SfxClassificationCategory> m_aCategories;
std::vector<OUString> m_aMarkings;
std::vector<OUString> m_aIPParts;
std::vector<OUString> m_aIPPartNumbers;
// Create a new category and initialize it with the data that's true for all categories.
m_aCategories.emplace_back();
SfxClassificationCategory& rCategory = m_aCategories.back();
rCategory.m_aName = aName; // Set the abbreviated name, if any, otherwise fallback on the full name. const OUString aAbbreviatedName = xAttribs->getValueByName(u"loextAbbreviatedName"_ustr);
rCategory.m_aAbbreviatedName = !aAbbreviatedName.isEmpty() ? aAbbreviatedName : aName;
rCategory.m_aIdentifier = aIdentifier;
/// Implementation details of SfxClassificationHelper. class SfxClassificationHelper::Impl
{ public: /// Selected categories, one category for each policy type.
std::map<SfxClassificationPolicyType, SfxClassificationCategory> m_aCategory; /// Possible categories of a policy to choose from.
std::vector<SfxClassificationCategory> m_aCategories;
std::vector<OUString> m_aMarkings;
std::vector<OUString> m_aIPParts;
std::vector<OUString> m_aIPPartNumbers;
explicit Impl(uno::Reference<document::XDocumentProperties> xDocumentProperties, boolbUseLocalized); void parsePolicy(); /// Synchronize m_aLabels back to the document properties. void pushToDocumentProperties(); /// Set the classification start date to the system time. void setStartValidity(SfxClassificationPolicyType eType);
};
// See if there is a localized variant next to the configured XML.
OUString aExtension(u".xml"_ustr); if (aPath.endsWith(aExtension) && m_bUseLocalized)
{
std::u16string_view aBase = aPath.subView(0, aPath.getLength() - aExtension.getLength()); const LanguageTag& rLanguageTag = Application::GetSettings().GetLanguageTag(); // Expected format is "<original path>_xx-XX.xml".
OUString aLocalized = OUString::Concat(aBase) + "_" + rLanguageTag.getBcp47() + aExtension; if (FStatHelper::IsDocument(aLocalized))
aPath = aLocalized;
}
void SfxClassificationHelper::Impl::setStartValidity(SfxClassificationPolicyType eType)
{ auto itCategory = m_aCategory.find(eType); if (itCategory == m_aCategory.end()) return;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(policyTypeToString(eType) + PROP_STARTVALIDITY()); if (it != rCategory.m_aLabels.end())
{ if (it->second == PROP_NONE())
{ // The policy left the start date unchanged, replace it with the system time.
util::DateTime aDateTime = DateTime(DateTime::SYSTEM).GetUNODateTime();
it->second = utl::toISO8601(aDateTime);
}
}
}
uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY); const uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties(); for (const beans::Property& rProperty : aProperties)
{ if (rProperty.Name.startsWith("urn:bails:")) returntrue;
}
returnfalse;
}
SfxClassificationCheckPasteResult SfxClassificationHelper::CheckPaste(const uno::Reference<document::XDocumentProperties>& xSource, const uno::Reference<document::XDocumentProperties>& xDestination)
{ if (!SfxClassificationHelper::IsClassified(xSource)) // No classification on the source side. Return early, regardless the // state of the destination side. return SfxClassificationCheckPasteResult::None;
if (!SfxClassificationHelper::IsClassified(xDestination))
{ // Paste from a classified document to a non-classified one -> deny. return SfxClassificationCheckPasteResult::TargetDocNotClassified;
}
// Remaining case: paste between two classified documents.
SfxClassificationHelper aSource(xSource);
SfxClassificationHelper aDestination(xDestination); if (aSource.GetImpactScale() != aDestination.GetImpactScale()) // It's possible to compare them if they have the same scale. return SfxClassificationCheckPasteResult::None;
if (aSource.GetImpactLevel() > aDestination.GetImpactLevel()) // Paste from a doc that has higher classification -> deny. return SfxClassificationCheckPasteResult::DocClassificationTooLow;
return SfxClassificationCheckPasteResult::None;
}
bool SfxClassificationHelper::ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
{ switch (eResult)
{ case SfxClassificationCheckPasteResult::None:
{ returntrue;
} break; case SfxClassificationCheckPasteResult::TargetDocNotClassified:
{ if (!Application::IsHeadlessModeEnabled())
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Info, VclButtonsType::Ok,
SfxResId(STR_TARGET_DOC_NOT_CLASSIFIED)));
xBox->run();
} returnfalse;
} break; case SfxClassificationCheckPasteResult::DocClassificationTooLow:
{ if (!Application::IsHeadlessModeEnabled())
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Info, VclButtonsType::Ok,
SfxResId(STR_DOC_CLASSIFICATION_TOO_LOW)));
xBox->run();
} returnfalse;
} break;
}
return nFirstConfidentiality >= nSecondConfidentiality ? first : second;
}
bool SfxClassificationHelper::HasImpactLevel()
{ auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) returnfalse;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTSCALE()); if (it == rCategory.m_aLabels.end()) returnfalse;
it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTLEVEL()); return it != rCategory.m_aLabels.end();
}
bool SfxClassificationHelper::HasDocumentHeader()
{ auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) returnfalse;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_DOCHEADER()); return it != rCategory.m_aLabels.end() && !it->second.isEmpty();
}
bool SfxClassificationHelper::HasDocumentFooter()
{ auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) returnfalse;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_DOCFOOTER()); return it != rCategory.m_aLabels.end() && !it->second.isEmpty();
}
auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) return aRet;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTSCALE()); if (it == rCategory.m_aLabels.end()) return aRet;
OUString aScale = it->second;
it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTLEVEL()); if (it == rCategory.m_aLabels.end()) return aRet;
OUString aLevel = it->second;
auto itCategory = m_pImpl->m_aCategory.find(SfxClassificationPolicyType::IntellectualProperty); if (itCategory == m_pImpl->m_aCategory.end()) return nRet;
SfxClassificationCategory& rCategory = itCategory->second; auto it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTSCALE()); if (it == rCategory.m_aLabels.end()) return nRet;
OUString aScale = it->second;
it = rCategory.m_aLabels.find(PROP_PREFIX_INTELLECTUALPROPERTY() + PROP_IMPACTLEVEL()); if (it == rCategory.m_aLabels.end()) return nRet;
OUString aLevel = it->second;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.