Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.protocol.http.control » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    *
   17    */
   18   
   19   package org.apache.jmeter.protocol.http.control;
   20   
   21   import java.io.Serializable;
   22   
   23   import org.apache.jmeter.config.ConfigElement;
   24   import org.apache.jmeter.protocol.http.util.Base64Encoder;
   25   import org.apache.jmeter.testelement.AbstractTestElement;
   26   
   27   /**
   28    * This class is an Authorization encapsulator.
   29    *
   30    */
   31   public class Authorization extends AbstractTestElement implements Serializable {
   32   
   33       private static final String URL = "Authorization.url"; // $NON-NLS-1$
   34   
   35       private static final String USERNAME = "Authorization.username"; // $NON-NLS-1$
   36   
   37       private static final String PASSWORD = "Authorization.password"; // $NON-NLS-1$
   38   
   39       private static final String DOMAIN = "Authorization.domain"; // $NON-NLS-1$
   40   
   41       private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
   42   
   43       private static final String TAB = "\t"; // $NON-NLS-1$
   44   
   45       /**
   46        * create the authorization
   47        */
   48       Authorization(String url, String user, String pass, String domain, String realm) {
   49           setURL(url);
   50           setUser(user);
   51           setPass(pass);
   52           setDomain(domain);
   53           setRealm(realm);
   54       }
   55   
   56       public boolean expectsModification() {
   57           return false;
   58       }
   59   
   60       public Authorization() {
   61           this("","","","","");
   62       }
   63   
   64       public void addConfigElement(ConfigElement config) {
   65       }
   66   
   67       public synchronized String getURL() {
   68           return getPropertyAsString(URL);
   69       }
   70   
   71       public synchronized void setURL(String url) {
   72           setProperty(URL, url);
   73       }
   74   
   75       public synchronized String getUser() {
   76           return getPropertyAsString(USERNAME);
   77       }
   78   
   79       public synchronized void setUser(String user) {
   80           setProperty(USERNAME, user);
   81       }
   82   
   83       public synchronized String getPass() {
   84           return getPropertyAsString(PASSWORD);
   85       }
   86   
   87       public synchronized void setPass(String pass) {
   88           setProperty(PASSWORD, pass);
   89       }
   90   
   91       public synchronized String getDomain() {
   92           return getPropertyAsString(DOMAIN);
   93       }
   94   
   95       public synchronized void setDomain(String domain) {
   96           setProperty(DOMAIN, domain);
   97       }
   98   
   99       public synchronized String getRealm() {
  100           return getPropertyAsString(REALM);
  101       }
  102   
  103       public synchronized void setRealm(String realm) {
  104           setProperty(REALM, realm);
  105       }
  106   
  107       // Used for saving entries to a file
  108       public String toString() {
  109           return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm();
  110       }
  111   
  112       public String toBasicHeader(){
  113           return "Basic " + Base64Encoder.encode(getUser() + ":" + getPass());
  114       }
  115   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.protocol.http.control » [javadoc | source]