List of usage examples for javax.xml.bind JAXBElement getName
public QName getName()
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Foo.class, ObjectFactory.class); StringReader xml = new StringReader("<foo><C>Hello World</C></foo>"); Unmarshaller unmarshaller = jc.createUnmarshaller(); Foo foo = (Foo) unmarshaller.unmarshal(xml); JAXBElement<?> aOrBOrCOrD = foo.aOrBOrCOrD; System.out.println(aOrBOrCOrD.getName().getLocalPart()); System.out.println(aOrBOrCOrD.getDeclaredType()); System.out.println(aOrBOrCOrD.getValue()); }
From source file:Main.java
public static <BoundType> boolean isJAXBElement(Class<BoundType> declaredType, QName name, Class scope, Object value) {//from w ww . j av a 2 s . c o m if (value == null) { return false; } else if (value instanceof JAXBElement) { final JAXBElement<?> element = (JAXBElement<?>) value; return element.getName().equals(name) && declaredType.isAssignableFrom(element.getDeclaredType()); } else { return false; } }
From source file:Main.java
public static String readComplexProperty(String name, List<Object> objects, String methodName) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart())) { return callMethod(element.getValue(), methodName); }//from w w w .j a v a 2s. c om } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readLinkType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof LinkType) { LinkType textType = (LinkType) element.getValue(); return textType.getHref(); }//from ww w .jav a2 s . c o m } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static XMLGregorianCalendar readDateTimeType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof DateTimeType) { DateTimeType dateTimeType = (DateTimeType) element.getValue(); return dateTimeType.getValue(); }//from w w w . j a va2 s.com } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readProperty(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart())) { return String.valueOf(element.getValue()); }/*from www .j a v a2 s . c o m*/ } else if (o instanceof ElementNSImpl) { ElementNSImpl element = (ElementNSImpl) o; if (name.equals(element.getNodeName())) { return element.getFirstChild().getNodeValue(); } } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readTextType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof TextType) { StringBuffer result = new StringBuffer(); TextType textType = (TextType) element.getValue(); for (Object content : textType.getContent()) { result.append(content); }/* w w w . ja v a2 s. c o m*/ return result.toString(); } } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readContentType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof ContentType) { StringBuffer result = new StringBuffer(); ContentType contentType = (ContentType) element.getValue(); for (Object content : contentType.getContent()) { result.append(content); }//from w ww.j a v a 2 s .c o m return result.toString(); } } } return null; }
From source file:be.e_contract.dssp.client.SignResponseVerifier.java
/** * Checks the signature on the SignResponse browser POST message. * /*from www.ja va2s . c om*/ * @param signResponseMessage * the SignResponse message. * @param session * the session object. * @return the verification result object. * @throws JAXBException * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws MarshalException * @throws XMLSignatureException * @throws Base64DecodingException * @throws UserCancelException * @throws ClientRuntimeException * @throws SubjectNotAuthorizedException */ public static SignResponseVerificationResult checkSignResponse(String signResponseMessage, DigitalSignatureServiceSession session) throws JAXBException, ParserConfigurationException, SAXException, IOException, MarshalException, XMLSignatureException, Base64DecodingException, UserCancelException, ClientRuntimeException, SubjectNotAuthorizedException { if (null == session) { throw new IllegalArgumentException("missing session"); } byte[] decodedSignResponseMessage; try { decodedSignResponseMessage = Base64.decode(signResponseMessage); } catch (Base64DecodingException e) { throw new SecurityException("no Base64"); } // JAXB parsing JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class, be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); SignResponse signResponse; try { signResponse = (SignResponse) unmarshaller .unmarshal(new ByteArrayInputStream(decodedSignResponseMessage)); } catch (UnmarshalException e) { throw new SecurityException("no valid SignResponse XML"); } // DOM parsing DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream signResponseInputStream = new ByteArrayInputStream(decodedSignResponseMessage); Document signResponseDocument = documentBuilder.parse(signResponseInputStream); // signature verification NodeList signatureNodeList = signResponseDocument .getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature"); if (signatureNodeList.getLength() != 1) { throw new SecurityException("requires 1 ds:Signature element"); } Element signatureElement = (Element) signatureNodeList.item(0); SecurityTokenKeySelector keySelector = new SecurityTokenKeySelector(session.getKey()); DOMValidateContext domValidateContext = new DOMValidateContext(keySelector, signatureElement); XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance("DOM"); XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext); boolean validSignature = xmlSignature.validate(domValidateContext); if (false == validSignature) { throw new SecurityException("invalid ds:Signature"); } // verify content String responseId = null; RelatesToType relatesTo = null; AttributedURIType to = null; TimestampType timestamp = null; String signerIdentity = null; AnyType optionalOutputs = signResponse.getOptionalOutputs(); List<Object> optionalOutputsList = optionalOutputs.getAny(); for (Object optionalOutputObject : optionalOutputsList) { LOG.debug("optional output object type: " + optionalOutputObject.getClass().getName()); if (optionalOutputObject instanceof JAXBElement) { JAXBElement optionalOutputElement = (JAXBElement) optionalOutputObject; LOG.debug("optional output name: " + optionalOutputElement.getName()); LOG.debug("optional output value type: " + optionalOutputElement.getValue().getClass().getName()); if (RESPONSE_ID_QNAME.equals(optionalOutputElement.getName())) { responseId = (String) optionalOutputElement.getValue(); } else if (optionalOutputElement.getValue() instanceof RelatesToType) { relatesTo = (RelatesToType) optionalOutputElement.getValue(); } else if (TO_QNAME.equals(optionalOutputElement.getName())) { to = (AttributedURIType) optionalOutputElement.getValue(); } else if (optionalOutputElement.getValue() instanceof TimestampType) { timestamp = (TimestampType) optionalOutputElement.getValue(); } else if (optionalOutputElement.getValue() instanceof NameIdentifierType) { NameIdentifierType nameIdentifier = (NameIdentifierType) optionalOutputElement.getValue(); signerIdentity = nameIdentifier.getValue(); } } } Result result = signResponse.getResult(); LOG.debug("result major: " + result.getResultMajor()); LOG.debug("result minor: " + result.getResultMinor()); if (DigitalSignatureServiceConstants.REQUESTER_ERROR_RESULT_MAJOR.equals(result.getResultMajor())) { if (DigitalSignatureServiceConstants.USER_CANCEL_RESULT_MINOR.equals(result.getResultMinor())) { throw new UserCancelException(); } if (DigitalSignatureServiceConstants.CLIENT_RUNTIME_RESULT_MINOR.equals(result.getResultMinor())) { throw new ClientRuntimeException(); } if (DigitalSignatureServiceConstants.SUBJECT_NOT_AUTHORIZED_RESULT_MINOR .equals(result.getResultMinor())) { throw new SubjectNotAuthorizedException(signerIdentity); } } if (false == DigitalSignatureServiceConstants.PENDING_RESULT_MAJOR.equals(result.getResultMajor())) { throw new SecurityException("invalid dss:ResultMajor"); } if (null == responseId) { throw new SecurityException("missing async:ResponseID"); } if (false == responseId.equals(session.getResponseId())) { throw new SecurityException("invalid async:ResponseID"); } if (null == relatesTo) { throw new SecurityException("missing wsa:RelatesTo"); } if (false == session.getInResponseTo().equals(relatesTo.getValue())) { throw new SecurityException("invalid wsa:RelatesTo"); } if (null == to) { throw new SecurityException("missing wsa:To"); } if (false == session.getDestination().equals(to.getValue())) { throw new SecurityException("invalid wsa:To"); } if (null == timestamp) { throw new SecurityException("missing wsu:Timestamp"); } AttributedDateTime expires = timestamp.getExpires(); if (null == expires) { throw new SecurityException("missing wsu:Timestamp/wsu:Expires"); } DateTime expiresDateTime = new DateTime(expires.getValue()); DateTime now = new DateTime(); if (now.isAfter(expiresDateTime)) { throw new SecurityException("wsu:Timestamp expired"); } session.setSignResponseVerified(true); SignResponseVerificationResult signResponseVerificationResult = new SignResponseVerificationResult( signerIdentity); return signResponseVerificationResult; }
From source file:com.evolveum.midpoint.schema.util.ValueDisplayUtil.java
public static String toStringValue(PrismPropertyValue propertyValue) { Object value = propertyValue.getValue(); if (value == null) { return null; } else if (value instanceof String) { return (String) value; } else if (value instanceof PolyString) { return ((PolyString) value).getOrig(); } else if (value instanceof ProtectedStringType) { return "(protected string)"; // todo i18n } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) { return value.toString(); } else if (value instanceof XMLGregorianCalendar) { return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString(); // todo fix } else if (value instanceof Date) { return ((Date) value).toLocaleString(); // todo fix } else if (value instanceof LoginEventType) { LoginEventType loginEventType = (LoginEventType) value; if (loginEventType.getTimestamp() != null) { return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString(); // todo fix } else {/*from ww w .j a va 2 s .c om*/ return ""; } } else if (value instanceof ApprovalSchemaType) { ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value; return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)"; } else if (value instanceof ConstructionType) { ConstructionType ct = (ConstructionType) value; Object resource = (ct.getResource() != null ? ct.getResource().getName() : (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null)); return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : ""); } else if (value instanceof Enum) { return value.toString(); } else if (value instanceof ResourceAttributeDefinitionType) { ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value; ItemPathType ref = radt.getRef(); String path; if (ref != null) { path = ref.getItemPath().toString(); } else { path = "(null)"; } StringBuilder sb = new StringBuilder(); MappingType mappingType = radt.getOutbound(); if (mappingType != null) { if (mappingType.getExpression() == null) { sb.append("Empty mapping for ").append(path); } else { sb.append(path).append(" = "); boolean first = true; for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) { if (first) { first = false; } else { sb.append(", "); } if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) { RawType raw = (RawType) evaluator.getValue(); try { XNode xnode = raw.serializeToXNode(); if (xnode instanceof PrimitiveXNode) { sb.append(((PrimitiveXNode) xnode).getStringValue()); } else { sb.append("(a complex value)"); } } catch (SchemaException e) { sb.append("(an invalid value)"); } } else { sb.append("(a complex expression)"); } } } if (mappingType.getStrength() != null) { sb.append(" (").append(mappingType.getStrength().value()).append(")"); } } else { sb.append("Empty mapping for ").append(path); } return sb.toString(); } else if (value instanceof QName) { QName qname = (QName) value; if (StringUtils.isNotEmpty(qname.getNamespaceURI())) { return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")"; } else { return qname.getLocalPart(); } } else { return "(a value of type " + value.getClass().getName() + ")"; // todo i18n } }