List of usage examples for org.joda.time.chrono ISOChronology getInstanceUTC
public static ISOChronology getInstanceUTC()
From source file:be.e_contract.dssp.client.PendingRequestFactory.java
License:Open Source License
/** * Creates the base64 encoded dss:PendingRequest element to be used for the * Browser POST phase./* w w w . j a va2s .c o m*/ * * <p> * The content of the parameter {@code authorizedSubjects} can be * constructed as follows. The {@code authorizedSubjects} parameter is a set * of regular expressions. Suppose you have a national registration number * that is allowed to sign, then you can construct the * {@code authorizedSubjects} as follows. * </p> * * <pre> * Set<String> authorizedSubjects = new HashSet<String>(); * String nrn = "1234"; * X500Principal x500Principal = new X500Principal("SERIALNUMBER=" + nrn); * String authorizedSubject = x500Principal.getName() + ",.*,C=BE"; * authorizedSubjects.add(authorizedSubject); * </pre> * * @param session * the session object. * @param destination * the destination URL within your web application. This is where * the DSS will return to. * @param language * the optional language * @param visibleSignatureConfiguration * the optional visible signature configuration. * @param returnSignerIdentity * indicates whether the DSS should return the signatory's * identity. * @param authorizedSubjects * the optional signatory subject DNs that are authorized to * sign. An authorized subject can be an regular expression. * @return * @see VisibleSignatureConfiguration */ public static String createPendingRequest(DigitalSignatureServiceSession session, String destination, String language, VisibleSignatureConfiguration visibleSignatureConfiguration, boolean returnSignerIdentity, Set<String> authorizedSubjects) { ObjectFactory asyncObjectFactory = new ObjectFactory(); be.e_contract.dssp.ws.jaxb.dss.ObjectFactory dssObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.ObjectFactory(); be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory wsaObjectFactory = new be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory(); be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory wsuObjectFactory = new be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory(); be.e_contract.dssp.ws.jaxb.dss.vs.ObjectFactory vsObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.vs.ObjectFactory(); be.e_contract.dssp.ws.jaxb.xacml.policy.ObjectFactory xacmlObjectFactory = new be.e_contract.dssp.ws.jaxb.xacml.policy.ObjectFactory(); PendingRequest pendingRequest = asyncObjectFactory.createPendingRequest(); pendingRequest.setProfile(DigitalSignatureServiceConstants.PROFILE); AnyType optionalInputs = dssObjectFactory.createAnyType(); pendingRequest.setOptionalInputs(optionalInputs); optionalInputs.getAny() .add(dssObjectFactory.createAdditionalProfile(DigitalSignatureServiceConstants.DSS_ASYNC_PROFILE)); optionalInputs.getAny().add(asyncObjectFactory.createResponseID(session.getResponseId())); if (null != language) { optionalInputs.getAny().add(dssObjectFactory.createLanguage(language)); } if (returnSignerIdentity) { optionalInputs.getAny().add(dssObjectFactory.createReturnSignerIdentity(null)); } AttributedURIType messageId = wsaObjectFactory.createAttributedURIType(); optionalInputs.getAny().add(wsaObjectFactory.createMessageID(messageId)); String requestId = "uuid:" + UUID.randomUUID().toString(); messageId.setValue(requestId); session.setInResponseTo(requestId); TimestampType timestamp = wsuObjectFactory.createTimestampType(); optionalInputs.getAny().add(wsuObjectFactory.createTimestamp(timestamp)); AttributedDateTime created = wsuObjectFactory.createAttributedDateTime(); timestamp.setCreated(created); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime() .withChronology(ISOChronology.getInstanceUTC()); DateTime createdDateTime = new DateTime(); created.setValue(dateTimeFormatter.print(createdDateTime)); AttributedDateTime expires = wsuObjectFactory.createAttributedDateTime(); timestamp.setExpires(expires); DateTime expiresDateTime = createdDateTime.plusMinutes(5); expires.setValue(dateTimeFormatter.print(expiresDateTime)); EndpointReferenceType replyTo = wsaObjectFactory.createEndpointReferenceType(); optionalInputs.getAny().add(wsaObjectFactory.createReplyTo(replyTo)); AttributedURIType address = wsaObjectFactory.createAttributedURIType(); replyTo.setAddress(address); address.setValue(destination); session.setDestination(destination); if (null != visibleSignatureConfiguration) { VisibleSignatureConfigurationType visSigConfig = vsObjectFactory .createVisibleSignatureConfigurationType(); optionalInputs.getAny().add(vsObjectFactory.createVisibleSignatureConfiguration(visSigConfig)); VisibleSignaturePolicyType visibleSignaturePolicy = VisibleSignaturePolicyType.DOCUMENT_SUBMISSION_POLICY; visSigConfig.setVisibleSignaturePolicy(visibleSignaturePolicy); VisibleSignatureItemsConfigurationType visibleSignatureItemsConfiguration = vsObjectFactory .createVisibleSignatureItemsConfigurationType(); visSigConfig.setVisibleSignatureItemsConfiguration(visibleSignatureItemsConfiguration); if (visibleSignatureConfiguration.getLocation() != null) { VisibleSignatureItemType locationVisibleSignatureItem = vsObjectFactory .createVisibleSignatureItemType(); visibleSignatureItemsConfiguration.getVisibleSignatureItem().add(locationVisibleSignatureItem); locationVisibleSignatureItem.setItemName(ItemNameEnum.SIGNATURE_PRODUCTION_PLACE); ItemValueStringType itemValue = vsObjectFactory.createItemValueStringType(); locationVisibleSignatureItem.setItemValue(itemValue); itemValue.setItemValue(visibleSignatureConfiguration.getLocation()); } if (visibleSignatureConfiguration.getRole() != null) { VisibleSignatureItemType locationVisibleSignatureItem = vsObjectFactory .createVisibleSignatureItemType(); visibleSignatureItemsConfiguration.getVisibleSignatureItem().add(locationVisibleSignatureItem); locationVisibleSignatureItem.setItemName(ItemNameEnum.SIGNATURE_REASON); ItemValueStringType itemValue = vsObjectFactory.createItemValueStringType(); locationVisibleSignatureItem.setItemValue(itemValue); itemValue.setItemValue(visibleSignatureConfiguration.getRole()); } if (visibleSignatureConfiguration.getSignerImageUri() != null) { PixelVisibleSignaturePositionType visibleSignaturePosition = vsObjectFactory .createPixelVisibleSignaturePositionType(); visSigConfig.setVisibleSignaturePosition(visibleSignaturePosition); visibleSignaturePosition.setPageNumber(BigInteger.valueOf(visibleSignatureConfiguration.getPage())); visibleSignaturePosition.setX(BigInteger.valueOf(visibleSignatureConfiguration.getX())); visibleSignaturePosition.setY(BigInteger.valueOf(visibleSignatureConfiguration.getY())); VisibleSignatureItemType visibleSignatureItem = vsObjectFactory.createVisibleSignatureItemType(); visibleSignatureItemsConfiguration.getVisibleSignatureItem().add(visibleSignatureItem); visibleSignatureItem.setItemName(ItemNameEnum.SIGNER_IMAGE); ItemValueURIType itemValue = vsObjectFactory.createItemValueURIType(); itemValue.setItemValue(visibleSignatureConfiguration.getSignerImageUri()); visibleSignatureItem.setItemValue(itemValue); } if (visibleSignatureConfiguration.getCustomText() != null) { VisibleSignatureItemType customTextVisibleSignatureItem = vsObjectFactory .createVisibleSignatureItemType(); visibleSignatureItemsConfiguration.getVisibleSignatureItem().add(customTextVisibleSignatureItem); customTextVisibleSignatureItem.setItemName(ItemNameEnum.CUSTOM_TEXT); ItemValueStringType itemValue = vsObjectFactory.createItemValueStringType(); customTextVisibleSignatureItem.setItemValue(itemValue); itemValue.setItemValue(visibleSignatureConfiguration.getCustomText()); } } if (null != authorizedSubjects) { PolicyType policy = xacmlObjectFactory.createPolicyType(); optionalInputs.getAny().add(xacmlObjectFactory.createPolicy(policy)); policy.setPolicyId("urn:" + UUID.randomUUID().toString()); policy.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides"); TargetType target = xacmlObjectFactory.createTargetType(); policy.setTarget(target); RuleType rule = xacmlObjectFactory.createRuleType(); policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); rule.setRuleId("whatever"); rule.setEffect(EffectType.PERMIT); TargetType ruleTarget = xacmlObjectFactory.createTargetType(); rule.setTarget(ruleTarget); SubjectsType subjects = xacmlObjectFactory.createSubjectsType(); ruleTarget.setSubjects(subjects); for (String authorizedSubject : authorizedSubjects) { SubjectType subject = xacmlObjectFactory.createSubjectType(); subjects.getSubject().add(subject); SubjectMatchType subjectMatch = xacmlObjectFactory.createSubjectMatchType(); subject.getSubjectMatch().add(subjectMatch); subjectMatch.setMatchId("urn:oasis:names:tc:xacml:2.0:function:x500Name-regexp-match"); AttributeValueType attributeValue = xacmlObjectFactory.createAttributeValueType(); subjectMatch.setAttributeValue(attributeValue); attributeValue.setDataType("http://www.w3.org/2001/XMLSchema#string"); attributeValue.getContent().add(authorizedSubject); SubjectAttributeDesignatorType subjectAttributeDesigator = xacmlObjectFactory .createSubjectAttributeDesignatorType(); subjectMatch.setSubjectAttributeDesignator(subjectAttributeDesigator); subjectAttributeDesigator.setAttributeId("urn:oasis:names:tc:xacml:1.0:subject:subject-id"); subjectAttributeDesigator.setDataType("urn:oasis:names:tc:xacml:1.0:data-type:x500Name"); } ResourcesType resources = xacmlObjectFactory.createResourcesType(); ruleTarget.setResources(resources); ResourceType resource = xacmlObjectFactory.createResourceType(); resources.getResource().add(resource); ResourceMatchType resourceMatch = xacmlObjectFactory.createResourceMatchType(); resource.getResourceMatch().add(resourceMatch); resourceMatch.setMatchId("urn:oasis:names:tc:xacml:1.0:function:anyURI-equal"); AttributeValueType resourceAttributeValue = xacmlObjectFactory.createAttributeValueType(); resourceMatch.setAttributeValue(resourceAttributeValue); resourceAttributeValue.setDataType("http://www.w3.org/2001/XMLSchema#anyURI"); resourceAttributeValue.getContent().add("urn:be:e-contract:dss"); AttributeDesignatorType resourceAttributeDesignator = xacmlObjectFactory .createAttributeDesignatorType(); resourceMatch.setResourceAttributeDesignator(resourceAttributeDesignator); resourceAttributeDesignator.setAttributeId("urn:oasis:names:tc:xacml:1.0:resource:resource-id"); resourceAttributeDesignator.setDataType("http://www.w3.org/2001/XMLSchema#anyURI"); ActionsType actions = xacmlObjectFactory.createActionsType(); ruleTarget.setActions(actions); ActionType action = xacmlObjectFactory.createActionType(); actions.getAction().add(action); ActionMatchType actionMatch = xacmlObjectFactory.createActionMatchType(); action.getActionMatch().add(actionMatch); actionMatch.setMatchId("urn:oasis:names:tc:xacml:1.0:function:string-equal"); AttributeValueType actionAttributeValue = xacmlObjectFactory.createAttributeValueType(); actionMatch.setAttributeValue(actionAttributeValue); actionAttributeValue.setDataType("http://www.w3.org/2001/XMLSchema#string"); actionAttributeValue.getContent().add("sign"); AttributeDesignatorType actionAttributeDesignator = xacmlObjectFactory.createAttributeDesignatorType(); actionMatch.setActionAttributeDesignator(actionAttributeDesignator); actionAttributeDesignator.setAttributeId("urn:oasis:names:tc:xacml:1.0:action:action-id"); actionAttributeDesignator.setDataType("http://www.w3.org/2001/XMLSchema#string"); } // marshall to DOM DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException("DOM error: " + e.getMessage(), e); } Document document = documentBuilder.newDocument(); try { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class, be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.dss.vs.ObjectFactory.class, be.e_contract.dssp.ws.jaxb.xacml.policy.ObjectFactory.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(pendingRequest, document); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } try { sign(document, session); } catch (Exception e) { throw new RuntimeException("error signing: " + e.getMessage(), e); } // marshall to base64 encoded TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException("JAXP config error: " + e.getMessage(), e); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { transformer.transform(new DOMSource(document), new StreamResult(outputStream)); } catch (TransformerException e) { throw new RuntimeException("JAXP error: " + e.getMessage(), e); } String encodedPendingRequest = Base64.encode(outputStream.toByteArray()); return encodedPendingRequest; }
From source file:be.fedict.eid.dss.model.bean.DocumentServiceBean.java
License:Open Source License
private boolean isExpired(DocumentEntity document) { return new DateTime(document.getExpiration(), ISOChronology.getInstanceUTC()).isBeforeNow(); }
From source file:be.fedict.eid.dss.model.bean.DocumentServiceBean.java
License:Open Source License
private DateTime getExpiration() { Integer documentStorageExpiration = this.configuration.getValue(ConfigProperty.DOCUMENT_STORAGE_EXPIRATION, Integer.class); if (null == documentStorageExpiration || documentStorageExpiration <= 0) { throw new RuntimeException("Invalid document storage validity: " + documentStorageExpiration); }/*from ww w . j a v a 2s . com*/ return new DateTime().plus(documentStorageExpiration * 60 * 1000) .toDateTime(ISOChronology.getInstanceUTC()); }
From source file:be.fedict.eid.idp.common.saml2.Saml2Util.java
License:Open Source License
@SuppressWarnings("unchecked") private static Attribute getAttribute(String attributeName, GregorianCalendar attributeValue) { Attribute attribute = buildXMLObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attributeName);//w w w . j a v a2s . com XMLObjectBuilder<XSDateTime> builder = Configuration.getBuilderFactory().getBuilder(XSDateTime.TYPE_NAME); XSDateTime xmlAttributeValue = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSDateTime.TYPE_NAME); // convert to Zulu timezone int day = attributeValue.get(Calendar.DAY_OF_MONTH); int month = attributeValue.get(Calendar.MONTH); int year = attributeValue.get(Calendar.YEAR); LOG.debug("day: " + day + " month: " + month + " year: " + year); DateTime zulu = new DateTime(year, month + 1, day, 0, 0, 0, 0, ISOChronology.getInstanceUTC()); xmlAttributeValue.setValue(zulu); attribute.getAttributeValues().add(xmlAttributeValue); LOG.debug("XmlAttributeValue: " + xmlAttributeValue.getValue()); return attribute; }
From source file:be.fedict.eid.idp.common.saml2.Saml2Util.java
License:Open Source License
private static void processAttribute(Attribute attribute, Map<String, Object> attributeMap) throws AssertionValidationException { String attributeName = attribute.getName(); if (attribute.getAttributeValues().get(0) instanceof XSString) { XSString attributeValue = (XSString) attribute.getAttributeValues().get(0); attributeMap.put(attributeName, attributeValue.getValue()); } else if (attribute.getAttributeValues().get(0) instanceof XSInteger) { XSInteger attributeValue = (XSInteger) attribute.getAttributeValues().get(0); attributeMap.put(attributeName, attributeValue.getValue()); } else if (attribute.getAttributeValues().get(0) instanceof XSDateTime) { XSDateTime attributeValue = (XSDateTime) attribute.getAttributeValues().get(0); attributeMap.put(attributeName, attributeValue.getValue().toDateTime(ISOChronology.getInstanceUTC())); } else if (attribute.getAttributeValues().get(0) instanceof XSBase64Binary) { XSBase64Binary attributeValue = (XSBase64Binary) attribute.getAttributeValues().get(0); attributeMap.put(attributeName, Base64.decode(attributeValue.getValue())); } else {//ww w . j a v a 2s .c om throw new AssertionValidationException("Unsupported attribute of " + "type: " + attribute.getAttributeValues().get(0).getClass().getName()); } }
From source file:ch.icclab.cyclops.model.ceilometerMeasurements.AbstractOpenStackCeilometerUsage.java
License:Open Source License
/** * Will compute number of milliseconds from epoch to startDate * * @param time as string//from w w w . j a v a2s. c om * @return milliseconds since epoch */ public static long getMilisForTime(String time) { // first we have to get rid of 'T', as we need just T String isoFormat = time.replace("'", ""); // then we have to create proper formatter DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS") .withLocale(Locale.ROOT).withChronology(ISOChronology.getInstanceUTC()); // and now parse it DateTime dt = formatter.parseDateTime(isoFormat); return dt.getMillis(); }
From source file:ch.icclab.cyclops.model.UsageData.java
License:Open Source License
/** * Will compute number of milliseconds from epoch to startDate * * @param time as string/* w w w . j a va 2s .com*/ * @return milliseconds since epoch */ public static long getMilisForTime(String time) { // first we have to get rid of 'T', as we need just T String isoFormat = time.replace("'", ""); // then we have to create proper formatter DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withLocale(Locale.ROOT) .withChronology(ISOChronology.getInstanceUTC()); // and now parse it DateTime dt = formatter.parseDateTime(isoFormat); return dt.getMillis(); }
From source file:ch.icclab.cyclops.services.iaas.cloudstack.util.Time.java
License:Open Source License
/** * This method computes the date of String time (with support for 'T' and time zones) * * @param full//ww w . j a v a 2s .c o m * @return UTC DateTime object */ public static DateTime getDateForTime(String full) { String day = (full.contains("T")) ? full.substring(0, full.indexOf("T")) : full; // convert it to time object DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd").withLocale(Locale.ROOT) .withChronology(ISOChronology.getInstanceUTC()); return formatter.parseDateTime(day); }
From source file:ch.icclab.cyclops.services.iaas.cloudstack.util.Time.java
License:Open Source License
/** * Normalise date in string format/* w ww . ja v a2 s . c o m*/ * * @param original string * @return normalised string */ public static String normaliseString(String original) { try { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").withLocale(Locale.ROOT) .withChronology(ISOChronology.getInstanceUTC()); // and now parse it DateTime dt = formatter.parseDateTime(original); return dt.toString(); } catch (Exception ignored) { return original; } }
From source file:ch.icclab.cyclops.usecases.tnova.model.RevenueSharingEntry.java
License:Open Source License
/** * Will compute number of milliseconds from epoch to startDate * * @param time as string// w w w. j a v a 2 s. c o m * @return milliseconds since epoch */ public static long getMillisForTime(String time) { // first we have to get rid of 'T', as we need just T String isoFormat = time.replace("'", ""); // then we have to create proper formatter DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withLocale(Locale.ROOT) .withChronology(ISOChronology.getInstanceUTC()); // and now parse it DateTime dt = formatter.parseDateTime(isoFormat); return dt.getMillis(); }