EidasSaml { public static byte[] createResponse(List<EidasAttribute> att, String destination, String recipient, EidasNameId nameid, String issuer, EidasLoA loa, String inResponseTo, EidasEncrypter encrypter, EidasSigner signer) throws InitializationException, CertificateEncodingException, XMLParserException, IOException, UnmarshallingException, EncryptionException, MarshallingException, SignatureException, TransformerFactoryConfigurationError, TransformerException, ComponentInitializationException { init(); EidasResponse response = new EidasResponse(att, destination, recipient, nameid, inResponseTo, issuer, loa, signer, encrypter); return response.generate(); } private  EidasSaml(); static synchronized void init(); static byte[] createRequest(String issuer,
                                     String destination,
                                     EidasSigner signer,
                                     Map<EidasPersonAttributes, Boolean> requestedAttributes); static byte[] createRequest(String issuer,
                                     String destination,
                                     EidasSigner signer,
                                     Map<EidasPersonAttributes, Boolean> requestedAttributes,
                                     String id); static byte[] createRequest(String issuer,
                                     String destination,
                                     String providerName,
                                     EidasSigner signer,
                                     Map<EidasPersonAttributes, Boolean> requestedAttributes,
                                     EidasRequestSectorType sectorType,
                                     EidasNameIdType nameIdPolicy,
                                     EidasLoA loa); static byte[] createRequest(String id,
                                     String issuer,
                                     String destination,
                                     String providerName,
                                     EidasSigner signer,
                                     Map<EidasPersonAttributes, Boolean> requestedAttributes,
                                     EidasRequestSectorType sectorType,
                                     EidasNameIdType nameIdPolicy,
                                     EidasLoA loa); static byte[] createRequest(String issuer,
                                     String destination,
                                     EidasSigner signer,
                                     Map<EidasPersonAttributes, Boolean> requestedAttributes,
                                     EidasRequestSectorType sectorType,
                                     EidasNameIdType nameIdPolicy,
                                     EidasLoA loa); static EidasRequest parseRequest(InputStream is); static EidasRequest parseRequest(InputStream is, List<X509Certificate> authors); static void verifyRequest(EidasRequest request, List<X509Certificate> authors); static byte[] createResponse(List<EidasAttribute> att,
                                      String destination,
                                      String recipient,
                                      EidasNameId nameid,
                                      String issuer,
                                      EidasLoA loa,
                                      String inResponseTo,
                                      EidasEncrypter encrypter,
                                      EidasSigner signer); static EidasResponse parseResponse(InputStream is,
                                            X509KeyPair[] decryptionKeyPairs,
                                            X509Certificate[] signatureAuthors); static byte[] createMetaDataService(String id,
                                             String entityId,
                                             Date validUntil,
                                             X509Certificate sigCert,
                                             X509Certificate encCert,
                                             EidasOrganisation organisation,
                                             EidasContactPerson technicalcontact,
                                             EidasContactPerson supportContact,
                                             String postEndpoint,
                                             String redirectEndpoint,
                                             List<EidasNameIdType> supportedNameIdTypes,
                                             List<EidasPersonAttributes> attributes,
                                             EidasSigner signer,
                                             String middlewareVersion,
                                             boolean doSign,
                                             boolean requesterIdFlag); static byte[] createMetaDataNode(String id,
                                          String entityId,
                                          Date validUntil,
                                          X509Certificate sigCert,
                                          X509Certificate encCert,
                                          EidasOrganisation organisation,
                                          EidasContactPerson techcontact,
                                          EidasContactPerson supportcontact,
                                          String postEndpoint,
                                          EidasRequestSectorType spType,
                                          List<EidasNameIdType> supportedNameIdTypes,
                                          EidasSigner signer); static EidasMetadataNode parseMetaDataNode(InputStream is, X509Certificate signer); static void validateXMLRequest(InputStream is, boolean resetStreamAfterValidation);  }
@Test public void createParseResponse() throws CertificateException, IOException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, NoSuchProviderException, KeyException, XMLParserException, UnmarshallingException, EncryptionException, MarshallingException, SignatureException, TransformerFactoryConfigurationError, TransformerException, ErrorCodeException, InitializationException, ComponentInitializationException { BirthNameAttribute birthName = new BirthNameAttribute("Meyer"); CurrentAddressAttribute currentAddress = new CurrentAddressAttribute("Am Fallturm", "33", "Bremen", "28207", "100", "bla", "bla", "bla", "bla"); DateOfBirthAttribute dao = new DateOfBirthAttribute("1982-02-11"); FamilyNameAttribute familyName = new FamilyNameAttribute("Muller", "Müller"); GenderAttribute gender = new GenderAttribute(GenderType.MALE); GivenNameAttribute givenName = new GivenNameAttribute("Bjorn", "Bjørn"); PersonIdentifierAttribute pi = new PersonIdentifierAttribute("test12321"); PlaceOfBirthAttribute pob = new PlaceOfBirthAttribute("Saint-Étienne, France"); ArrayList<EidasAttribute> att = new ArrayList<>(); att.add(birthName); att.add(currentAddress); att.add(dao); att.add(familyName); att.add(gender); att.add(givenName); att.add(pi); att.add(pob); String destination = "test destination"; String recipient = "test_recipient"; EidasNameId nameid = new EidasPersistentNameId("eidasnameidTest"); String issuer = "test issuer"; String inResponseTo = "test inResponseTo"; EidasLoA loa = EidasLoA.SUBSTANTIAL; X509Certificate[] cert = {Utils.readCert(TestEidasSaml.class.getResourceAsStream("/EidasSignerTest_x509.cer"))}; X509KeyPair[] keypair = {Utils.readPKCS12(TestEidasSaml.class.getResourceAsStream(TEST_P12), "123456".toCharArray())}; PrivateKey pk = keypair[0].getKey(); EidasEncrypter encrypter = new EidasEncrypter(true, cert[0]); EidasSigner signer = new EidasSigner(true, pk, cert[0]); byte[] response = EidasSaml.createResponse(att, destination, recipient, nameid, issuer, loa, inResponseTo, encrypter, signer); System.out.println("-->>Response-->>" + new String(response)); EidasResponse result = EidasResponse.parse(new ByteArrayInputStream(response), keypair, cert); assertEquals(result.getDestination(), destination); assertEquals(result.getNameId().getValue(), nameid.getValue()); assertEquals(result.getIssuer(), issuer); assertEquals(result.getInResponseTo(), inResponseTo); for ( int i = 0 ; i < att.size() ; i++ ) { assertEquals(result.getAttributes().get(i).getLatinScript().replaceAll("\\s+", ""), att.get(i).getLatinScript().replaceAll("\\s+", "")); } }