public class FormAuthConfig extends Object
| Constructor and Description |
|---|
FormAuthConfig()
Creates a new empty
FormAuthConfig. |
FormAuthConfig(String formAction,
String userNameInputTagName,
String passwordInputTagName)
Create a form auth config with a pre-defined form action, username input tag, password input tag.
|
| Modifier and Type | Method and Description |
|---|---|
FormAuthConfig |
and()
Syntactic sugar
|
static FormAuthConfig |
formAuthConfig()
Creates a new empty
FormAuthConfig. |
String |
getCsrfFieldName() |
String |
getFormAction() |
LogConfig |
getLogConfig() |
LogDetail |
getLogDetail() |
String |
getPasswordInputTagName() |
String |
getUserInputTagName() |
boolean |
hasCsrfFieldName() |
boolean |
hasFormAction() |
boolean |
hasPasswordInputTagName() |
boolean |
hasUserInputTagName() |
boolean |
isAutoDetectCsrfFieldName() |
boolean |
isLoggingEnabled() |
boolean |
requiresParsingOfLoginPage() |
FormAuthConfig |
sendCsrfTokenAsFormParam() |
FormAuthConfig |
sendCsrfTokenAsHeader() |
boolean |
shouldSendCsrfTokenAsFormParam() |
static FormAuthConfig |
springSecurity() |
FormAuthConfig |
withAutoDetectionOfCsrf()
Enable Cross-site request forgery (csrf) support when using form authentication by automatically trying to find the name and value of the csrf input field.
|
FormAuthConfig |
withCsrfFieldName(String fieldName)
Enable Cross-site request forgery (csrf) support when using form authentication by including the csrf value of the input field with the specified name.
|
FormAuthConfig |
withLoggingEnabled()
Enables logging with log level
LogDetail.ALL of the request made to authenticate using
form authentication. |
FormAuthConfig |
withLoggingEnabled(LogConfig logConfig)
Enables logging with log level
LogDetail.ALL of the request made to authenticate using
form authentication using the specified LogConfig. |
FormAuthConfig |
withLoggingEnabled(LogDetail logDetail)
Enables logging with the supplied logDetail of the request made to authenticate using form authentication.
|
FormAuthConfig |
withLoggingEnabled(LogDetail logDetail,
LogConfig logConfig)
Enables logging with the supplied log detail of the request made to authenticate using form authentication using the
specified
LogConfig. |
public FormAuthConfig(String formAction, String userNameInputTagName, String passwordInputTagName)
<form action="/j_spring_security_check">
<label for="j_username">Username</label>
<input type="text" name="j_username" id="j_username"/>
<br/>
<label for="j_password">Password</label>
<input type="password" name="j_password" id="j_password"/>
<br/>
<input type='checkbox' name='_spring_security_remember_me'/> Remember me on this computer.
<br/>
<input type="submit" value="Login"/>
</form>
This means that formAction should be set to /j_spring_security_check, userNameInputTagName
should be set to j_username and passwordInputTagName should be set to j_password.formAction - The action of the formuserNameInputTagName - The name of the username input tag in the login formpasswordInputTagName - The name of the password input tag in the login formpublic FormAuthConfig()
FormAuthConfig.public static FormAuthConfig springSecurity()
public FormAuthConfig withCsrfFieldName(String fieldName)
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="j_spring_security_check_with_csrf" method="POST">
<table>
<tr>
<td>User: </td>
<td><input type="text" name="j_username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="j_password"></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit"/></td>
</tr>
</table>
<input type="hidden" name="_csrf" value="8adf2ea1-b246-40aa-8e13-a85fb7914341"/>
</form>
</body>
</html>
The csrf field name is called _csrf.
Important: When enabling csrf support then REST Assured must always make an additional request to the server in order to
be able to include in the csrf value which will slow down the tests.fieldName - The csrf field name as specified in the login page.withAutoDetectionOfCsrf()public FormAuthConfig sendCsrfTokenAsHeader()
public FormAuthConfig sendCsrfTokenAsFormParam()
public FormAuthConfig withAutoDetectionOfCsrf()
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="j_spring_security_check_with_csrf" method="POST">
<table>
<tr>
<td>User: </td>
<td><input type="text" name="j_username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="j_password"></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit"/></td>
</tr>
</table>
<input type="hidden" name="_csrf" value="8adf2ea1-b246-40aa-8e13-a85fb7914341"/>
</form>
</body>
</html>
The csrf field name is called _csrf and REST Assured will autodetect its name since the field name is the only hidden field on this page.
If auto-detection fails you can consider using withCsrfFieldName(String).
Important: When enabling csrf support then REST Assured must always make an additional request to the server in order to
be able to include in the csrf value which will slow down the tests.withCsrfFieldName(String)public FormAuthConfig withLoggingEnabled()
LogDetail.ALL of the request made to authenticate using
form authentication. Both the request and the response is logged.public FormAuthConfig withLoggingEnabled(LogDetail logDetail)
public FormAuthConfig withLoggingEnabled(LogConfig logConfig)
LogDetail.ALL of the request made to authenticate using
form authentication using the specified LogConfig. Both the request and the response is logged.public FormAuthConfig withLoggingEnabled(LogDetail logDetail, LogConfig logConfig)
LogConfig. Both the request and the response is logged.public static FormAuthConfig formAuthConfig()
FormAuthConfig.public FormAuthConfig and()
public String getFormAction()
public String getUserInputTagName()
public String getPasswordInputTagName()
null if undefinedpublic LogConfig getLogConfig()
public boolean isLoggingEnabled()
true if logging is enabled or false otherwise.public LogDetail getLogDetail()
null if undefinedpublic String getCsrfFieldName()
null if undefinedpublic boolean hasCsrfFieldName()
true if csrf field name is defined or false otherwise.public boolean isAutoDetectCsrfFieldName()
true if auto detection of csrf field name is enabled, false otherwise.public boolean hasUserInputTagName()
true if the user input tag name is defined or false otherwise.public boolean hasPasswordInputTagName()
true if the password input tag name is defined or false otherwise.public boolean hasFormAction()
true if the form action is defined or false otherwise.public boolean requiresParsingOfLoginPage()
true if the FormAuthConfig instance contains settings that require REST Assured to make a request to the server before applying form authentication, false otherwise.public boolean shouldSendCsrfTokenAsFormParam()
true if the csrf token should be sent as a form param or false if it's sent as a header.Copyright © 2010–2015. All rights reserved.