All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.restassured.authentication.FormAuthConfig Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jayway.restassured.authentication;

import static com.jayway.restassured.internal.assertion.AssertParameter.notNull;

/**
 * Configuration of form authentication to correctly identify which form that contains the username and password
 * and the action of the form.
 */
public class FormAuthConfig {
    private final String formAction;
    private final String userInputTagName;
    private final String passwordInputTagName;

    /**
     * Create a form auth config with a pre-defined form action, username input tag, password input tag.
     * E.g. let's say that the login form on your login page looks like this:
     * 
     *  <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. * * @param formAction The action of the form * @param userNameInputTagName The name of the username input tag in the login form * @param passwordInputTagName The name of the password input tag in the login form */ public FormAuthConfig(String formAction, String userNameInputTagName, String passwordInputTagName) { notNull(formAction, "Form action"); notNull(userNameInputTagName, "User input tag name"); notNull(passwordInputTagName, "Password input tag name"); this.formAction = formAction; this.userInputTagName = userNameInputTagName; this.passwordInputTagName = passwordInputTagName; } /** * @return A predefined form authentication config for default Spring Security configuration (tested in version 3.0.5). */ public static FormAuthConfig springSecurity() { return new FormAuthConfig("/j_spring_security_check", "j_username", "j_password"); } public String getFormAction() { return formAction; } public String getUserInputTagName() { return userInputTagName; } public String getPasswordInputTagName() { return passwordInputTagName; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy