2626import com .onelogin .saml2 .authn .AuthnRequestParams ;
2727import com .onelogin .saml2 .authn .SamlResponse ;
2828import com .onelogin .saml2 .exception .SettingsException ;
29- import com .onelogin .saml2 .factory .SamlOutgoingMessageFactory ;
30- import com .onelogin .saml2 .factory .SamlReceivedMessageFactory ;
29+ import com .onelogin .saml2 .factory .SamlMessageFactory ;
3130import com .onelogin .saml2 .exception .Error ;
3231import com .onelogin .saml2 .http .HttpRequest ;
3332import com .onelogin .saml2 .logout .LogoutRequest ;
@@ -171,19 +170,9 @@ public class Auth {
171170 */
172171 private String lastResponse ;
173172
174- private static final SamlOutgoingMessageFactory <AuthnRequestParams , AuthnRequest > DEFAULT_AUTHN_REQUEST_FACTORY = AuthnRequest ::new ;
175- private static final SamlReceivedMessageFactory <SamlResponse > DEFAULT_SAML_RESPONSE_FACTORY = SamlResponse ::new ;
176- private static final SamlOutgoingMessageFactory <LogoutRequestParams , LogoutRequest > DEFAULT_OUTGOING_LOGOUT_REQUEST_FACTORY = LogoutRequest ::new ;
177- private static final SamlReceivedMessageFactory <LogoutRequest > DEFAULT_RECEIVED_LOGOUT_REQUEST_FACTORY = LogoutRequest ::new ;
178- private static final SamlOutgoingMessageFactory <LogoutResponseParams , LogoutResponse > DEFAULT_OUTGOING_LOGOUT_RESPONSE_FACTORY = LogoutResponse ::new ;
179- private static final SamlReceivedMessageFactory <LogoutResponse > DEFAULT_RECEIVED_LOGOUT_RESPONSE_FACTORY = LogoutResponse ::new ;
173+ private static final SamlMessageFactory DEFAULT_SAML_MESSAGE_FACTORY = new SamlMessageFactory () {};
180174
181- private SamlOutgoingMessageFactory <AuthnRequestParams , AuthnRequest > authnRequestFactory = DEFAULT_AUTHN_REQUEST_FACTORY ;
182- private SamlReceivedMessageFactory <SamlResponse > samlResponseFactory = DEFAULT_SAML_RESPONSE_FACTORY ;
183- private SamlOutgoingMessageFactory <LogoutRequestParams , LogoutRequest > outgoingLogoutRequestFactory = DEFAULT_OUTGOING_LOGOUT_REQUEST_FACTORY ;
184- private SamlReceivedMessageFactory <LogoutRequest > receivedLogoutRequestFactory = DEFAULT_RECEIVED_LOGOUT_REQUEST_FACTORY ;
185- private SamlOutgoingMessageFactory <LogoutResponseParams , LogoutResponse > outgoingLogoutResponseFactory = DEFAULT_OUTGOING_LOGOUT_RESPONSE_FACTORY ;
186- private SamlReceivedMessageFactory <LogoutResponse > receivedLogoutResponseFactory = DEFAULT_RECEIVED_LOGOUT_RESPONSE_FACTORY ;
175+ private SamlMessageFactory samlMessageFactory = DEFAULT_SAML_MESSAGE_FACTORY ;
187176
188177 /**
189178 * Initializes the SP SAML instance.
@@ -626,7 +615,7 @@ public String login(String relayState, AuthnRequestParams authnRequestParams, Bo
626615 * @throws SettingsException
627616 */
628617 public String login (String relayState , AuthnRequestParams authnRequestParams , Boolean stay , Map <String , String > parameters ) throws IOException , SettingsException {
629- AuthnRequest authnRequest = authnRequestFactory . create (settings , authnRequestParams );
618+ AuthnRequest authnRequest = samlMessageFactory . createAuthnRequest (settings , authnRequestParams );
630619
631620 if (parameters == null ) {
632621 parameters = new HashMap <String , String >();
@@ -802,7 +791,7 @@ public String logout(String relayState, LogoutRequestParams logoutRequestParams,
802791 parameters = new HashMap <String , String >();
803792 }
804793
805- LogoutRequest logoutRequest = outgoingLogoutRequestFactory . create (settings , logoutRequestParams );
794+ LogoutRequest logoutRequest = samlMessageFactory . createOutgoingLogoutRequest (settings , logoutRequestParams );
806795 String samlLogoutRequest = logoutRequest .getEncodedLogoutRequest ();
807796 parameters .put ("SAMLRequest" , samlLogoutRequest );
808797
@@ -1213,7 +1202,7 @@ public void processResponse(String requestId) throws Exception {
12131202 final String samlResponseParameter = httpRequest .getParameter ("SAMLResponse" );
12141203
12151204 if (samlResponseParameter != null ) {
1216- SamlResponse samlResponse = samlResponseFactory . create (settings , httpRequest );
1205+ SamlResponse samlResponse = samlMessageFactory . createSamlResponse (settings , httpRequest );
12171206 lastResponse = samlResponse .getSAMLResponseXml ();
12181207
12191208 if (samlResponse .isValid (requestId )) {
@@ -1286,7 +1275,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
12861275 final String samlResponseParameter = httpRequest .getParameter ("SAMLResponse" );
12871276
12881277 if (samlResponseParameter != null ) {
1289- LogoutResponse logoutResponse = receivedLogoutResponseFactory . create (settings , httpRequest );
1278+ LogoutResponse logoutResponse = samlMessageFactory . createIncomingLogoutResponse (settings , httpRequest );
12901279 lastResponse = logoutResponse .getLogoutResponseXml ();
12911280 if (!logoutResponse .isValid (requestId )) {
12921281 errors .add ("invalid_logout_response" );
@@ -1316,7 +1305,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
13161305 }
13171306 return null ;
13181307 } else if (samlRequestParameter != null ) {
1319- LogoutRequest logoutRequest = receivedLogoutRequestFactory . create (settings , httpRequest );
1308+ LogoutRequest logoutRequest = samlMessageFactory . createIncomingLogoutRequest (settings , httpRequest );
13201309 lastRequest = logoutRequest .getLogoutRequestXml ();
13211310 if (!logoutRequest .isValid ()) {
13221311 errors .add ("invalid_logout_request" );
@@ -1334,7 +1323,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
13341323 }
13351324
13361325 String inResponseTo = logoutRequest .id ;
1337- LogoutResponse logoutResponseBuilder = outgoingLogoutResponseFactory . create (settings ,
1326+ LogoutResponse logoutResponseBuilder = samlMessageFactory . createOutgoingLogoutResponse (settings ,
13381327 new LogoutResponseParams (inResponseTo , Constants .STATUS_SUCCESS ));
13391328 lastResponse = logoutResponseBuilder .getLogoutResponseXml ();
13401329
@@ -1663,107 +1652,19 @@ public String getLastResponseXML() {
16631652 }
16641653
16651654 /**
1666- * Sets the factory this {@link Auth} will use to create {@link AuthnRequest}
1667- * objects.
1655+ * Sets the factory this {@link Auth} will use to create SAML messages.
16681656 * <p>
1669- * This allows consumers to provide their own extension of {@link AuthnRequest}
1670- * possibly implementing custom features and/or XML post- processing.
1657+ * This allows consumers to provide their own extension classes for SAML message
1658+ * XML generation and/or processing.
16711659 *
1672- * @param authnRequestFactory
1673- * the factory to use to create {@link AuthnRequest} objects; if
1660+ * @param samlMessageFactory
1661+ * the factory to use to create SAML message objects; if
16741662 * <code>null</code>, a default provider will be used which creates
1675- * plain {@link AuthnRequest} instances
1663+ * the standard message implementation provided by this library
1664+ * (i.e.: {@link AuthnRequest}, {@link SamlResponse},
1665+ * {@link LogoutRequest} and {@link LogoutResponse})
16761666 */
1677- public void setAuthnRequestFactory (
1678- final SamlOutgoingMessageFactory <AuthnRequestParams , AuthnRequest > authnRequestFactory ) {
1679- this .authnRequestFactory = authnRequestFactory != null ? authnRequestFactory
1680- : DEFAULT_AUTHN_REQUEST_FACTORY ;
1681- }
1682-
1683- /**
1684- * Sets the factory this {@link Auth} will use to create {@link SamlResponse}
1685- * objects.
1686- * <p>
1687- * This allows consumers to provide their own extension of {@link SamlResponse}
1688- * possibly implementing custom features and/or XML validation.
1689- *
1690- * @param samlResponseFactory
1691- * the factory to use to create {@link SamlResponse} objects; if
1692- * <code>null</code>, a default factory will be used which creates
1693- * plain {@link SamlResponse} instances
1694- */
1695- public void setSamlResponseFactory (final SamlReceivedMessageFactory <SamlResponse > samlResponseFactory ) {
1696- this .samlResponseFactory = samlResponseFactory != null ? samlResponseFactory : DEFAULT_SAML_RESPONSE_FACTORY ;
1697- }
1698-
1699- /**
1700- * Sets the factory this {@link Auth} will use to create outgoing
1701- * {@link LogoutRequest} objects.
1702- * <p>
1703- * This allows consumers to provide their own extension of {@link LogoutRequest}
1704- * possibly implementing custom features and/or XML post-processing.
1705- *
1706- * @param outgoingLogoutRequestFactory
1707- * the factory to use to create outgoing {@link LogoutRequest}
1708- * objects; if <code>null</code>, a default provider will be used
1709- * which creates plain {@link LogoutRequest} instances
1710- */
1711- public void setOutgoingLogoutRequestFactory (final
1712- SamlOutgoingMessageFactory <LogoutRequestParams , LogoutRequest > outgoingLogoutRequestFactory ) {
1713- this .outgoingLogoutRequestFactory = outgoingLogoutRequestFactory != null ? outgoingLogoutRequestFactory : DEFAULT_OUTGOING_LOGOUT_REQUEST_FACTORY ;
1714- }
1715-
1716- /**
1717- * Sets the factory this {@link Auth} will use to create received
1718- * {@link LogoutRequest} objects.
1719- * <p>
1720- * This allows consumers to provide their own extension of {@link LogoutRequest}
1721- * possibly implementing custom features and/or XML validation.
1722- *
1723- * @param receivedLogoutRequestFactory
1724- * the factory to use to create received {@link LogoutRequest}
1725- * objects; if <code>null</code>, a default provider will be used
1726- * which creates plain {@link LogoutRequest} instances
1727- */
1728- public void setReceivedLogoutRequestFactory (
1729- final SamlReceivedMessageFactory <LogoutRequest > receivedLogoutRequestFactory ) {
1730- this .receivedLogoutRequestFactory = receivedLogoutRequestFactory != null ? receivedLogoutRequestFactory
1731- : DEFAULT_RECEIVED_LOGOUT_REQUEST_FACTORY ;
1732- }
1733-
1734- /**
1735- * Sets the factory this {@link Auth} will use to create outgoing
1736- * {@link LogoutResponse} objects.
1737- * <p>
1738- * This allows consumers to provide their own extension of
1739- * {@link LogoutResponse} possibly implementing custom features and/or XML
1740- * post-processing.
1741- *
1742- * @param outgoingLogoutResponseFactory
1743- * the factory to use to create outgoing {@link LogoutResponse}
1744- * objects; if <code>null</code>, a default provider will be used
1745- * which creates plain {@link LogoutResponse} instances
1746- */
1747- public void setOutgoingLogoutResponseFactory (final
1748- SamlOutgoingMessageFactory <LogoutResponseParams , LogoutResponse > outgoingLogoutResponseFactory ) {
1749- this .outgoingLogoutResponseFactory = outgoingLogoutResponseFactory != null ? outgoingLogoutResponseFactory : DEFAULT_OUTGOING_LOGOUT_RESPONSE_FACTORY ;
1750- }
1751-
1752- /**
1753- * Sets the factory this {@link Auth} will use to create received
1754- * {@link LogoutResponse} objects.
1755- * <p>
1756- * This allows consumers to provide their own extension of
1757- * {@link LogoutResponse} possibly implementing custom features and/or XML
1758- * validation.
1759- *
1760- * @param receivedLogoutResponseFactory
1761- * the factory to use to create received {@link LogoutResponse}
1762- * objects; if <code>null</code>, a default provider will be used
1763- * which creates plain {@link LogoutResponse} instances
1764- */
1765- public void setReceivedLogoutResponseFactory (final
1766- SamlReceivedMessageFactory <LogoutResponse > receivedLogoutResponseFactory ) {
1767- this .receivedLogoutResponseFactory = receivedLogoutResponseFactory != null ? receivedLogoutResponseFactory : DEFAULT_RECEIVED_LOGOUT_RESPONSE_FACTORY ;
1667+ public void setSamlMessageFactory (final SamlMessageFactory samlMessageFactory ) {
1668+ this .samlMessageFactory = samlMessageFactory != null ? samlMessageFactory : DEFAULT_SAML_MESSAGE_FACTORY ;
17681669 }
17691670}
0 commit comments