List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:org.aselect.server.request.handler.xsaml20.idp.Xsaml20_Metadata_handler.java
License:Open Source License
/** * Create Metadata entries for IdP// w ww. ja va 2s .c om * @param the remoteID * The remote identity for whom to create the metadata. * with entityID is redirect_url from aselect.xml * @return the xml metadata string * @throws ASelectException * the a select exception * (non-Javadoc) * @see org.aselect.server.request.handler.xsaml20.Saml20_Metadata#createMetaDataXML() */ @Override // protected String createMetaDataXML(String sLocalIssuer) protected String createMetaDataXML(String sRemoteID) throws ASelectException { String sMethod = "createMetaDataXML"; String xmlMDRequest = null; DateTime tStamp = new DateTime(); _systemLogger.log(Level.INFO, MODULE, sMethod, "Starting to build metadata"); // Create the EntityDescriptor SAMLObjectBuilder<EntityDescriptor> entityDescriptorBuilder = (SAMLObjectBuilder<EntityDescriptor>) _oBuilderFactory .getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME); EntityDescriptor entityDescriptor = entityDescriptorBuilder.buildObject(); // optionally we could get another entityID from application section in aselect.xml based on remoteID // but we don't use sRemoteID just yet // entityDescriptor.setEntityID((sRemoteID != null)? sRemoteID: getEntityIdIdp()); // RH, 20110111, o entityDescriptor.setEntityID(getEntityIdIdp()); // RH, 20110111, n entityDescriptor.setID(SamlTools.generateIdentifier(_systemLogger, MODULE)); if (getValidUntil() != null) entityDescriptor.setValidUntil(tStamp.plus(getValidUntil().longValue())); if (getCacheDuration() != null) entityDescriptor.setCacheDuration(getCacheDuration()); // Create the IDPSSODescriptor SAMLObjectBuilder<IDPSSODescriptor> ssoDescriptorBuilder = (SAMLObjectBuilder<IDPSSODescriptor>) _oBuilderFactory .getBuilder(IDPSSODescriptor.DEFAULT_ELEMENT_NAME); IDPSSODescriptor ssoDescriptor = ssoDescriptorBuilder.buildObject(); // Create the SingleSignOnService if (getSingleSignOnServiceTarget() != null) { SAMLObjectBuilder<SingleSignOnService> ssoServiceBuilder = (SAMLObjectBuilder<SingleSignOnService>) _oBuilderFactory .getBuilder(SingleSignOnService.DEFAULT_ELEMENT_NAME); SingleSignOnService ssoService = ssoServiceBuilder.buildObject(); ssoService.setBinding(singleSignOnServiceBindingConstantREDIRECT); ssoService.setLocation(getIdpSsoUrl() + getSingleSignOnServiceTarget()); ssoDescriptor.getSingleSignOnServices().add(ssoService); // RM_47_01 // add HTTP-POST binding on same handler SingleSignOnService ssoServicePOST = ssoServiceBuilder.buildObject(); ssoServicePOST.setBinding(singleSignOnServiceBindingConstantPOST); ssoServicePOST.setLocation(getIdpSsoUrl() + getSingleSignOnServiceTarget()); ssoDescriptor.getSingleSignOnServices().add(ssoServicePOST); } // Create the ArtifactResolutionService if (getArtifactResolverTarget() != null) { SAMLObjectBuilder<ArtifactResolutionService> artResolutionSeviceBuilder = (SAMLObjectBuilder<ArtifactResolutionService>) _oBuilderFactory .getBuilder(ArtifactResolutionService.DEFAULT_ELEMENT_NAME); ArtifactResolutionService artResolutionService = artResolutionSeviceBuilder.buildObject(); artResolutionService.setBinding(artifactResolutionServiceBindingConstantSOAP); artResolutionService.setLocation(getIdpArtifactResolverUrl() + getArtifactResolverTarget()); artResolutionService.setIsDefault(true); artResolutionService.setIndex(0); ssoDescriptor.getArtifactResolutionServices().add(artResolutionService); } // Create the SingleLogoutService HTTP if (getIdpSloHttpLocation() != null) { SAMLObjectBuilder<SingleLogoutService> sloHttpServiceBuilder = (SAMLObjectBuilder<SingleLogoutService>) _oBuilderFactory .getBuilder(SingleLogoutService.DEFAULT_ELEMENT_NAME); SingleLogoutService sloHttpService = sloHttpServiceBuilder.buildObject(); sloHttpService.setBinding(singleLogoutServiceBindingConstantREDIRECT); sloHttpService.setLocation(getIdpSloHttpRequestUrl() + getIdpSloHttpLocation()); if (getIdpSloHttpResponse() != null) sloHttpService.setResponseLocation(getIdpSloHttpResponseUrl() + getIdpSloHttpResponse()); ssoDescriptor.getSingleLogoutServices().add(sloHttpService); } // Create the SingleLogoutService SOAP if (getIdpSloSoapLocation() != null) { SAMLObjectBuilder<SingleLogoutService> sloSoaperviceBuilder = (SAMLObjectBuilder<SingleLogoutService>) _oBuilderFactory .getBuilder(SingleLogoutService.DEFAULT_ELEMENT_NAME); SingleLogoutService sloSoapService = sloSoaperviceBuilder.buildObject(); sloSoapService.setBinding(singleLogoutServiceBindingConstantSOAP); sloSoapService.setLocation(getIdpSloSoapRequestUrl() + getIdpSloSoapLocation()); if (getIdpSloSoapResponse() != null) sloSoapService.setResponseLocation(getIdpSloSoapResponseUrl() + getIdpSloSoapResponse()); ssoDescriptor.getSingleLogoutServices().add(sloSoapService); } // Create the PDPDescriptor> SAMLObjectBuilder<PDPDescriptor> pdpDescriptorBuilder = (SAMLObjectBuilder<PDPDescriptor>) _oBuilderFactory .getBuilder(PDPDescriptor.DEFAULT_ELEMENT_NAME); PDPDescriptor pdpDescriptor = pdpDescriptorBuilder.buildObject(); // Create the AuthDecisionQuery target if (getIdpSSSoapLocation() != null) { SAMLObjectBuilder<AuthzService> adqSoaperviceBuilder = (SAMLObjectBuilder<AuthzService>) _oBuilderFactory .getBuilder(AuthzService.DEFAULT_ELEMENT_NAME); AuthzService adqSoapService = adqSoaperviceBuilder.buildObject(); adqSoapService.setBinding(authzServiceBindingConstantSOAP); adqSoapService.setLocation(getIdpSyncUrl() + getIdpSSSoapLocation()); pdpDescriptor.getAuthzServices().add(adqSoapService); } // Create final EntityDescriptor ssoDescriptor.setWantAuthnRequestsSigned(true); // ssoDescriptor.getKeyDescriptors().add(keyDescriptor); ssoDescriptor.getKeyDescriptors().add(createKeyDescriptor(getSigningCertificate())); ssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); entityDescriptor.getRoleDescriptors().add(ssoDescriptor); pdpDescriptor.getKeyDescriptors().add(createKeyDescriptor(getSigningCertificate())); pdpDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); entityDescriptor.getRoleDescriptors().add(pdpDescriptor); entityDescriptor = (EntityDescriptor) SamlTools.signSamlObject(entityDescriptor); _systemLogger.log(Level.INFO, MODULE, sMethod, "Just built the entityDescriptor"); // Marshall to the Node MarshallerFactory factory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = factory.getMarshaller(entityDescriptor); Node node = null; try { node = marshaller.marshall(entityDescriptor); _systemLogger.log(Level.INFO, MODULE, sMethod, xmlMDRequest); } catch (MarshallingException e) { _systemLogger.log(Level.SEVERE, MODULE, sMethod, e.getMessage(), e); _systemLogger.log(Level.WARNING, MODULE, sMethod, "Could not marshall metadata", e); throw new ASelectException(Errors.ERROR_ASELECT_INIT_ERROR, e); } _systemLogger.log(Level.INFO, MODULE, sMethod, "Just marshalled into metadata node"); xmlMDRequest = XMLHelper.nodeToString(node); _systemLogger.log(Level.INFO, MODULE, sMethod, "xmlMDRequest: " + xmlMDRequest); return xmlMDRequest; }
From source file:org.aselect.server.request.handler.xsaml20.SamlTools.java
License:Open Source License
/** * Set OpenSAML2 library Conditions object for timeRestrictions NotBefore and NotOnOrAfter. * //from w ww . jav a2 s.c om * @param obj * The object to which conditions are to be added * @param refInstant * Reference moment in time * @param maxNotBefore * the max not before * @param maxNotOnOrAfter * the max not on or after * @return valid Object with conditions (if not all timeRestrictions were null) otherwise return same object * unmodified * @throws ValidationException * Thrown if an error occurs while placing conditions * @throws ASelectException */ public static SAMLObject setValidityInterval(SAMLObject obj, DateTime refInstant, Long maxNotBefore, Long maxNotOnOrAfter) throws ASelectException { String sMethod = "setValidityInterval"; ASelectSystemLogger _systemLogger = ASelectSystemLogger.getHandle(); _systemLogger.log(Level.INFO, MODULE, sMethod, "obj->" + obj + ", refInstant->" + refInstant + ", maxNotBefore->" + maxNotBefore + ", maxNotOnOrAfter->" + maxNotOnOrAfter); // Still think this is a bit clumsy, maybe implement some sort of // (command) pattern here or use generics if (obj instanceof Assertion) { Conditions conditions = ((Assertion) obj).getConditions(); if (maxNotBefore != null || maxNotOnOrAfter != null) { XMLObjectBuilderFactory oBuilderFactory = org.opensaml.xml.Configuration.getBuilderFactory(); SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) oBuilderFactory .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); if (maxNotBefore != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } if (conditions != null) { ((Assertion) obj).setConditions(conditions); _systemLogger.log(Level.INFO, MODULE, sMethod, "Conditions set on Assertion->" + obj); } } else // not instanceof Assertion if (obj instanceof AuthnRequest) { Conditions conditions = ((AuthnRequest) obj).getConditions(); if (maxNotBefore != null || maxNotOnOrAfter != null) { XMLObjectBuilderFactory oBuilderFactory = org.opensaml.xml.Configuration.getBuilderFactory(); SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) oBuilderFactory .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); if (maxNotBefore != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } if (conditions != null) { ((AuthnRequest) obj).setConditions(conditions); _systemLogger.log(Level.INFO, MODULE, sMethod, "Conditions set on AuthnRequest->" + obj); } } else // not instanceof AuthnRequest if (obj instanceof SubjectConfirmationData) { if (maxNotBefore != null) { ((SubjectConfirmationData) obj).setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { ((SubjectConfirmationData) obj).setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } else // not instanceof SubjectConfirmationData if (obj instanceof LogoutRequest) { if (maxNotOnOrAfter != null) { ((LogoutRequest) obj).setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } // not instanceof LogoutRequest return obj; }
From source file:org.aselect.server.request.handler.xsaml20.sp.Xsaml20_Metadata_handler.java
License:Open Source License
/** * Create Metadata entries for SP//from ww w . j ava2s . com * @param the remoteID * The remote identity for whom to create the metadata. If null a default metadata xml will be created * with entityID is redirect_url from aselect.xml * @return the xml metadata string * @throws ASelectException * the a select exception * (non-Javadoc) * @see org.aselect.server.request.handler.xsaml20.Saml20_Metadata#createMetaDataXML() */ @Override // protected String createMetaDataXML(String sLocalIssuer) protected String createMetaDataXML(String remoteID) throws ASelectException { String sMethod = "createMetaDataXML"; String xmlMDRequest = null; DateTime tStamp = new DateTime(); // RH, 20110113, sn boolean addkeyname = false; boolean addcertificate = false; boolean usesha256 = false; // RH, 20110113, en _systemLogger.log(Level.INFO, MODULE, sMethod, "Starting to build metadata"); // RH, 20110111, sn PartnerData partnerData = null; String sLocalIssuer = null; if (remoteID != null) { // find "id" in the partner's section partnerData = MetaDataManagerSp.getHandle().getPartnerDataEntry(remoteID); } if (partnerData != null) sLocalIssuer = partnerData.getLocalIssuer(); // RH, 20110111, en // RH, 20110113, sn _systemLogger.log(Level.INFO, MODULE, sMethod, "setting partnerdata"); if (partnerData != null) { addkeyname = Boolean.parseBoolean(partnerData.getMetadata4partner().getAddkeyname()); addcertificate = Boolean.parseBoolean(partnerData.getMetadata4partner().getAddcertificate()); String specialsettings = partnerData.getMetadata4partner().getSpecialsettings(); usesha256 = specialsettings != null && specialsettings.toLowerCase().contains("sha256"); } // Create the EntityDescriptor SAMLObjectBuilder<EntityDescriptor> entityDescriptorBuilder = (SAMLObjectBuilder<EntityDescriptor>) _oBuilderFactory .getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME); EntityDescriptor entityDescriptor = entityDescriptorBuilder.buildObject(); // EntityID can be overruled by the caller entityDescriptor.setEntityID((sLocalIssuer != null) ? sLocalIssuer : getEntityIdIdp()); entityDescriptor.setID(SamlTools.generateIdentifier(_systemLogger, MODULE)); if (getValidUntil() != null) entityDescriptor.setValidUntil(tStamp.plus(getValidUntil().longValue())); if (getCacheDuration() != null) entityDescriptor.setCacheDuration(getCacheDuration()); // RH, 20140320, sn if (partnerData != null && partnerData.getMetadata4partner().getNamespaceInfo().size() > 0) { // Get namespaceinfo + additional attributes to publish from partnerdata Enumeration<NamespaceInfo> eHandler = partnerData.getMetadata4partner().getNamespaceInfo().elements(); while (eHandler.hasMoreElements()) { NamespaceInfo nsi = eHandler.nextElement(); entityDescriptor.addNamespace(new Namespace(nsi.getUri(), nsi.getPrefix())); Hashtable<String, String> atts = nsi.getAttributes(); Enumeration<String> attenum = atts.keys(); while (attenum.hasMoreElements()) { String localp = attenum.nextElement(); entityDescriptor.getUnknownAttributes().put(new QName(nsi.getUri(), localp, nsi.getPrefix()), atts.get(localp)); } } } // RH, 20140320, en // Create the KeyDescriptor SAMLObjectBuilder<KeyDescriptor> keyDescriptorBuilder = (SAMLObjectBuilder<KeyDescriptor>) _oBuilderFactory .getBuilder(KeyDescriptor.DEFAULT_ELEMENT_NAME); KeyDescriptor keyDescriptor = keyDescriptorBuilder.buildObject(); keyDescriptor.setUse(org.opensaml.xml.security.credential.UsageType.SIGNING); XMLSignatureBuilder<KeyInfo> keyInfoBuilder = (XMLSignatureBuilder<KeyInfo>) _oBuilderFactory .getBuilder(KeyInfo.DEFAULT_ELEMENT_NAME); KeyInfo keyInfo = keyInfoBuilder.buildObject(); X509CertificateBuilder x509CertificateBuilder = (X509CertificateBuilder) _oBuilderFactory .getBuilder(X509Certificate.DEFAULT_ELEMENT_NAME); X509Certificate x509Certificate = x509CertificateBuilder.buildObject(); x509Certificate.setValue(getSigningCertificate()); X509DataBuilder x509DataBuilder = (X509DataBuilder) _oBuilderFactory .getBuilder(X509Data.DEFAULT_ELEMENT_NAME); X509Data x509Data = x509DataBuilder.buildObject(); x509Data.getX509Certificates().add(x509Certificate); keyInfo.getX509Datas().add(x509Data); if (addkeyname) { _systemLogger.log(Level.INFO, MODULE, sMethod, "Add keyname to keyinfo"); XMLSignatureBuilder<KeyName> keyNameBuilder = (XMLSignatureBuilder<KeyName>) _oBuilderFactory .getBuilder(KeyName.DEFAULT_ELEMENT_NAME); KeyName keyName = keyNameBuilder.buildObject(); keyName.setValue(_configManager.getDefaultCertId()); keyInfo.getKeyNames().add(keyName); } keyDescriptor.setKeyInfo(keyInfo); // Create the SPSSODescriptor SAMLObjectBuilder<SPSSODescriptor> ssoDescriptorBuilder = (SAMLObjectBuilder<SPSSODescriptor>) _oBuilderFactory .getBuilder(SPSSODescriptor.DEFAULT_ELEMENT_NAME); SPSSODescriptor ssoDescriptor = ssoDescriptorBuilder.buildObject(); // RH, 20110113, sn if (partnerData != null && partnerData.getMetadata4partner().getHandlers().size() > 0) { // Get handlers to publish from partnerdata _systemLogger.log(Level.INFO, MODULE, sMethod, "Using Parnerdata"); Enumeration<HandlerInfo> eHandler = partnerData.getMetadata4partner().getHandlers().elements(); while (eHandler.hasMoreElements()) { HandlerInfo hHandler = eHandler.nextElement(); if (AssertionConsumerService.DEFAULT_ELEMENT_LOCAL_NAME.equalsIgnoreCase(hHandler.getType())) { // Create the AssertionConsumerService // RH, 20121228, n, For assertionconsumer service we allow to define alternate location String forcedLocation = hHandler.getLocation(); // returns null if not set _systemLogger.log(Level.INFO, MODULE, sMethod, getAssertionConsumerTarget()); // if (getAssertionConsumerTarget() != null) { // RH, 20121228, o if ((getAssertionConsumerTarget() != null) || (forcedLocation != null)) { // RH, 20121228, n SAMLObjectBuilder<AssertionConsumerService> assResolutionSeviceBuilder = (SAMLObjectBuilder<AssertionConsumerService>) _oBuilderFactory .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME); AssertionConsumerService assResolutionService = assResolutionSeviceBuilder.buildObject(); if (SAMLConstants.SAML2_POST_BINDING_URI.equals(hHandler.getBinding())) { assResolutionService.setBinding(SAMLConstants.SAML2_POST_BINDING_URI); } else { assResolutionService.setBinding(assertionConsumerServiceBindingConstantARTIFACT); } if (forcedLocation != null) { // RH, 20121228, sn assResolutionService.setLocation(forcedLocation); } else { // RH, 20121228, en assResolutionService.setLocation(getRedirectURL() + getAssertionConsumerTarget()); } if (hHandler.getResponselocation() != null) { // RH, 20121228, sn assResolutionService.setResponseLocation(hHandler.getResponselocation()); } // RH, 20121228, en if (hHandler.getIsdefault() != null) { assResolutionService.setIsDefault(hHandler.getIsdefault().booleanValue()); } if (hHandler.getIndex() != null) { assResolutionService.setIndex(hHandler.getIndex().intValue()); } ssoDescriptor.getAssertionConsumerServices().add(assResolutionService); } } if (SingleLogoutService.DEFAULT_ELEMENT_LOCAL_NAME.equalsIgnoreCase(hHandler.getType())) { String sBInding = null; String sLocation = null; // RH, 20120703, n, For singlelogout service we allow to define alternate location String forcedLocation = hHandler.getLocation(); // returns null if not set if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(hHandler.getBinding())) { // Create the SingleLogoutService HTTP, creates Request and Response _systemLogger.log(Level.INFO, MODULE, sMethod, getSpSloHttpLocation()); sBInding = SAMLConstants.SAML2_REDIRECT_BINDING_URI; sLocation = getSpSloHttpLocation(); } else if (SAMLConstants.SAML2_SOAP11_BINDING_URI.equals(hHandler.getBinding())) { // Create the SingleLogoutService SOAP, creates Request and Response _systemLogger.log(Level.INFO, MODULE, sMethod, getSpSloSoapLocation()); sBInding = SAMLConstants.SAML2_SOAP11_BINDING_URI; sLocation = getSpSloSoapLocation(); } if (sBInding != null && sLocation != null) { SAMLObjectBuilder<SingleLogoutService> sloHttpServiceBuilder = (SAMLObjectBuilder<SingleLogoutService>) _oBuilderFactory .getBuilder(SingleLogoutService.DEFAULT_ELEMENT_NAME); SingleLogoutService sloHttpService = sloHttpServiceBuilder.buildObject(); sloHttpService.setBinding(sBInding); if (forcedLocation != null) { // RH, 20120703, sn sloHttpService.setLocation(forcedLocation); ; } else // RH, 20120703, en sloHttpService.setLocation(getRedirectURL() + sLocation); if (hHandler.getResponselocation() != null) { sloHttpService.setResponseLocation(hHandler.getResponselocation()); } else { sloHttpService.setResponseLocation(getRedirectURL() + sLocation); } ssoDescriptor.getSingleLogoutServices().add(sloHttpService); } } } } else { // publish all handlers in config // RH, 20110113, en // Create the AssertionConsumerService _systemLogger.log(Level.INFO, MODULE, sMethod, getAssertionConsumerTarget()); if (getAssertionConsumerTarget() != null) { SAMLObjectBuilder<AssertionConsumerService> assResolutionSeviceBuilder = (SAMLObjectBuilder<AssertionConsumerService>) _oBuilderFactory .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME); AssertionConsumerService assResolutionService = assResolutionSeviceBuilder.buildObject(); assResolutionService.setBinding(assertionConsumerServiceBindingConstantARTIFACT); assResolutionService.setLocation(getRedirectURL() + getAssertionConsumerTarget()); assResolutionService.setIsDefault(true); assResolutionService.setIndex(0); ssoDescriptor.getAssertionConsumerServices().add(assResolutionService); } // Create the SingleLogoutService HTTP, creates Request and Response _systemLogger.log(Level.INFO, MODULE, sMethod, getSpSloHttpLocation()); if (getSpSloHttpLocation() != null) { SAMLObjectBuilder<SingleLogoutService> sloHttpServiceBuilder = (SAMLObjectBuilder<SingleLogoutService>) _oBuilderFactory .getBuilder(SingleLogoutService.DEFAULT_ELEMENT_NAME); SingleLogoutService sloHttpService = sloHttpServiceBuilder.buildObject(); sloHttpService.setBinding(singleLogoutServiceBindingConstantREDIRECT); sloHttpService.setLocation(getRedirectURL() + getSpSloHttpLocation()); if (getSpSloHttpResponse() != null) sloHttpService.setResponseLocation(getRedirectURL() + getSpSloHttpResponse()); ssoDescriptor.getSingleLogoutServices().add(sloHttpService); } // Create the SingleLogoutService SOAP, creates Request and Response _systemLogger.log(Level.INFO, MODULE, sMethod, getSpSloSoapLocation()); if (getSpSloSoapLocation() != null) { SAMLObjectBuilder<SingleLogoutService> sloSoaperviceBuilder = (SAMLObjectBuilder<SingleLogoutService>) _oBuilderFactory .getBuilder(SingleLogoutService.DEFAULT_ELEMENT_NAME); SingleLogoutService sloSoapService = sloSoaperviceBuilder.buildObject(); sloSoapService.setBinding(singleLogoutServiceBindingConstantSOAP); sloSoapService.setLocation(getRedirectURL() + getSpSloSoapLocation()); if (getSpSloSoapResponse() != null) sloSoapService.setResponseLocation(getRedirectURL() + getSpSloSoapResponse()); ssoDescriptor.getSingleLogoutServices().add(sloSoapService); } } // end publish all handlers in config // Publish Organization info if (partnerData != null && partnerData.getMetadata4partner().getMetaorgname() != null) { // If Organization present name is mandatory, so check name _systemLogger.log(Level.INFO, MODULE, sMethod, "Setting Organization info"); SAMLObjectBuilder<Organization> organizationBuilder = (SAMLObjectBuilder<Organization>) _oBuilderFactory .getBuilder(Organization.DEFAULT_ELEMENT_NAME); Organization organization = organizationBuilder.buildObject(); SAMLObjectBuilder<OrganizationName> organizationNameBuilder = (SAMLObjectBuilder<OrganizationName>) _oBuilderFactory .getBuilder(OrganizationName.DEFAULT_ELEMENT_NAME); OrganizationName organizationName = organizationNameBuilder.buildObject(); organizationName.setName(new LocalizedString(partnerData.getMetadata4partner().getMetaorgname(), partnerData.getMetadata4partner().getMetaorgnamelang())); organization.getOrganizationNames().add(organizationName); if (partnerData.getMetadata4partner().getMetaorgdisplname() != null) { SAMLObjectBuilder<OrganizationDisplayName> organizationDisplayNameBuilder = (SAMLObjectBuilder<OrganizationDisplayName>) _oBuilderFactory .getBuilder(OrganizationDisplayName.DEFAULT_ELEMENT_NAME); OrganizationDisplayName organizationDisplayName = organizationDisplayNameBuilder.buildObject(); organizationDisplayName .setName(new LocalizedString(partnerData.getMetadata4partner().getMetaorgdisplname(), partnerData.getMetadata4partner().getMetaorgdisplnamelang())); organization.getDisplayNames().add(organizationDisplayName); } if (partnerData.getMetadata4partner().getMetaorgurl() != null) { SAMLObjectBuilder<OrganizationURL> organizationURLBuilder = (SAMLObjectBuilder<OrganizationURL>) _oBuilderFactory .getBuilder(OrganizationURL.DEFAULT_ELEMENT_NAME); OrganizationURL organizationURL = organizationURLBuilder.buildObject(); organizationURL.setURL(new LocalizedString(partnerData.getMetadata4partner().getMetaorgurl(), partnerData.getMetadata4partner().getMetaorgurllang())); organization.getURLs().add(organizationURL); } entityDescriptor.setOrganization(organization); } // End Publish Organization info // publish ContactPerson info if (partnerData != null && partnerData.getMetadata4partner().getMetacontacttype() != null) { // If ContactPerson present ContactType is mandatory so check ContactType _systemLogger.log(Level.INFO, MODULE, sMethod, "Setting ContactPerson info"); SAMLObjectBuilder<ContactPerson> contactBuilder = (SAMLObjectBuilder<ContactPerson>) _oBuilderFactory .getBuilder(ContactPerson.DEFAULT_ELEMENT_NAME); ContactPerson contact = contactBuilder.buildObject(); if (ContactPersonTypeEnumeration.ADMINISTRATIVE.toString() .equalsIgnoreCase(partnerData.getMetadata4partner().getMetacontacttype())) { contact.setType(ContactPersonTypeEnumeration.ADMINISTRATIVE); } else if (ContactPersonTypeEnumeration.BILLING.toString() .equalsIgnoreCase(partnerData.getMetadata4partner().getMetacontacttype())) { contact.setType(ContactPersonTypeEnumeration.BILLING); } else if (ContactPersonTypeEnumeration.SUPPORT.toString() .equalsIgnoreCase(partnerData.getMetadata4partner().getMetacontacttype())) { contact.setType(ContactPersonTypeEnumeration.SUPPORT); } else if (ContactPersonTypeEnumeration.TECHNICAL.toString() .equalsIgnoreCase(partnerData.getMetadata4partner().getMetacontacttype())) { contact.setType(ContactPersonTypeEnumeration.TECHNICAL); } else { contact.setType(ContactPersonTypeEnumeration.OTHER); } if (partnerData.getMetadata4partner().getMetacontactname() != null) { SAMLObjectBuilder<GivenName> givenNameBuilder = (SAMLObjectBuilder<GivenName>) _oBuilderFactory .getBuilder(GivenName.DEFAULT_ELEMENT_NAME); GivenName givenName = givenNameBuilder.buildObject(); givenName.setName(partnerData.getMetadata4partner().getMetacontactname()); contact.setGivenName(givenName); } if (partnerData.getMetadata4partner().getMetacontactsurname() != null) { SAMLObjectBuilder<SurName> surNameBuilder = (SAMLObjectBuilder<SurName>) _oBuilderFactory .getBuilder(SurName.DEFAULT_ELEMENT_NAME); SurName surName = surNameBuilder.buildObject(); surName.setName(partnerData.getMetadata4partner().getMetacontactsurname()); contact.setSurName(surName); } if (partnerData.getMetadata4partner().getMetacontactemail() != null) { SAMLObjectBuilder<EmailAddress> emailBuilder = (SAMLObjectBuilder<EmailAddress>) _oBuilderFactory .getBuilder(EmailAddress.DEFAULT_ELEMENT_NAME); EmailAddress email = emailBuilder.buildObject(); email.setAddress(partnerData.getMetadata4partner().getMetacontactemail()); contact.getEmailAddresses().add(email); } if (partnerData.getMetadata4partner().getMetacontactephone() != null) { SAMLObjectBuilder<TelephoneNumber> phonelBuilder = (SAMLObjectBuilder<TelephoneNumber>) _oBuilderFactory .getBuilder(TelephoneNumber.DEFAULT_ELEMENT_NAME); TelephoneNumber phone = phonelBuilder.buildObject(); phone.setNumber(partnerData.getMetadata4partner().getMetacontactephone()); contact.getTelephoneNumbers().add(phone); } entityDescriptor.getContactPersons().add(contact); } // End publish ContactPerson info // Create final EntityDescriptor ssoDescriptor.setWantAssertionsSigned(true); ssoDescriptor.setAuthnRequestsSigned(true); // RH, 20120727, n. Actually we always sign the request. Just never told so ssoDescriptor.getKeyDescriptors().add(keyDescriptor); ssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS); entityDescriptor.getRoleDescriptors().add(ssoDescriptor); // entityDescriptor = (EntityDescriptor) SamlTools.signSamlObject(entityDescriptor); // RH, 20110113, o // RH, 20110113, sn _systemLogger.log(Level.INFO, MODULE, sMethod, "Signing entityDescriptor"); entityDescriptor = (EntityDescriptor) SamlTools.signSamlObject(entityDescriptor, usesha256 ? "sha256" : "sha1", addkeyname, addcertificate); // RH, 20110113, en // The Session Sync descriptor (PDPDescriptor?) would go here _systemLogger.log(Level.INFO, MODULE, sMethod, "entityDescriptor done"); // Marshall to the Node MarshallerFactory factory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = factory.getMarshaller(entityDescriptor); Node node = null; try { node = marshaller.marshall(entityDescriptor); } catch (MarshallingException e) { _systemLogger.log(Level.SEVERE, MODULE, sMethod, e.getMessage(), e); _systemLogger.log(Level.WARNING, MODULE, sMethod, "Could not marshall metadata", e); throw new ASelectException(Errors.ERROR_ASELECT_INIT_ERROR, e); } _systemLogger.log(Level.INFO, MODULE, sMethod, "Marshalling done"); xmlMDRequest = XMLHelper.nodeToString(node); _systemLogger.log(Level.INFO, MODULE, sMethod, "xmlMDRequest: " + xmlMDRequest); return xmlMDRequest; }
From source file:org.atlasapi.content.Broadcast.java
License:Apache License
public Broadcast(Id channelId, DateTime start, Duration duration, Boolean activelyPublished) { this(channelId, new Interval(start, start.plus(duration)), activelyPublished); }
From source file:org.atlasapi.content.Broadcast.java
License:Apache License
public Broadcast(Channel channel, DateTime start, Duration duration, Boolean activelyPublished) { this(Id.valueOf(channel.getId()), new Interval(start, start.plus(duration)), activelyPublished); }
From source file:org.atlasapi.media.entity.Broadcast.java
License:Apache License
public Broadcast(String broadcastOn, DateTime transmissionTime, Duration duration, Boolean activelyPublished) { this.broadcastOn = broadcastOn; this.transmissionTime = transmissionTime; this.transmissionEndTime = transmissionTime.plus(duration); this.broadcastDuration = (int) duration.getStandardSeconds(); this.activelyPublished = activelyPublished; }
From source file:org.emonocot.portal.scheduling.HarvestDataJob.java
License:Open Source License
@Override protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { try {/*from w w w . j a v a 2 s.c o m*/ SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get("applicationContext"); ResourceService resourceService = (ResourceService) applicationContext.getBean(resourceServiceName); JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean(jobLauncherName); logger.info("HarvestDataJob"); for (String cronExpression : cronExpressions) { CronExpression expression = new CronExpression(cronExpression); DateTime now = new DateTime(); if (expression.isSatisfiedBy(now.toDate()) && !resourceService.isHarvesting()) { DateTime nextInvalidDate = new DateTime(expression.getNextInvalidTimeAfter(now.toDate())); logger.info(cronExpression + " is satified and resourceService is not harvesting, looking for jobs to harvest . . ."); List<Resource> resourcesToHarvest = resourceService.listResourcesToHarvest(10, now, "job-with-source"); Resource resource = null; for (Resource r : resourcesToHarvest) { DateTime probableFinishingTime = now.plus(r.getDuration()); if (probableFinishingTime.isBefore(nextInvalidDate) && (r.getLastAttempt() == null || r.getLastAttempt().plusHours(MINIMAL_INTERVAL).isBefore(now))) { resource = r; break; } } if (resource != null) { logger.info("Found that we can harvest " + resource.getTitle()); Map<String, String> jobParametersMap = new HashMap<String, String>(); jobParametersMap.put("authority.name", resource.getOrganisation().getIdentifier()); jobParametersMap.put("authority.uri", resource.getUri()); jobParametersMap.put("resource.identifier", resource.getIdentifier()); jobParametersMap.put("attempt", UUID.randomUUID().toString()); // Prevent jobs failing if a job has been executed with the same parameters jobParametersMap.put("authority.last.harvested", Long.toString((resource.getStartTime().getMillis()))); jobParametersMap.putAll(resource.getParameters()); JobLaunchRequest jobLaunchRequest = new JobLaunchRequest(); jobLaunchRequest.setJob(resource.getResourceType().getJobName()); jobLaunchRequest.setParameters(jobParametersMap); try { jobLauncher.launch(jobLaunchRequest); resource.setLastAttempt(now); resource.setStartTime(null); resource.setDuration(null); resource.setExitCode(null); resource.setExitDescription(null); resource.setJobId(null); resource.setStatus(BatchStatus.UNKNOWN); resource.setRecordsRead(0); resource.setReadSkip(0); resource.setProcessSkip(0); resource.setWriteSkip(0); resource.setWritten(0); resourceService.saveOrUpdate(resource); } catch (org.emonocot.api.job.JobExecutionException jee) { throw new JobExecutionException(jee); } } else { logger.info("Could not find a resource we can safely harvest in the time available"); } } else { logger.info(now + " is not within " + cronExpression + "or resourceService is harvesting, skipping!"); } } } catch (ParseException pe) { throw new JobExecutionException(pe); } catch (SchedulerException se) { throw new JobExecutionException(se); } }
From source file:org.eumetsat.usd.gcp.server.data.NetCDFCalibrationDataManager.java
License:Apache License
/** * Add several calibration records from a certain source. * //from ww w. j a v a 2s. com * @param userID * id of the user making the request. * @param ncfile * netCDF file handler to read conversion parameters. * @param sourceName * name of the data source. * @param sourceURL * URL of the data source. * @param dateArray * array of dates. * @param offsetArray * array of offsets. * @param offsetSeArray * array of standard deviations for offset. * @param slopeArray * array of slopes. * @param slopeSeArray * array of standard deviations for slope. * @param covarianceArray * array of covariances. * @param channelNum * channel number. * @param sceneTb * scene brightness temperature. * @param radToTbConvFormula * rad to tb conversion formula. * @param tbToRadConvFormula * tb to rad conversion formula. * @param convVarsNames * conversion variables names. * @throws DatasetReadException * when dataset could not be opened for reading. * @throws InvalidFormatException * when dataset has an invalid format. * @throws InvalidFilenameException * when dataset has an invalid filename. * @throws VariableReadException * @throws ChannelNotFoundException * @throws VariableNotFoundException */ private final void addCalibrationRecords(final String userID, final NetcdfFile ncfile, final String sourceName, final String sourceURL, final Array dateArray, final Array offsetArray, final Array offsetSeArray, final Array slopeArray, final Array slopeSeArray, final Array covarianceArray, final int channelNum, final double sceneTb, final String radToTbConvFormula, final String tbToRadConvFormula, final Set<String> convVarsNames) throws BadArgumentException, InvalidFilenameException, DatasetReadException, VariableNotFoundException, ChannelNotFoundException, VariableReadException { // Check dimensions consistency. if ((dateArray.getShape()[0] != offsetArray.getShape()[0]) || (dateArray.getShape()[0] != slopeArray.getShape()[0]) || (dateArray.getShape()[0] != offsetSeArray.getShape()[0]) || (dateArray.getShape()[0] != slopeSeArray.getShape()[0]) || (dateArray.getShape()[0] != covarianceArray.getShape()[0])) { throw new BadArgumentException("array dimensions mismatch."); } // Sweep arrays and add each record into the map. for (int i = 0; i < dateArray.getShape()[0]; i++) { Double dateDouble = dateArray.getDouble(i) * 1e3; // in [ms] Date date = new Date(dateDouble.longValue()); // Read the conversion variables. Map<String, Double> convVars = new HashMap<String, Double>(); for (String convVarName : convVarsNames) { // TODO: [Remove workaround when formulas are changed] // Restore 'c1' and 'c2', if they are in the formula... if (convVarName.equals(configManager.getGlobalAttributesNames().getC1())) { convVars.put(C1_VARNAME, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum)); } else if (convVarName.equals(configManager.getGlobalAttributesNames().getC2())) { convVars.put(C2_VARNAME, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum)); } else { convVars.put(convVarName, NetcdfUtils.readDouble(ncfile, convVarName, i, channelNum)); } } // Create calibration record. CalibrationRecord calRecord = new CalibrationRecordImpl(radToTbConvFormula, tbToRadConvFormula, convVars, TB_VARNAME, RAD_VARNAME, offsetArray.getDouble(i), offsetSeArray.getDouble(i), slopeArray.getDouble(i), slopeSeArray.getDouble(i), covarianceArray.getDouble(i), sceneTb); // Add calibration record, if valid, to data for this user. if (calRecord.isValid()) { dataForUser(userID).addRecord(date, sourceName, sourceURL, calRecord); // TODO: to be checked. // if single-point, add a second one, with same value, and shifted one second, so that // it can be plotted by dygraphs. if (dateArray.getShape()[0] == 1) { DateTime dt = new DateTime(date); dt = dt.plus(Seconds.ONE); dataForUser(userID).addRecord(dt.toDate(), sourceName, sourceURL, calRecord); } } } }
From source file:org.fao.geonet.domain.ISODate.java
License:Open Source License
public static String parseISODateTimes(String input1, String input2) { DateTimeFormatter dto = ISODateTimeFormat.dateTime(); PeriodFormatter p = ISOPeriodFormat.standard(); DateTime odt1; String odt = ""; // input1 should be some sort of ISO time // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc // convert everything to UTC so that we remove any timezone // problems//w w w . j a v a 2s. c o m try { DateTime idt = parseBasicOrFullDateTime(input1); odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt1.toString(); } catch (Exception e) { Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e); return DEFAULT_DATE_TIME; } if (input2 == null || input2.equals("")) return odt; // input2 can be an ISO time as for input1 but also an ISO time period // eg. -P3D or P3D - if an ISO time period then it must be added to the // DateTime generated for input1 (odt1) // convert everything to UTC so that we remove any timezone // problems try { boolean minus = false; if (input2.startsWith("-P")) { input2 = input2.substring(1); minus = true; } if (input2.startsWith("P")) { Period ip = p.parsePeriod(input2); DateTime odt2; if (!minus) odt2 = odt1.plus(ip.toStandardDuration().getMillis()); else odt2 = odt1.minus(ip.toStandardDuration().getMillis()); odt = odt + "|" + odt2.toString(); } else { DateTime idt = parseBasicOrFullDateTime(input2); DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt + "|" + odt2.toString(); } } catch (Exception e) { Log.error("geonetwork.domain", "Error parsing ISO DateTimes, error: " + e.getMessage(), e); return odt + "|" + DEFAULT_DATE_TIME; } return odt; }
From source file:org.fao.geonet.util.JODAISODate.java
License:Open Source License
public static String parseISODateTimes(String input1, String input2) { DateTimeFormatter dto = ISODateTimeFormat.dateTime(); PeriodFormatter p = ISOPeriodFormat.standard(); DateTime odt1; String odt = ""; // input1 should be some sort of ISO time // eg. basic: 20080909, full: 2008-09-09T12:21:00 etc // convert everything to UTC so that we remove any timezone // problems/*w ww . j a v a2 s . co m*/ try { DateTime idt = parseBasicOrFullDateTime(input1); odt1 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt1.toString(); } catch (Exception e) { e.printStackTrace(); return dt; } if (input2 == null || input2.equals("")) return odt; // input2 can be an ISO time as for input1 but also an ISO time period // eg. -P3D or P3D - if an ISO time period then it must be added to the // DateTime generated for input1 (odt1) // convert everything to UTC so that we remove any timezone // problems try { boolean minus = false; if (input2.startsWith("-P")) { input2 = input2.substring(1); minus = true; } if (input2.startsWith("P")) { Period ip = p.parsePeriod(input2); DateTime odt2; if (!minus) odt2 = odt1.plus(ip.toStandardDuration().getMillis()); else odt2 = odt1.minus(ip.toStandardDuration().getMillis()); odt = odt + "|" + odt2.toString(); } else { DateTime idt = parseBasicOrFullDateTime(input2); DateTime odt2 = dto.parseDateTime(idt.toString()).withZone(DateTimeZone.forID("UTC")); odt = odt + "|" + odt2.toString(); } } catch (Exception e) { e.printStackTrace(); return odt + "|" + dt; } return odt; }