001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.http.control;
020:
021: import java.io.Serializable;
022:
023: import org.apache.jmeter.config.ConfigElement;
024: import org.apache.jmeter.protocol.http.util.Base64Encoder;
025: import org.apache.jmeter.testelement.AbstractTestElement;
026:
027: /**
028: * This class is an Authorization encapsulator.
029: *
030: * author <a href="mailto:luta.raphael@networks.vivendi.net">Raphael Luta</a>
031: */
032: public class Authorization extends AbstractTestElement implements
033: Serializable {
034:
035: private static String URL = "Authorization.url"; // $NON-NLS-1$
036:
037: private static String USERNAME = "Authorization.username"; // $NON-NLS-1$
038:
039: private static String PASSWORD = "Authorization.password"; // $NON-NLS-1$
040:
041: private static String DOMAIN = "Authorization.domain"; // $NON-NLS-1$
042:
043: private static String REALM = "Authorization.realm"; // $NON-NLS-1$
044:
045: private static final String TAB = "\t"; // $NON-NLS-1$
046:
047: /**
048: * create the authorization
049: */
050: Authorization(String url, String user, String pass, String domain,
051: String realm) {
052: setURL(url);
053: setUser(user);
054: setPass(pass);
055: setDomain(domain);
056: setRealm(realm);
057: }
058:
059: public boolean expectsModification() {
060: return false;
061: }
062:
063: public Authorization() {
064: this ("", "", "", "", "");
065: }
066:
067: public void addConfigElement(ConfigElement config) {
068: }
069:
070: public synchronized String getURL() {
071: return getPropertyAsString(URL);
072: }
073:
074: public synchronized void setURL(String url) {
075: setProperty(URL, url);
076: }
077:
078: public synchronized String getUser() {
079: return getPropertyAsString(USERNAME);
080: }
081:
082: public synchronized void setUser(String user) {
083: setProperty(USERNAME, user);
084: }
085:
086: public synchronized String getPass() {
087: return getPropertyAsString(PASSWORD);
088: }
089:
090: public synchronized void setPass(String pass) {
091: setProperty(PASSWORD, pass);
092: }
093:
094: public synchronized String getDomain() {
095: return getPropertyAsString(DOMAIN);
096: }
097:
098: public synchronized void setDomain(String domain) {
099: setProperty(DOMAIN, domain);
100: }
101:
102: public synchronized String getRealm() {
103: return getPropertyAsString(REALM);
104: }
105:
106: public synchronized void setRealm(String realm) {
107: setProperty(REALM, realm);
108: }
109:
110: // Used for saving entries to a file
111: public String toString() {
112: return getURL() + TAB + getUser() + TAB + getPass() + TAB
113: + getDomain() + TAB + getRealm();
114: }
115:
116: public String toBasicHeader() {
117: return "Basic "
118: + Base64Encoder.encode(getUser() + ":" + getPass());
119: }
120: }
|