本文整理汇总了Java中org.apache.xml.security.signature.Reference类的典型用法代码示例。如果您正苦于以下问题:Java Reference类的具体用法?Java Reference怎么用?Java Reference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reference类属于org.apache.xml.security.signature包,在下文中一共展示了Reference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSignatureImpl
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* Validate an instance of {@link SignatureImpl}, which is in turn based on underlying Apache XML Security
* <code>XMLSignature</code> instance.
*
* @param sigImpl the signature implementation object to validate
* @throws ValidationException thrown if the signature is not valid with respect to the profile
*/
protected void validateSignatureImpl(SignatureImpl sigImpl) throws ValidationException {
if (sigImpl.getXMLSignature() == null) {
log.error("SignatureImpl did not contain the an Apache XMLSignature child");
throw new ValidationException("Apache XMLSignature does not exist on SignatureImpl");
}
XMLSignature apacheSig = sigImpl.getXMLSignature();
if (!(sigImpl.getParent() instanceof SignableSAMLObject)) {
log.error("Signature is not an immedidate child of a SignableSAMLObject");
throw new ValidationException("Signature is not an immediate child of a SignableSAMLObject.");
}
SignableSAMLObject signableObject = (SignableSAMLObject) sigImpl.getParent();
Reference ref = validateReference(apacheSig);
String uri = ref.getURI();
validateReferenceURI(uri, signableObject);
validateTransforms(ref);
validateObjectChildren(apacheSig);
}
示例2: validateReference
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* Validate the Signature's SignedInfo Reference.
*
* The SignedInfo must contain exactly 1 Reference.
*
* @param apacheSig the Apache XML Signature instance
* @return the valid Reference contained within the SignedInfo
* @throws ValidationException thrown if the Signature does not contain exactly 1 Reference, or if there is an error
* obtaining the Reference instance
*/
protected Reference validateReference(XMLSignature apacheSig) throws ValidationException {
int numReferences = apacheSig.getSignedInfo().getLength();
if (numReferences != 1) {
log.error("Signature SignedInfo had invalid number of References: " + numReferences);
throw new ValidationException("Signature SignedInfo must have exactly 1 Reference element");
}
Reference ref = null;
try {
ref = apacheSig.getSignedInfo().item(0);
} catch (XMLSecurityException e) {
log.error("Apache XML Security exception obtaining Reference", e);
throw new ValidationException("Could not obtain Reference from Signature/SignedInfo", e);
}
if (ref == null) {
log.error("Signature Reference was null");
throw new ValidationException("Signature Reference was null");
}
return ref;
}
示例3: checkReferences
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
private void checkReferences(XMLSignature xmlSignature) throws Exception {
SignedInfo signedInfo = xmlSignature.getSignedInfo();
assertTrue(signedInfo.getLength() > 0);
for (int i = 0; i < signedInfo.getLength(); i++) {
Reference reference = signedInfo.item(i);
assertNotNull(reference);
ReferenceData referenceData = reference.getReferenceData();
assertNotNull(referenceData);
if (referenceData instanceof ReferenceNodeSetData) {
Iterator<Node> iter = ((ReferenceNodeSetData)referenceData).iterator();
assertTrue(iter.hasNext());
boolean found = false;
while (iter.hasNext()) {
Node n = iter.next();
if (n instanceof Element) {
found = true;
break;
}
}
assertTrue(found);
} else if (referenceData instanceof ReferenceOctetStreamData) {
assertNotNull(((ReferenceOctetStreamData)referenceData).getOctetStream());
}
}
}
示例4: addReference
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Override
public void addReference(Reference r) throws CannotAddDataToDigestInputException
{
if (null == r)
{
throw new NullPointerException();
}
try
{
XMLSignatureInput refData = r.getContentsAfterTransformation();
addToDigestInput(refData, r.getDocument());
} catch (XMLSignatureException ex)
{
throw new CannotAddDataToDigestInputException(ex);
}
}
示例5: createPropDataObj
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Override
protected BaseXAdESTimeStampData createPropDataObj(
IndividualDataObjsTimeStampProperty prop,
Algorithm c14n,
TimeStampTokenRes tsTknRes,
PropertiesDataGenerationContext ctx)
{
Collection<DataObjectDesc> targetDataObjs = prop.getTargetDataObjects();
Map<DataObjectDesc, Reference> refsMaps = ctx.getReferencesMappings();
List<String> includes = new ArrayList<String>(targetDataObjs.size());
for (DataObjectDesc dataObj : targetDataObjs)
{
Reference r = refsMaps.get(dataObj);
includes.add('#' + r.getId());
}
prop.setTime(tsTknRes.timeStampTime);
return new IndividualDataObjsTimeStampData(c14n, includes, tsTknRes.encodedTimeStampToken);
}
示例6: PropertiesDataGenerationContext
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* A simple constructor to be used when only unsigned signature properties
* will be processed.
* @param targetXmlSignature the target signature
* @param algorithmsProvider algorithms in use
*/
PropertiesDataGenerationContext(XMLSignature targetXmlSignature) throws XAdES4jXMLSigException
{
this.targetXmlSignature = targetXmlSignature;
this.sigDocument = targetXmlSignature.getDocument();
this.referencesMappings = null;
SignedInfo signedInfo = targetXmlSignature.getSignedInfo();
List<Reference> refs = new ArrayList<Reference>(signedInfo.getLength());
for (int i = 0; i < signedInfo.getLength(); i++)
{
try
{
refs.add(signedInfo.item(i));
} catch (XMLSecurityException ex)
{
throw new XAdES4jXMLSigException(String.format("Cannot process the %dth reference", i), ex);
}
}
this.references = Collections.unmodifiableList(refs);
}
示例7: testAddNullReference
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Test
public void testAddNullReference() throws Exception
{
System.out.println("addNullReference");
Document doc = SignatureServicesTestBase.getNewDocument();
SignedDataObjects dataObjsDescs = new SignedDataObjects()
.withSignedDataObject(new AnonymousDataObjectReference("data".getBytes()));
XMLSignature xmlSignature = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);
xmlSignature.setId("sigId");
SignedDataObjectsProcessor processor = new SignedDataObjectsProcessor(new TestAlgorithmsProvider(), new AllwaysNullAlgsParamsMarshaller());
Map<DataObjectDesc, Reference> result = processor.process(dataObjsDescs, xmlSignature);
assertEquals(1, result.size());
assertEquals(0, xmlSignature.getObjectLength());
assertEquals(1, xmlSignature.getSignedInfo().getLength());
Reference r = xmlSignature.getSignedInfo().item(0);
assertNull(r.getElement().getAttributeNodeNS(Constants.SignatureSpecNS, "URI"));
}
示例8: generateXAdESContentTimestampAsTimestampToken
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* Method that generates a XAdES ContentTimestamp (either an ALL DATA OBJECTS TIMESTAMP or an INDIVIDUAL DATA
* OBJECTS TIMESTAMP) and returns
* it as a TimestampToken
*
* @param toSignDocument
* @param externalParameters
* @param timestampType
* @return
*/
public TimestampToken generateXAdESContentTimestampAsTimestampToken(final DSSDocument toSignDocument, final XAdESSignatureParameters externalParameters,
final TimestampType timestampType) {
if (externalParameters == null) {
throw new NullPointerException();
}
// 1. Set initial parameters
final XAdESSignatureParameters signatureParameters = setSignatureParameters(externalParameters);
// 2. Build temporary signature structure
final XAdESLevelBaselineB levelBaselineB = new XAdESLevelBaselineB(commonCertificateVerifier);
byte[] signatureValueBytes = Utils.fromBase64(fakeSignatureValue);
final DSSDocument fullSignature = levelBaselineB.signDocument(toSignDocument, signatureParameters, signatureValueBytes);
final List<Reference> references = getReferencesFromValidatedSignature(toSignDocument, fullSignature);
// 4. Concatenate byte value of references, excluding references of type SignedProperties
byte[] concatenatedReferences = concatenateReferencesAsByteArray(references);
// 5. Generate ContentTimestamp using the concatenated references
switch (timestampType) {
case ALL_DATA_OBJECTS_TIMESTAMP:
case INDIVIDUAL_DATA_OBJECTS_TIMESTAMP:
return generateTimestampToken(timestampType, externalParameters, concatenatedReferences);
default:
throw new DSSException("Incompatible timestamp type");
}
}
示例9: validateSignatureImpl
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* Validate an instance of {@link SignatureImpl}, which is in turn based on underlying Apache XML Security
* <code>XMLSignature</code> instance.
*
* @param sigImpl the signature implementation object to validate
* @throws ValidationException thrown if the signature is not valid with respect to the profile
*/
protected void validateSignatureImpl(SignatureImpl sigImpl) throws ValidationException {
if (sigImpl.getXMLSignature() == null) {
log.error("SignatureImpl did not contain the an Apache XMLSignature child");
throw new ValidationException("Apache XMLSignature does not exist on SignatureImpl");
}
XMLSignature apacheSig = sigImpl.getXMLSignature();
if (!(sigImpl.getParent() instanceof SignableSAMLObject)) {
log.error("Signature is not an immedidate child of a SignableSAMLObject");
throw new ValidationException("Signature is not an immediate child of a SignableSAMLObject.");
}
SignableSAMLObject signableObject = (SignableSAMLObject) sigImpl.getParent();
Reference ref = validateReference(apacheSig);
String uri = ref.getURI();
String id = signableObject.getSignatureReferenceID();
validateReferenceURI(uri, id);
validateTransforms(ref);
}
示例10: getSignatureEntries
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
private Set<ManifestEntry> getSignatureEntries(BDocSignature signature) {
Set<ManifestEntry> signatureEntries = new HashSet<>();
List<Reference> references = signature.getOrigin().getReferences();
for (Reference reference : references) {
if (reference.getType().equals("")) {
String mimeTypeString = null;
Node signatureNode = signature.getOrigin().getDssSignature().getSignatureElement();
Node node = DomUtils.getNode(signatureNode, "./ds:SignedInfo/ds:Reference[@URI=\"" + reference.getURI() + "\"]");
if (node != null) {
String referenceId = node.getAttributes().getNamedItem("Id").getNodeValue();
mimeTypeString = DomUtils.getValue(signatureNode,
"./ds:Object/xades:QualifyingProperties/xades:SignedProperties/" +
"xades:SignedDataObjectProperties/xades:DataObjectFormat" +
"[@ObjectReference=\"#" + referenceId + "\"]/xades:MimeType");
}
// TODO: mimeTypeString == null ? node == null?
String uri = getFileURI(reference);
signatureEntries.add(new ManifestEntry(uri, mimeTypeString));
}
}
return signatureEntries;
}
示例11: getDigestAlgorithm
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
/**
* Returns the digest algorithm identifier from the signature
*
* @return The algorithm identifier
* @throws SAMLException Thrown if the signature is missing
*/
public String getDigestAlgorithm()
throws SAMLException
{
if (isSigned()) {
SignedInfo si=sig.getSignedInfo();
if (si.getLength()==1) {
Reference ref;
try {
ref = si.item(0);
return ref.getMessageDigestAlgorithm().getAlgorithmURI();
}
catch (XMLSecurityException e) {
throw new InvalidCryptoException("SAMLSignedObject.getDigestAlgorithm() detected an XML security exception: " + e.getMessage(),e);
}
}
}
throw new InvalidCryptoException("SAMLSignedObject.getDigestAlgorithm() can't examine unsigned or improperly signed object");
}
示例12: testSigningVerifyingReference
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@org.junit.Test
public void testSigningVerifyingReference() throws Throwable {
Document doc = getOriginalDocument();
XMLSignature signature = signDocument(doc);
PublicKey pubKey = getPublicKey();
assertTrue(signature.checkSignatureValue(pubKey));
// Check the reference(s)
SignedInfo signedInfo = signature.getSignedInfo();
assertTrue(signedInfo.getLength() == 1);
Reference reference = signedInfo.item(0);
ReferenceData referenceData = reference.getReferenceData();
assertNotNull(referenceData);
assertTrue(referenceData instanceof ReferenceNodeSetData);
// Test the cached Element
Element referenceElement =
(Element)((ReferenceNodeSetData)referenceData).iterator().next();
assertNotNull(referenceElement);
assertTrue("root".equals(referenceElement.getLocalName()));
Element originalElement =
(Element) doc.getElementsByTagNameNS("http://ns.example.org/", "root").item(0);
assertNotNull(originalElement);
assertEquals(referenceElement, originalElement);
}
示例13: addPropSpecificTimeStampInput
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Override
protected void addPropSpecificTimeStampInput(
IndividualDataObjsTimeStampProperty prop,
TimeStampDigestInput digestInput,
PropertiesDataGenerationContext ctx) throws CannotAddDataToDigestInputException
{
Collection<DataObjectDesc> targetDataObjs = prop.getTargetDataObjects();
Map<DataObjectDesc, Reference> refsMaps = ctx.getReferencesMappings();
for (DataObjectDesc dataObj : targetDataObjs)
{
Reference r = refsMaps.get(dataObj);
digestInput.addReference(r);
}
}
示例14: addPropSpecificTimeStampInput
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Override
protected void addPropSpecificTimeStampInput(
AllDataObjsTimeStampProperty prop,
TimeStampDigestInput digestInput,
PropertiesDataGenerationContext ctx) throws CannotAddDataToDigestInputException
{
List<Reference> refs = ctx.getReferences();
for (Reference r : refs)
{
digestInput.addReference(r);
}
}
示例15: generatePropertyData
import org.apache.xml.security.signature.Reference; //导入依赖的package包/类
@Override
public PropertyDataObject generatePropertyData(
CommitmentTypeProperty prop,
PropertiesDataGenerationContext ctx)
{
CommitmentTypeData commTypeData = new CommitmentTypeData(
prop.getUri(),
prop.getDescription());
/* One ObjectReference element refers to one ds:Reference element of the
* ds:SignedInfo corresponding with one data object qualified by this
* property. If some but not all the signed data objects share the same
* commitment, one ObjectReference element MUST appear for each one of
* them. However, if all the signed data objects share the same commitment,
* the AllSignedDataObjects empty element MUST be present.
*/
Collection<DataObjectDesc> targets = prop.getTargetDataObjects();
Map<DataObjectDesc, Reference> referencesMappings = ctx.getReferencesMappings();
for (DataObjectDesc obj : targets)
{
// The ObjectReference refers the Reference element. This assumes
// that the QualifyingProperties are in the signature's document.
commTypeData.addObjReferences('#' + referencesMappings.get(obj).getId());
}
commTypeData.setQualifiers(prop.getQualifiers());
return commTypeData;
}