Marshal the assertion as a JSON object.

@param assertion the assertion to marshal
509689
public JSONObject marshal(final AccessAssertion assertion) {
        final JSONObject jsonObject = assertion.marshal();
        if (jsonObject.has(JSON_CLASS_NAME)) {
            throw new AssertionError("The toJson method in AccessAssertion: '" + assertion.getClass() +
                                             "' defined a JSON field " + JSON_CLASS_NAME +
                                             " which is a reserved keyword and is not permitted to be used " +
                                             "in toJSON method");
        }
        try {
            jsonObject.put(JSON_CLASS_NAME, assertion.getClass().getName());
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }

        return jsonObject;
    }
680671
protected final void validateAssertion(final Assertion assertion, final SAML2MessageContext context,
                                           final SignatureTrustEngine engine, final Decrypter decrypter) {

        validateIssueInstant(assertion.getIssueInstant());

        validateIssuer(assertion.getIssuer(), context);

        if (assertion.getSubject() != null) {
            validateSubject(assertion.getSubject(), context, decrypter);
        } else {
            throw new SAMAssertionSubjectException("Assertion subject cannot be null");
        }

        validateAssertionConditions(assertion.getConditions(), context);

        validateAuthenticationStatements(assertion.getAuthnStatements(), context);

        validateAssertionSignature(assertion.getSignature(), context, engine);

    }
75330
static
	public void marshal(Object object, Result result) throws JAXBException {
		Marshaller marshaller = createMarshaller();

		marshaller.marshal(object, result);
	}
1003785
protected void setAuthenticatingAuthority(Assertion assertion, Assertion proxiedAssertion) {
    if (proxiedAssertion.getIssuer() == null || proxiedAssertion.getIssuer().getValue() == null) {
      log.warn("No issuer element found in proxied assertion");
      return;
    }
    if (assertion.getAuthnStatements().isEmpty()) {
      log.warn("No AuthnStatement available is assertion to update - will not process");
      return;
    }
    AuthnStatement authnStatement = assertion.getAuthnStatements().get(0);
    if (authnStatement.getAuthnContext() == null) {
      log.warn("No AuthnContext found in assertion to update - will not process");
    }

    final XMLObjectBuilderFactory bf = XMLObjectProviderRegistrySupport.getBuilderFactory();

    SAMLObjectBuilder<AuthenticatingAuthority> aaBuilder = (SAMLObjectBuilder<AuthenticatingAuthority>) bf
      .<AuthenticatingAuthority> getBuilderOrThrow(AuthenticatingAuthority.DEFAULT_ELEMENT_NAME);

    AuthenticatingAuthority aa = aaBuilder.buildObject();
    aa.setURI(proxiedAssertion.getIssuer().getValue());

    authnStatement.getAuthnContext().getAuthenticatingAuthorities().add(aa);
    log.info("Updated Assertion with AuthenticatingAuthority ({})", aa.getURI());
  }
545559
public JSONBuilder serialize(Object value) {
        if (value == null) {
            _sb.append("null");
        } else {
            Class<?> t = value.getClass();
            if (t.isArray()) {
                _sb.append('[');
                boolean hasElements = false;
                for (int i = 0, ii = Array.getLength(value); i < ii; ++i) {
                    serialize(Array.get(value, i));
                    _sb.append(',');
                    hasElements = true;
                }
                if (hasElements) {
                    _sb.setCharAt(_sb.length()-1, ']');
                } else {
                    _sb.append(']');
                }
            } else if (Iterable.class.isAssignableFrom(t)) {
                _sb.append('[');
                boolean hasElements = false;
                for (Object object: (Iterable<?>)value) {
                    serialize(object);
                    _sb.append(',');
                    hasElements = true;
                }
                if (hasElements) {
                    _sb.setCharAt(_sb.length()-1, ']');
                } else {
                    _sb.append(']');
                }
            } else if (Number.class.isAssignableFrom(t) || Boolean.class.isAssignableFrom(t)) {
                _sb.append(value.toString());
            } else if (String.class == t) {
                quote((String)value);
            } else {
                quote(value.toString());
            }
        }
        return this;
    }
486574
def _assertion(self, matcher, value):
        
        # To support the syntax `any_of(subject) | should ...` we check if the
        # value to check is an Expectation object and if it is we use the descriptor
        # protocol to bind the value's assertion logic to this expectation.
        if isinstance(value, Expectation):
            assertion = value._assertion.__get__(self, Expectation)
            assertion(matcher, value.value)
        else:
            hc.assert_that(value, matcher)
