26
26
import com .onelogin .saml2 .authn .AuthnRequestParams ;
27
27
import com .onelogin .saml2 .authn .SamlResponse ;
28
28
import 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 ;
31
30
import com .onelogin .saml2 .exception .Error ;
32
31
import com .onelogin .saml2 .http .HttpRequest ;
33
32
import com .onelogin .saml2 .logout .LogoutRequest ;
@@ -171,19 +170,9 @@ public class Auth {
171
170
*/
172
171
private String lastResponse ;
173
172
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 () {};
180
174
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 ;
187
176
188
177
/**
189
178
* Initializes the SP SAML instance.
@@ -626,7 +615,7 @@ public String login(String relayState, AuthnRequestParams authnRequestParams, Bo
626
615
* @throws SettingsException
627
616
*/
628
617
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 );
630
619
631
620
if (parameters == null ) {
632
621
parameters = new HashMap <String , String >();
@@ -802,7 +791,7 @@ public String logout(String relayState, LogoutRequestParams logoutRequestParams,
802
791
parameters = new HashMap <String , String >();
803
792
}
804
793
805
- LogoutRequest logoutRequest = outgoingLogoutRequestFactory . create (settings , logoutRequestParams );
794
+ LogoutRequest logoutRequest = samlMessageFactory . createOutgoingLogoutRequest (settings , logoutRequestParams );
806
795
String samlLogoutRequest = logoutRequest .getEncodedLogoutRequest ();
807
796
parameters .put ("SAMLRequest" , samlLogoutRequest );
808
797
@@ -1213,7 +1202,7 @@ public void processResponse(String requestId) throws Exception {
1213
1202
final String samlResponseParameter = httpRequest .getParameter ("SAMLResponse" );
1214
1203
1215
1204
if (samlResponseParameter != null ) {
1216
- SamlResponse samlResponse = samlResponseFactory . create (settings , httpRequest );
1205
+ SamlResponse samlResponse = samlMessageFactory . createSamlResponse (settings , httpRequest );
1217
1206
lastResponse = samlResponse .getSAMLResponseXml ();
1218
1207
1219
1208
if (samlResponse .isValid (requestId )) {
@@ -1286,7 +1275,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
1286
1275
final String samlResponseParameter = httpRequest .getParameter ("SAMLResponse" );
1287
1276
1288
1277
if (samlResponseParameter != null ) {
1289
- LogoutResponse logoutResponse = receivedLogoutResponseFactory . create (settings , httpRequest );
1278
+ LogoutResponse logoutResponse = samlMessageFactory . createIncomingLogoutResponse (settings , httpRequest );
1290
1279
lastResponse = logoutResponse .getLogoutResponseXml ();
1291
1280
if (!logoutResponse .isValid (requestId )) {
1292
1281
errors .add ("invalid_logout_response" );
@@ -1316,7 +1305,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
1316
1305
}
1317
1306
return null ;
1318
1307
} else if (samlRequestParameter != null ) {
1319
- LogoutRequest logoutRequest = receivedLogoutRequestFactory . create (settings , httpRequest );
1308
+ LogoutRequest logoutRequest = samlMessageFactory . createIncomingLogoutRequest (settings , httpRequest );
1320
1309
lastRequest = logoutRequest .getLogoutRequestXml ();
1321
1310
if (!logoutRequest .isValid ()) {
1322
1311
errors .add ("invalid_logout_request" );
@@ -1334,7 +1323,7 @@ public String processSLO(Boolean keepLocalSession, String requestId, Boolean sta
1334
1323
}
1335
1324
1336
1325
String inResponseTo = logoutRequest .id ;
1337
- LogoutResponse logoutResponseBuilder = outgoingLogoutResponseFactory . create (settings ,
1326
+ LogoutResponse logoutResponseBuilder = samlMessageFactory . createOutgoingLogoutResponse (settings ,
1338
1327
new LogoutResponseParams (inResponseTo , Constants .STATUS_SUCCESS ));
1339
1328
lastResponse = logoutResponseBuilder .getLogoutResponseXml ();
1340
1329
@@ -1663,107 +1652,19 @@ public String getLastResponseXML() {
1663
1652
}
1664
1653
1665
1654
/**
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.
1668
1656
* <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.
1671
1659
*
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
1674
1662
* <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})
1676
1666
*/
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 ;
1768
1669
}
1769
1670
}
0 commit comments