@@ -27,17 +27,19 @@ public class PapeResponse extends PapeMessage
2727 private static final boolean DEBUG = _log .isDebugEnabled ();
2828
2929 protected final static List PAPE_FIELDS = Arrays .asList ( new String [] {
30- "auth_policies" , "auth_time" , "nist_auth_level"
30+ "auth_policies" , "auth_time" ,
3131 });
3232
33+ private static final String AUTH_POLICY_NONE = "http://schemas.openid.net/pape/policies/2007/06/none" ;
34+
3335 private static InternetDateFormat _dateFormat = new InternetDateFormat ();
3436
3537 /**
3638 * Constructs a Pape Response with an empty parameter list.
3739 */
3840 protected PapeResponse ()
3941 {
40- set ("auth_policies" , "none" );
42+ set ("auth_policies" , AUTH_POLICY_NONE );
4143
4244 if (DEBUG ) _log .debug ("Created empty PAPE response." );
4345 }
@@ -59,7 +61,7 @@ public static PapeResponse createPapeResponse()
5961 */
6062 protected PapeResponse (ParameterList params )
6163 {
62- _parameters = params ;
64+ super ( params ) ;
6365 }
6466
6567 public static PapeResponse createPapeResponse (ParameterList params )
@@ -112,7 +114,7 @@ public void addAuthPolicy(String policyUri)
112114
113115 String policies = getAuthPolicies ();
114116
115- if (policies == null || "none" .equals (policies )) // should never be null
117+ if (policies == null || AUTH_POLICY_NONE .equals (policies )) // should never be null
116118 setAuthPolicies (policyUri );
117119 else
118120 setAuthPolicies (policies + " " + policyUri );
@@ -126,7 +128,7 @@ public List getAuthPoliciesList()
126128 {
127129 String policies = getParameterValue ("auth_policies" );
128130
129- if (policies == null || "none" .equals (policies )) // should never be null
131+ if (policies == null || AUTH_POLICY_NONE .equals (policies )) // should never be null
130132 return new ArrayList ();
131133 else
132134 return Arrays .asList (policies .split (" " ));
@@ -190,33 +192,6 @@ public Date getAuthDate()
190192 return null ;
191193 }
192194
193- /**
194- * Gets the value of the nist_auth_level parameter.
195- * <p>
196- * NIST levels are integers between 1 and 4 inclusive. Level 0 is
197- * used to signify that the OP recognizes the parameter and the
198- * user authentication did not meet the requirements of Level 1.
199- *
200- * @return The NIST level, or -1 if the parameter is not set.
201- */
202- public int getNistAuthLevel ()
203- {
204- String level = getParameterValue ("nist_auth_level" );
205-
206- if ( level != null && level .length () > 0 )
207- return Integer .parseInt (level );
208- else
209- return -1 ;
210- }
211-
212- public void setNistAuthLevel (int level ) throws MessageException
213- {
214- if (level < 0 || level > 4 )
215- throw new MessageException ("Invalid NIST level: " + level );
216-
217- set ("nist_auth_level" , Integer .toString (level ));
218- }
219-
220195 /**
221196 * Checks the validity of the extension.
222197 * <p>
@@ -253,12 +228,31 @@ private void validate() throws MessageException
253228 {
254229 String paramName = ((Parameter ) it .next ()).getKey ();
255230
256- if (! PAPE_FIELDS .contains (paramName ))
257- {
258- throw new MessageException (
259- "Invalid parameter name in PAPE response: " + paramName ,
260- OpenIDException .PAPE_ERROR );
261- }
231+ if (PAPE_FIELDS .contains (paramName ) || paramName .startsWith (PapeMessage .AUTH_LEVEL_NS_PREFIX ))
232+ continue ;
233+
234+ if ( paramName .startsWith (AUTH_LEVEL_PREFIX ) &&
235+ (authLevelAliases .values ().contains (paramName .substring (AUTH_LEVEL_PREFIX .length ()))))
236+ continue ;
237+
238+ throw new MessageException (
239+ "Invalid parameter in PAPE response: " + paramName ,
240+ OpenIDException .PAPE_ERROR );
262241 }
263242 }
243+
244+ public void setCustomAuthLevel (String authLevelTypeUri , String level )
245+ {
246+ String alias = addAuthLevelExtension (authLevelTypeUri );
247+ set (AUTH_LEVEL_PREFIX + alias , level );
248+ }
249+
250+ public String getCustomAuthLevel (String authLevelTypeUri )
251+ {
252+ if (hasCustomAuthLevel (authLevelTypeUri ))
253+ return getParameterValue (AUTH_LEVEL_PREFIX + getCustomAuthLevelAlias (authLevelTypeUri ));
254+ else
255+ return null ;
256+ }
257+
264258}
0 commit comments