643207
public WsFederationCredential createCredentialFromToken(final Assertion assertion) {
        val retrievedOn = ZonedDateTime.now(ZoneOffset.UTC);
        LOGGER.debug("Retrieved on [{}]", retrievedOn);
        val credential = new WsFederationCredential();
        credential.setRetrievedOn(retrievedOn);
        credential.setId(assertion.getID());
        credential.setIssuer(assertion.getIssuer());
        credential.setIssuedOn(ZonedDateTime.parse(assertion.getIssueInstant().toDateTimeISO().toString()));
        val conditions = assertion.getConditions();
        if (conditions != null) {
            credential.setNotBefore(ZonedDateTime.parse(conditions.getNotBefore().toDateTimeISO().toString()));
            credential.setNotOnOrAfter(ZonedDateTime.parse(conditions.getNotOnOrAfter().toDateTimeISO().toString()));
            if (!conditions.getAudienceRestrictionConditions().isEmpty()) {
                credential.setAudience(conditions.getAudienceRestrictionConditions().get(0).getAudiences().get(0).getUri());
            }
        }
        if (!assertion.getAuthenticationStatements().isEmpty()) {
            credential.setAuthenticationMethod(assertion.getAuthenticationStatements().get(0).getAuthenticationMethod());
        }
        //retrieve an attributes from the assertion
        val attributes = new HashMap<String, List<Object>>();
        assertion.getAttributeStatements().stream().flatMap(attributeStatement -> attributeStatement.getAttributes().stream()).forEach(item -> {
            LOGGER.debug("Processed attribute: [{}]", item.getAttributeName());
            final List<Object> itemList = item.getAttributeValues().stream()
                .map(xmlObject -> ((XSAny) xmlObject).getTextContent())
                .collect(Collectors.toList());
            if (!itemList.isEmpty()) {
                attributes.put(item.getAttributeName(), itemList);
            }
        });
        credential.setAttributes(attributes);
        LOGGER.debug("Credential: [{}]", credential);
        return credential;
    }
666862
@Override
    public void assertStatement(org.openrdf.model.Statement stmnt) {
	try {
	    if (currentContext==null) {
		manager.getConnection().add(stmnt);
	    } else {
		manager.getConnection().add(stmnt, currentContext);
	    }
	} catch (org.openrdf.repository.RepositoryException e) {
	}
    }
1228077
void writeObject(java.io.ObjectOutputStream out) throws IOException {
        // when using object serialization, write the json bytes
        byte[] bytes = toString().getBytes(StandardCharsets.UTF_8);
        out.writeInt(bytes.length);
        out.write(bytes);
    }
1352697
protected Assertion buildCasAssertion(final Authentication authentication,
                                          final Service service,
                                          final RegisteredService registeredService,
                                          final Map<String, List<Object>> attributesToCombine) {
        val attributes = registeredService.getAttributeReleasePolicy().getAttributes(authentication.getPrincipal(), service, registeredService);
        val principalId = registeredService.getUsernameAttributeProvider().resolveUsername(authentication.getPrincipal(), service, registeredService);
        val principal = new AttributePrincipalImpl(principalId, (Map) attributes);
        val authnAttrs = new LinkedHashMap<>(authentication.getAttributes());
        authnAttrs.putAll(attributesToCombine);
        return new AssertionImpl(principal, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
            null, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
            (Map) authnAttrs);
    }
678436
function AssertionException(type, message, id) {
        var _this = _super.call(this, message) || this;
        _this.type = type;
        _this.id = id;
        if (Error.captureStackTrace) {
            Error.captureStackTrace(_this, _this.constructor);
        }
        return _this;
    }
1193470
public String toJson(Map<?, ?> map) {
    StringWriter stringWriter = new StringWriter();
    try {
      toJson(map, stringWriter);
    } catch (IOException e) {
      throw new AssertionError(e); // No I/O writing to a Buffer.
    }
    return stringWriter.toString();
  }
564543
public static byte[] serialize(Object instance) throws JsonGenerationException,
            JsonMappingException, IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        mapper.writeValue(out, instance);
        return out.toByteArray();
    }
198171
public static void serializeAsStream(Object o, OutputStream s) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            Map<String, Object> config = new HashMap<String, Object>();
            config.put(JsonGenerator.PRETTY_PRINTING, true);
            JsonWriterFactory writerFactory = Json.createWriterFactory(config);
            JsonWriter streamWriter = writerFactory.createWriter(s);
            streamWriter.write(builtJsonObject);
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
655393
@Override
    public AssertionError newAssertionError(Description d, Representation representation) {
        AssertionError assertionError = getComparisonFailureInstance();
        if (assertionError != null) {
            return assertionError;
        }

        String message = String.format(EXPECTED_BUT_WAS_MESSAGE, getActual(), getExpected());
        return Failures.instance().failure(message);
    }
398165
public static EsriFeature FeatureFromJson(InputStream jsonInputStream) throws JsonParseException, IOException{
		JsonParser parser = jsonFactory.createJsonParser(jsonInputStream);
		return FeatureFromJson(parser);
	}
633661
void write(CallInfo callInfo, DataSetAssertion assertion) {
    Element rootNode = root(callInfo); 
    DataSource ds = assertion.getSource();
    write(rootNode, ds);
    Element saNode = createNode(rootNode, ASSERTION_TAG);
    List<MetaData.ColumnInfo> mdCols = ds.getMetaData().columns();
    write(saNode, 
        EXPECTED_TAG, 
        mdCols,
        assertion.data(DataSetAssertion.IteratorType.EXPECTED_DATA));
    if (! assertion.passed()) {
      Element errorsNode = createNode(saNode, ERRORS_TAG);
      write(errorsNode, 
          EXPECTED_TAG, 
          mdCols,
          assertion.data(DataSetAssertion.IteratorType.ERRORS_EXPECTED));
      write(errorsNode, 
          ACTUAL_TAG, 
          mdCols,
          assertion.data(DataSetAssertion.IteratorType.ERRORS_ACTUAL));
    }
    flush(rootNode);
  }