@@ -42,26 +42,6 @@ public class AuthnRequest {
4242 */
4343 private final Saml2Settings settings ;
4444
45- /**
46- * When true the AuthNRequest will set the ForceAuthn='true'
47- */
48- private final boolean forceAuthn ;
49-
50- /**
51- * When true the AuthNRequest will set the IsPassive='true'
52- */
53- private final boolean isPassive ;
54-
55- /**
56- * When true the AuthNReuqest will set a nameIdPolicy
57- */
58- private final boolean setNameIdPolicy ;
59-
60- /**
61- * Indicates to the IdP the subject that should be authenticated
62- */
63- private final String nameIdValueReq ;
64-
6545 /**
6646 * Time stamp that indicates when the AuthNRequest was created
6747 */
@@ -72,55 +52,73 @@ public class AuthnRequest {
7252 *
7353 * @param settings
7454 * OneLogin_Saml2_Settings
55+ * @see #AuthnRequest(Saml2Settings, AuthnRequestParams)
7556 */
7657 public AuthnRequest (Saml2Settings settings ) {
77- this (settings , false , false , true );
58+ this (settings , new AuthnRequestParams ( false , false , true ) );
7859 }
7960
8061 /**
8162 * Constructs the AuthnRequest object.
8263 *
8364 * @param settings
84- * OneLogin_Saml2_Settings
65+ * OneLogin_Saml2_Settings
8566 * @param forceAuthn
86- * When true the AuthNReuqest will set the ForceAuthn='true'
67+ * When true the AuthNReuqest will set the ForceAuthn='true'
8768 * @param isPassive
88- * When true the AuthNReuqest will set the IsPassive='true'
69+ * When true the AuthNReuqest will set the IsPassive='true'
8970 * @param setNameIdPolicy
90- * When true the AuthNReuqest will set a nameIdPolicy
71+ * When true the AuthNReuqest will set a nameIdPolicy
9172 * @param nameIdValueReq
92- * Indicates to the IdP the subject that should be authenticated
73+ * Indicates to the IdP the subject that should be authenticated
74+ * @deprecated use {@link #AuthnRequest(Saml2Settings, AuthnRequestParams)} with
75+ * {@link AuthnRequestParams#AuthnRequestParams(boolean, boolean, boolean, String)}
76+ * instead
9377 */
78+ @ Deprecated
9479 public AuthnRequest (Saml2Settings settings , boolean forceAuthn , boolean isPassive , boolean setNameIdPolicy , String nameIdValueReq ) {
95- this .id = Util .generateUniqueID (settings .getUniqueIDPrefix ());
96- issueInstant = Calendar .getInstance ();
97- this .isPassive = isPassive ;
98- this .settings = settings ;
99- this .forceAuthn = forceAuthn ;
100- this .setNameIdPolicy = setNameIdPolicy ;
101- this .nameIdValueReq = nameIdValueReq ;
102-
103- StrSubstitutor substitutor = generateSubstitutor (settings );
104- authnRequestString = postProcessXml (substitutor .replace (getAuthnRequestTemplate ()), settings );
105- LOGGER .debug ("AuthNRequest --> " + authnRequestString );
80+ this (settings , new AuthnRequestParams (forceAuthn , isPassive , setNameIdPolicy , nameIdValueReq ));
10681 }
107-
82+
10883 /**
10984 * Constructs the AuthnRequest object.
11085 *
11186 * @param settings
112- * OneLogin_Saml2_Settings
87+ * OneLogin_Saml2_Settings
11388 * @param forceAuthn
114- * When true the AuthNReuqest will set the ForceAuthn='true'
89+ * When true the AuthNReuqest will set the ForceAuthn='true'
11590 * @param isPassive
116- * When true the AuthNReuqest will set the IsPassive='true'
91+ * When true the AuthNReuqest will set the IsPassive='true'
11792 * @param setNameIdPolicy
118- * When true the AuthNReuqest will set a nameIdPolicy
93+ * When true the AuthNReuqest will set a nameIdPolicy
94+ * @deprecated use {@link #AuthnRequest(Saml2Settings, AuthnRequestParams)} with
95+ * {@link AuthnRequestParams#AuthnRequestParams(boolean, boolean, boolean)}
96+ * instead
11997 */
98+ @ Deprecated
12099 public AuthnRequest (Saml2Settings settings , boolean forceAuthn , boolean isPassive , boolean setNameIdPolicy ) {
121100 this (settings , forceAuthn , isPassive , setNameIdPolicy , null );
122101 }
123102
103+ /**
104+ * Constructs the AuthnRequest object.
105+ *
106+ * @param settings
107+ * OneLogin_Saml2_Settings
108+ * @param params
109+ * a set of authentication request input parameters that shape the
110+ * request to create
111+ */
112+ public AuthnRequest (Saml2Settings settings , AuthnRequestParams params ) {
113+ this .id = Util .generateUniqueID (settings .getUniqueIDPrefix ());
114+ issueInstant = Calendar .getInstance ();
115+ this .settings = settings ;
116+
117+ StrSubstitutor substitutor = generateSubstitutor (params , settings );
118+ authnRequestString = postProcessXml (substitutor .replace (getAuthnRequestTemplate ()), params , settings );
119+ LOGGER .debug ("AuthNRequest --> " + authnRequestString );
120+ }
121+
124122 /**
125123 * Allows for an extension class to post-process the AuthnRequest XML generated
126124 * for this request, in order to customize the result.
@@ -132,15 +130,17 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
132130 * @param authnRequestXml
133131 * the XML produced for this AuthnRequest by the standard
134132 * implementation provided by {@link AuthnRequest}
133+ * @param params
134+ * the authentication request input parameters
135135 * @param settings
136136 * the settings
137137 * @return the post-processed XML for this AuthnRequest, which will then be
138138 * returned by any call to {@link #getAuthnRequestXml()}
139139 */
140- protected String postProcessXml (final String authnRequestXml , final Saml2Settings settings ) {
140+ protected String postProcessXml (final String authnRequestXml , final AuthnRequestParams params , final Saml2Settings settings ) {
141141 return authnRequestXml ;
142142 }
143-
143+
144144 /**
145145 * @return the base64 encoded unsigned AuthnRequest (deflated or not)
146146 *
@@ -181,22 +181,24 @@ public String getAuthnRequestXml() {
181181 /**
182182 * Substitutes AuthnRequest variables within a string by values.
183183 *
184+ * @param params
185+ * the authentication request input parameters
184186 * @param settings
185187 * Saml2Settings object. Setting data
186188 *
187189 * @return the StrSubstitutor object of the AuthnRequest
188190 */
189- private StrSubstitutor generateSubstitutor (Saml2Settings settings ) {
191+ private StrSubstitutor generateSubstitutor (AuthnRequestParams params , Saml2Settings settings ) {
190192
191193 Map <String , String > valueMap = new HashMap <String , String >();
192194
193195 String forceAuthnStr = "" ;
194- if (forceAuthn ) {
196+ if (params . isForceAuthn () ) {
195197 forceAuthnStr = " ForceAuthn=\" true\" " ;
196198 }
197199
198200 String isPassiveStr = "" ;
199- if (isPassive ) {
201+ if (params . isPassive () ) {
200202 isPassiveStr = " IsPassive=\" true\" " ;
201203 }
202204
@@ -211,6 +213,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
211213 valueMap .put ("destinationStr" , destinationStr );
212214
213215 String subjectStr = "" ;
216+ String nameIdValueReq = params .getNameIdValueReq ();
214217 if (nameIdValueReq != null && !nameIdValueReq .isEmpty ()) {
215218 String nameIDFormat = settings .getSpNameIDFormat ();
216219 subjectStr = "<saml:Subject>" ;
@@ -221,7 +224,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
221224 valueMap .put ("subjectStr" , subjectStr );
222225
223226 String nameIDPolicyStr = "" ;
224- if (setNameIdPolicy ) {
227+ if (params . isSetNameIdPolicy () ) {
225228 String nameIDPolicyFormat = settings .getSpNameIDFormat ();
226229 if (settings .getWantNameIdEncrypted ()) {
227230 nameIDPolicyFormat = Constants .NAMEID_ENCRYPTED ;
0 commit comments