List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeParser
public static DateTimeFormatter dateTimeParser()
From source file:be.agiv.security.client.IPSTSClient.java
License:Open Source License
private SecurityToken getSecurityToken(String username, String password, X509Certificate certificate, PrivateKey privateKey) {/*from w w w. ja va 2 s .co m*/ RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType(); List<Object> requestSecurityTokenContent = requestSecurityToken.getAny(); requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE)); EntropyType entropy = this.objectFactory.createEntropyType(); requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy)); BinarySecretType binarySecret = this.objectFactory.createBinarySecretType(); entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret)); binarySecret.setType(WSConstants.SECRET_TYPE_NONCE); requestSecurityTokenContent.add(this.objectFactory.createKeyType(WSConstants.KEY_TYPE_SYMMETRIC)); requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L)); if (null == this.wsTrustHandler.getSecondaryParameters()) { requestSecurityTokenContent .add(this.objectFactory.createKeyWrapAlgorithm(WSConstants.KEY_WRAP_ALGO_RSA_OAEP_MGF1P)); requestSecurityTokenContent.add(this.objectFactory.createEncryptWith(WSConstants.ENC_ALGO_AES256_CBC)); requestSecurityTokenContent.add(this.objectFactory.createSignWith(WSConstants.SIGN_ALGO_HMAC_SHA1)); requestSecurityTokenContent .add(this.objectFactory.createCanonicalizationAlgorithm(WSConstants.C14N_ALGO_EXC)); requestSecurityTokenContent .add(this.objectFactory.createEncryptionAlgorithm(WSConstants.ENC_ALGO_AES256_CBC)); } AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo(); EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType(); AttributedURIType address = this.addrObjectFactory.createAttributedURIType(); address.setValue(this.realm); endpointReference.setAddress(address); appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference)); requestSecurityTokenContent.add(appliesTo); requestSecurityTokenContent .add(this.objectFactory.createComputedKeyAlgorithm(WSConstants.COMP_KEY_ALGO_PSHA1)); byte[] entropyData = new byte[256 / 8]; // entropy = keysize / 8 this.secureRandom.setSeed(System.currentTimeMillis()); this.secureRandom.nextBytes(entropyData); binarySecret.setValue(entropyData); BindingProvider bindingProvider = (BindingProvider) this.port; if (null != username) { this.wsSecurityHandler.setCredentials(username, password); } else if (null != certificate) { this.wsSecurityHandler.setCredentials(privateKey, certificate); } this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_ISSUE_ACTION, this.location); RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port .requestSecurityToken(requestSecurityToken); SecurityToken securityToken = new SecurityToken(); List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection .getRequestSecurityTokenResponse(); RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0); List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny(); for (Object contentObject : requestSecurityTokenResponseContent) { LOG.debug("content object: " + contentObject.getClass().getName()); if (contentObject instanceof Element) { Element contentElement = (Element) contentObject; LOG.debug("element name: " + contentElement.getLocalName()); } if (contentObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) contentObject; QName qname = jaxbElement.getName(); LOG.debug("qname: " + qname); if (WSConstants.ENTROPY_QNAME.equals(qname)) { LOG.debug("trust:Entropy"); EntropyType serverEntropy = (EntropyType) jaxbElement.getValue(); List<Object> entropyContent = serverEntropy.getAny(); for (Object entropyObject : entropyContent) { if (entropyObject instanceof JAXBElement) { JAXBElement entropyElement = (JAXBElement) entropyObject; if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) { BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue(); byte[] serverSecret = serverBinarySecret.getValue(); P_SHA1 p_SHA1 = new P_SHA1(); byte[] key; try { key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8); } catch (ConversationException e) { LOG.error(e); return null; } LOG.debug("client secret size: " + entropyData.length); LOG.debug("server secret size: " + serverSecret.length); LOG.debug("key size: " + key.length); securityToken.setKey(key); } } } } else if (WSConstants.LIFETIME_QNAME.equals(qname)) { LOG.debug("trust:Lifetime"); LifetimeType lifetime = (LifetimeType) jaxbElement.getValue(); String createdValue = lifetime.getCreated().getValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime created = dateTimeFormatter.parseDateTime(createdValue); securityToken.setCreated(created.toDate()); String expiresString = lifetime.getExpires().getValue(); DateTime expires = dateTimeFormatter.parseDateTime(expiresString); securityToken.setExpires(expires.toDate()); } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) { KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement .getValue(); String attachedReference = keyIdentifier.getValue(); securityToken.setAttachedReference(attachedReference); } } } } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) { KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement .getValue(); String unattachedReference = keyIdentifier.getValue(); securityToken.setUnattachedReference(unattachedReference); } } } } } } Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken(); securityToken.setToken(requestedSecurityToken); securityToken.setRealm(this.realm); securityToken.setStsLocation(this.location); return securityToken; }
From source file:be.agiv.security.client.RSTSClient.java
License:Open Source License
/** * Retrieves a new security token from the R-STS WS-Trust web service using * the given IP-STS security token. The security token retrieved from the * R-STS always applies to a certain AGIV web service. The location of this * AGIV web service is also passed as parameter. * /*from w w w .ja va 2 s. co m*/ * @param ipStsSecurityToken * the IP-STS security token. * @param appliesTo * the WS-SecureConversation enabled web service to which the * R-STS security token should apply. * @return the R-STS security token to be used by the service Secure * Conversation. */ public SecurityToken getSecurityToken(SecurityToken ipStsSecurityToken, String appliesTo) { RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType(); List<Object> requestSecurityTokenContent = requestSecurityToken.getAny(); requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE)); AppliesTo jaxbAppliesTo = this.policyObjectFactory.createAppliesTo(); EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType(); AttributedURIType address = this.addrObjectFactory.createAttributedURIType(); address.setValue(appliesTo); endpointReference.setAddress(address); jaxbAppliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference)); requestSecurityTokenContent.add(jaxbAppliesTo); BindingProvider bindingProvider = (BindingProvider) this.port; this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_ISSUE_ACTION, this.location); this.wsSecurityHandler.setKey(ipStsSecurityToken.getKey(), ipStsSecurityToken.getAttachedReference(), ipStsSecurityToken.getToken()); RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port .requestSecurityToken(requestSecurityToken); SecurityToken securityToken = new SecurityToken(); List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection .getRequestSecurityTokenResponse(); RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0); List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny(); for (Object contentObject : requestSecurityTokenResponseContent) { LOG.debug("content object: " + contentObject.getClass().getName()); if (contentObject instanceof Element) { Element contentElement = (Element) contentObject; LOG.debug("element name: " + contentElement.getLocalName()); } if (contentObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) contentObject; QName qname = jaxbElement.getName(); LOG.debug("JAXB qname: " + qname); if (WSConstants.LIFETIME_QNAME.equals(qname)) { LOG.debug("trust:Lifetime"); LifetimeType lifetime = (LifetimeType) jaxbElement.getValue(); String createdValue = lifetime.getCreated().getValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime created = dateTimeFormatter.parseDateTime(createdValue); securityToken.setCreated(created.toDate()); String expiresString = lifetime.getExpires().getValue(); DateTime expires = dateTimeFormatter.parseDateTime(expiresString); securityToken.setExpires(expires.toDate()); } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) { KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement .getValue(); String tokenIdentifier = keyIdentifier.getValue(); securityToken.setAttachedReference(tokenIdentifier); } } } } else if (WSConstants.REQUESTED_PROOF_TOKEN_QNAME.equals(qname)) { RequestedProofTokenType requestedProofToken = (RequestedProofTokenType) jaxbElement.getValue(); Object requestedProofTokenContent = requestedProofToken.getAny(); LOG.debug("requested proof token content: " + requestedProofTokenContent.getClass().getName()); if (requestedProofTokenContent instanceof JAXBElement) { JAXBElement requestedProofTokenElement = (JAXBElement) requestedProofTokenContent; LOG.debug("requested proof token element: " + requestedProofTokenElement.getName()); if (WSConstants.BINARY_SECRET_QNAME.equals(requestedProofTokenElement.getName())) { BinarySecretType serverBinarySecret = (BinarySecretType) requestedProofTokenElement .getValue(); byte[] serverSecret = serverBinarySecret.getValue(); securityToken.setKey(serverSecret); } } } } } Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken(); securityToken.setToken(requestedSecurityToken); securityToken.setRealm(appliesTo); securityToken.setStsLocation(this.location); securityToken.setParentSecurityToken(ipStsSecurityToken); return securityToken; }
From source file:be.agiv.security.client.SecureConversationClient.java
License:Open Source License
/** * Gives back a secure conversation token using the given R-STS security * token. The R-STS security token should apply to this web service. * /*w w w .j a va2 s .c o m*/ * @param rStsSecurityToken * the R-STS security token. * @return the secure conversation token to be used to secure the web * service calls. */ public SecurityToken getSecureConversationToken(SecurityToken rStsSecurityToken) { RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType(); List<Object> requestSecurityTokenContent = requestSecurityToken.getAny(); requestSecurityTokenContent .add(this.objectFactory.createTokenType(WSConstants.SECURE_CONVERSATION_TOKEN_TYPE)); requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE)); EntropyType entropy = this.objectFactory.createEntropyType(); requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy)); BinarySecretType binarySecret = this.objectFactory.createBinarySecretType(); entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret)); binarySecret.setType(WSConstants.SECRET_TYPE_NONCE); byte[] entropyData = new byte[256 / 8]; this.secureRandom.setSeed(System.currentTimeMillis()); this.secureRandom.nextBytes(entropyData); binarySecret.setValue(entropyData); requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L)); BindingProvider bindingProvider = (BindingProvider) this.port; this.wsAddressingHandler.setAddressing(WSConstants.SEC_CONV_ISSUE_ACTION, this.location); this.wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(), rStsSecurityToken.getToken()); RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port .requestSecurityToken(requestSecurityToken); SecurityToken securityToken = new SecurityToken(); List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection .getRequestSecurityTokenResponse(); RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0); List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny(); for (Object contentObject : requestSecurityTokenResponseContent) { LOG.debug("content object: " + contentObject.getClass().getName()); if (contentObject instanceof Element) { Element contentElement = (Element) contentObject; LOG.debug("element name: " + contentElement.getLocalName()); } if (contentObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) contentObject; QName qname = jaxbElement.getName(); if (WSConstants.ENTROPY_QNAME.equals(qname)) { LOG.debug("trust:Entropy"); EntropyType serverEntropy = (EntropyType) jaxbElement.getValue(); List<Object> entropyContent = serverEntropy.getAny(); for (Object entropyObject : entropyContent) { if (entropyObject instanceof JAXBElement) { JAXBElement entropyElement = (JAXBElement) entropyObject; if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) { BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue(); byte[] serverSecret = serverBinarySecret.getValue(); P_SHA1 p_SHA1 = new P_SHA1(); byte[] key; try { key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8); } catch (ConversationException e) { LOG.error(e); return null; } LOG.debug("client secret size: " + entropyData.length); LOG.debug("server secret size: " + serverSecret.length); LOG.debug("key size: " + key.length); securityToken.setKey(key); } } } } else if (WSConstants.LIFETIME_QNAME.equals(qname)) { LOG.debug("trust:Lifetime"); LifetimeType lifetime = (LifetimeType) jaxbElement.getValue(); String createdValue = lifetime.getCreated().getValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime created = dateTimeFormatter.parseDateTime(createdValue); securityToken.setCreated(created.toDate()); String expiresString = lifetime.getExpires().getValue(); DateTime expires = dateTimeFormatter.parseDateTime(expiresString); securityToken.setExpires(expires.toDate()); } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) { ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue(); String tokenIdentifier = reference.getURI().substring(1); securityToken.setAttachedReference(tokenIdentifier); } } } } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) { ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue(); String tokenIdentifier = reference.getURI(); securityToken.setUnattachedReference(tokenIdentifier); } } } } } } Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken(); securityToken.setToken(requestedSecurityToken); securityToken.setStsLocation(this.location); securityToken.setRealm(this.location); // what else? securityToken.setParentSecurityToken(rStsSecurityToken); return securityToken; }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImpl.java
License:Open Source License
private void validateToken(Element tokenElement, String expectedAudience, IdentityProviderConfiguration identityProviderConfiguration) throws Exception { List<X509Certificate> certificateChain = identityProviderConfiguration.getIdentityCertificateChain(); if (certificateChain.isEmpty()) { throw new SecurityException("no eID IdP service identity configured"); }//from w ww .j a va2 s.c o m Element nsElement = tokenElement.getOwnerDocument().createElement("nsElement"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"); nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:saml2", "urn:oasis:names:tc:SAML:2.0:assertion"); LOG.debug("token element: " + tokenElement.getLocalName()); LOG.debug("token element namespace: " + tokenElement.getNamespaceURI()); LOG.debug("token: " + toString(tokenElement)); // fix for recent versions of Apache xmlsec. tokenElement.setIdAttribute("ID", true); Element signatureElement = (Element) XPathAPI.selectSingleNode(tokenElement, "ds:Signature", nsElement); if (null == signatureElement) { throw new SecurityException("missing XML signature"); } XMLSignature xmlSignature = new XMLSignature(signatureElement, ""); KeyInfo keyInfo = xmlSignature.getKeyInfo(); X509Certificate actualCertificate = keyInfo.getX509Certificate(); boolean signatureResult = xmlSignature.checkSignatureValue(actualCertificate); if (false == signatureResult) { throw new SecurityException("invalid XML signature"); } LOG.debug("XML signature OK"); X509Certificate serviceCertificate = certificateChain.get(0); if (false == Arrays.equals(serviceCertificate.getEncoded(), actualCertificate.getEncoded())) { throw new SecurityException("SAML signing certificate different from eID IdP service identity"); } LOG.debug("SAML signer OK"); String actualIssuer = XPathAPI.selectSingleNode(tokenElement, "saml2:Issuer/text()", nsElement) .getNodeValue(); String serviceIssuer = identityProviderConfiguration.getDefaultIssuer(); if (false == actualIssuer.equals(serviceIssuer)) { LOG.debug("actual issuer: " + actualIssuer); LOG.debug("service issuer: " + serviceIssuer); throw new SecurityException("wrong SAML issuer"); } LOG.debug("SAML issuer OK"); if (null != expectedAudience) { String audience = XPathAPI .selectSingleNode(tokenElement, "saml2:Conditions/saml2:AudienceRestriction/saml2:Audience/text()", nsElement) .getNodeValue(); if (false == expectedAudience.equals(audience)) { LOG.debug("expected audience: " + expectedAudience); LOG.debug("actual audience: " + audience); throw new SecurityException("incorrect SAML audience"); } LOG.debug("SAML Audience OK"); } else { LOG.warn("SAML audience restriction not checked"); } String authnContextClassRef = XPathAPI .selectSingleNode(tokenElement, "saml2:AuthnStatement/saml2:AuthnContext/saml2:AuthnContextClassRef/text()", nsElement) .getNodeValue(); LOG.debug("AuthnContextClassRef: " + authnContextClassRef); SamlAuthenticationPolicy samlAuthenticationPolicy = SamlAuthenticationPolicy .getAuthenticationPolicy(authnContextClassRef); if (SamlAuthenticationPolicy.AUTHENTICATION != samlAuthenticationPolicy && SamlAuthenticationPolicy.AUTHENTICATION_WITH_IDENTIFICATION != samlAuthenticationPolicy) { throw new SecurityException("wrong SAML authentication policy: " + samlAuthenticationPolicy); } String notBeforeStr = XPathAPI.selectSingleNode(tokenElement, "saml2:Conditions/@NotBefore", nsElement) .getNodeValue(); String notOnOrAfterStr = XPathAPI .selectSingleNode(tokenElement, "saml2:Conditions/@NotOnOrAfter", nsElement).getNodeValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime notBefore = dateTimeFormatter.parseDateTime(notBeforeStr); DateTime notOnOrAfter = dateTimeFormatter.parseDateTime(notOnOrAfterStr); DateTime now = new DateTime(); if (now.isBefore(notBefore)) { throw new SecurityException("SAML assertion in future"); } if (now.isAfter(notOnOrAfter)) { throw new SecurityException("SAML assertion expired"); } LOG.debug("SAML timestamp OK"); }
From source file:buri.ddmsence.util.Util.java
License:Open Source License
/** * Helper method for DDMS components that use the DDMS custom date. Converts date strings * in any of the valid DDMS date types (ddms:CombinedDateType) into an XMLGregorianCalendar. * /* w w w .j a va 2 s . com*/ * Returns null if the string is empty or not a valid date type. * * @param date the raw date string * @return an XMLGregorianCalendar for valid dates, null otherwise. */ public static XMLGregorianCalendar toXMLGregorianCalendar(String date) { try { return (getDataTypeFactory().newXMLGregorianCalendar(date)); } catch (IllegalArgumentException e) { if (isEmpty(date) || TemporalCoverage.EXTENDED_DATE_TYPES.contains(date)) return (null); GregorianCalendar gregory = ISODateTimeFormat.dateTimeParser().parseDateTime(date) .toGregorianCalendar(); return (getDataTypeFactory().newXMLGregorianCalendar(gregory)); } }
From source file:ca.ualberta.physics.cssdp.util.JSONDateTimeDeserializer.java
License:Apache License
@Override public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {//from ww w .j a va 2s. co m return ISODateTimeFormat.dateTimeParser().parseDateTime(jp.getText()); } catch (Exception e) { e.printStackTrace(); throw new JsonParseException(e.getMessage(), jp.getCurrentLocation()); } }
From source file:ca.ualberta.physics.cssdp.util.JSONLocalDateDeserializer.java
License:Apache License
@Override public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { return ISODateTimeFormat.dateTimeParser().parseLocalDate(jp.getText()); }
From source file:ca.ualberta.physics.cssdp.util.JSONLocalDateTimeDeserializer.java
License:Apache License
@Override public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {/*w w w.j a v a 2 s . com*/ return ISODateTimeFormat.dateTimeParser().parseLocalDateTime(jp.getText()); } catch (Exception e) { e.printStackTrace(); throw new JsonParseException(e.getMessage(), jp.getCurrentLocation()); } }
From source file:cc.vidr.datum.term.DateTimeTerm.java
License:Open Source License
/** * Creat a new term from the given ISO8601-formatted string. * /*from w w w . j a v a2 s . c o m*/ * @param text the string */ public DateTimeTerm(String text) { this(text, ISODateTimeFormat.dateTimeParser()); }
From source file:ch.admin.suis.msghandler.util.ISO8601Utils.java
License:Open Source License
/** * Parse the given string in the ISO-8601 format and returns the resulting * date. If the provided value is <code>null</code>, this method returns * <code>null</code> as well. * * @param value must be a string in the ISO-8601 format * @return the created <code>java.util.Date</code> object * @throws IllegalArgumentException if the provided parameter value is not a string in the ISO-8601 * format * @throws UnsupportedOperationException if parsing is not supported *///from ww w . ja v a2 s. co m public static Date parse(String value) { if (null == value) { return null; } DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser(); return fmt.parseDateTime(value).toDate(); }