@@ -42,26 +42,6 @@ public class AuthnRequest {
42
42
*/
43
43
private final Saml2Settings settings ;
44
44
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
-
65
45
/**
66
46
* Time stamp that indicates when the AuthNRequest was created
67
47
*/
@@ -72,55 +52,73 @@ public class AuthnRequest {
72
52
*
73
53
* @param settings
74
54
* OneLogin_Saml2_Settings
55
+ * @see #AuthnRequest(Saml2Settings, AuthnRequestParams)
75
56
*/
76
57
public AuthnRequest (Saml2Settings settings ) {
77
- this (settings , false , false , true );
58
+ this (settings , new AuthnRequestParams ( false , false , true ) );
78
59
}
79
60
80
61
/**
81
62
* Constructs the AuthnRequest object.
82
63
*
83
64
* @param settings
84
- * OneLogin_Saml2_Settings
65
+ * OneLogin_Saml2_Settings
85
66
* @param forceAuthn
86
- * When true the AuthNReuqest will set the ForceAuthn='true'
67
+ * When true the AuthNReuqest will set the ForceAuthn='true'
87
68
* @param isPassive
88
- * When true the AuthNReuqest will set the IsPassive='true'
69
+ * When true the AuthNReuqest will set the IsPassive='true'
89
70
* @param setNameIdPolicy
90
- * When true the AuthNReuqest will set a nameIdPolicy
71
+ * When true the AuthNReuqest will set a nameIdPolicy
91
72
* @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
93
77
*/
78
+ @ Deprecated
94
79
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 ));
106
81
}
107
-
82
+
108
83
/**
109
84
* Constructs the AuthnRequest object.
110
85
*
111
86
* @param settings
112
- * OneLogin_Saml2_Settings
87
+ * OneLogin_Saml2_Settings
113
88
* @param forceAuthn
114
- * When true the AuthNReuqest will set the ForceAuthn='true'
89
+ * When true the AuthNReuqest will set the ForceAuthn='true'
115
90
* @param isPassive
116
- * When true the AuthNReuqest will set the IsPassive='true'
91
+ * When true the AuthNReuqest will set the IsPassive='true'
117
92
* @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
119
97
*/
98
+ @ Deprecated
120
99
public AuthnRequest (Saml2Settings settings , boolean forceAuthn , boolean isPassive , boolean setNameIdPolicy ) {
121
100
this (settings , forceAuthn , isPassive , setNameIdPolicy , null );
122
101
}
123
102
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
+
124
122
/**
125
123
* Allows for an extension class to post-process the AuthnRequest XML generated
126
124
* for this request, in order to customize the result.
@@ -132,15 +130,17 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
132
130
* @param authnRequestXml
133
131
* the XML produced for this AuthnRequest by the standard
134
132
* implementation provided by {@link AuthnRequest}
133
+ * @param params
134
+ * the authentication request input parameters
135
135
* @param settings
136
136
* the settings
137
137
* @return the post-processed XML for this AuthnRequest, which will then be
138
138
* returned by any call to {@link #getAuthnRequestXml()}
139
139
*/
140
- protected String postProcessXml (final String authnRequestXml , final Saml2Settings settings ) {
140
+ protected String postProcessXml (final String authnRequestXml , final AuthnRequestParams params , final Saml2Settings settings ) {
141
141
return authnRequestXml ;
142
142
}
143
-
143
+
144
144
/**
145
145
* @return the base64 encoded unsigned AuthnRequest (deflated or not)
146
146
*
@@ -181,22 +181,24 @@ public String getAuthnRequestXml() {
181
181
/**
182
182
* Substitutes AuthnRequest variables within a string by values.
183
183
*
184
+ * @param params
185
+ * the authentication request input parameters
184
186
* @param settings
185
187
* Saml2Settings object. Setting data
186
188
*
187
189
* @return the StrSubstitutor object of the AuthnRequest
188
190
*/
189
- private StrSubstitutor generateSubstitutor (Saml2Settings settings ) {
191
+ private StrSubstitutor generateSubstitutor (AuthnRequestParams params , Saml2Settings settings ) {
190
192
191
193
Map <String , String > valueMap = new HashMap <String , String >();
192
194
193
195
String forceAuthnStr = "" ;
194
- if (forceAuthn ) {
196
+ if (params . isForceAuthn () ) {
195
197
forceAuthnStr = " ForceAuthn=\" true\" " ;
196
198
}
197
199
198
200
String isPassiveStr = "" ;
199
- if (isPassive ) {
201
+ if (params . isPassive () ) {
200
202
isPassiveStr = " IsPassive=\" true\" " ;
201
203
}
202
204
@@ -211,6 +213,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
211
213
valueMap .put ("destinationStr" , destinationStr );
212
214
213
215
String subjectStr = "" ;
216
+ String nameIdValueReq = params .getNameIdValueReq ();
214
217
if (nameIdValueReq != null && !nameIdValueReq .isEmpty ()) {
215
218
String nameIDFormat = settings .getSpNameIDFormat ();
216
219
subjectStr = "<saml:Subject>" ;
@@ -221,7 +224,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
221
224
valueMap .put ("subjectStr" , subjectStr );
222
225
223
226
String nameIDPolicyStr = "" ;
224
- if (setNameIdPolicy ) {
227
+ if (params . isSetNameIdPolicy () ) {
225
228
String nameIDPolicyFormat = settings .getSpNameIDFormat ();
226
229
if (settings .getWantNameIdEncrypted ()) {
227
230
nameIDPolicyFormat = Constants .NAMEID_ENCRYPTED ;
0 commit comments