mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
Moved old obsolete stuff to sandbox.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* Interface for filtering Authenticator requests, used by the
|
||||
* SimpleAuthenticator.
|
||||
*
|
||||
* @see SimpleAuthenticator
|
||||
* @see java.net.Authenticator
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface AuthenticatorFilter {
|
||||
public boolean accept(InetAddress pAddress, int pPort, String pProtocol, String pPrompt, String pScheme);
|
||||
}
|
143
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/BASE64.java
Executable file
143
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/BASE64.java
Executable file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import com.twelvemonkeys.io.*;
|
||||
import com.twelvemonkeys.io.enc.Base64Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* This class does BASE64 encoding (and decoding).
|
||||
*
|
||||
* @author unascribed
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/BASE64.java#1 $
|
||||
* @deprecated Use {@link com.twelvemonkeys.io.enc.Base64Encoder}/{@link Base64Decoder} instead
|
||||
*/
|
||||
class BASE64 {
|
||||
/**
|
||||
* This array maps the characters to their 6 bit values
|
||||
*/
|
||||
private final static char[] PEM_ARRAY = {
|
||||
//0 1 2 3 4 5 6 7
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 1
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 2
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 3
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 4
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 5
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 6
|
||||
'4', '5', '6', '7', '8', '9', '+', '/' // 7
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes the input data using the standard base64 encoding scheme.
|
||||
*
|
||||
* @param pData the bytes to encode to base64
|
||||
* @return a string with base64 encoded data
|
||||
*/
|
||||
public static String encode(byte[] pData) {
|
||||
int offset = 0;
|
||||
int len;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
while ((pData.length - offset) > 0) {
|
||||
byte a, b, c;
|
||||
if ((pData.length - offset) > 2) {
|
||||
len = 3;
|
||||
}
|
||||
else {
|
||||
len = pData.length - offset;
|
||||
}
|
||||
|
||||
switch (len) {
|
||||
case 1:
|
||||
a = pData[offset];
|
||||
b = 0;
|
||||
buf.append(PEM_ARRAY[(a >>> 2) & 0x3F]);
|
||||
buf.append(PEM_ARRAY[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
buf.append('=');
|
||||
buf.append('=');
|
||||
offset++;
|
||||
break;
|
||||
case 2:
|
||||
a = pData[offset];
|
||||
b = pData[offset + 1];
|
||||
c = 0;
|
||||
buf.append(PEM_ARRAY[(a >>> 2) & 0x3F]);
|
||||
buf.append(PEM_ARRAY[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
buf.append(PEM_ARRAY[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
|
||||
buf.append('=');
|
||||
offset += offset + 2; // ???
|
||||
break;
|
||||
default:
|
||||
a = pData[offset];
|
||||
b = pData[offset + 1];
|
||||
c = pData[offset + 2];
|
||||
buf.append(PEM_ARRAY[(a >>> 2) & 0x3F]);
|
||||
buf.append(PEM_ARRAY[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
buf.append(PEM_ARRAY[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
|
||||
buf.append(PEM_ARRAY[c & 0x3F]);
|
||||
offset = offset + 3;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static byte[] decode(String pData) throws IOException {
|
||||
InputStream in = new DecoderStream(new ByteArrayInputStream(pData.getBytes()), new Base64Decoder());
|
||||
ByteArrayOutputStream bytes = new FastByteArrayOutputStream(pData.length() * 3);
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
|
||||
//private final static sun.misc.BASE64Decoder DECODER = new sun.misc.BASE64Decoder();
|
||||
|
||||
public static void main(String[] pArgs) throws IOException {
|
||||
if (pArgs.length == 1) {
|
||||
System.out.println(encode(pArgs[0].getBytes()));
|
||||
}
|
||||
else
|
||||
if (pArgs.length == 2 && ("-d".equals(pArgs[0]) || "--decode".equals(pArgs[0])))
|
||||
{
|
||||
System.out.println(new String(decode(pArgs[1])));
|
||||
}
|
||||
else {
|
||||
System.err.println("BASE64 [ -d | --decode ] arg");
|
||||
System.err.println("Encodes or decodes a given string");
|
||||
System.exit(5);
|
||||
}
|
||||
}
|
||||
}
|
1101
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/HttpURLConnection.java
Executable file
1101
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/HttpURLConnection.java
Executable file
File diff suppressed because it is too large
Load Diff
1258
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/NetUtil.java
Executable file
1258
sandbox/sandbox-common/src/main/java/com/twelvemonkeys/net/NetUtil.java
Executable file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* Interface fro PasswordAuthenticators used by SimpleAuthenticator.
|
||||
*
|
||||
* @see SimpleAuthenticator
|
||||
* @see java.net.Authenticator
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface PasswordAuthenticator {
|
||||
public PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme);
|
||||
}
|
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
|
||||
import java.net.Authenticator;
|
||||
import java.net.InetAddress;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A simple Authenticator implementation.
|
||||
* Singleton class, obtain reference through the static
|
||||
* {@code getInstance} method.
|
||||
* <p/>
|
||||
* <EM>After swearing, sweating, pulling my hair, banging my head repeatedly
|
||||
* into the walls and reading the java.net.Authenticator API documentation
|
||||
* once more, an idea came to my mind. This is the result. I hope you find it
|
||||
* useful. -- Harald K.</EM>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version 1.0
|
||||
* @see java.net.Authenticator
|
||||
*/
|
||||
public class SimpleAuthenticator extends Authenticator {
|
||||
/** The reference to the single instance of this class. */
|
||||
private static SimpleAuthenticator sInstance = null;
|
||||
/** Keeps track of the state of this class. */
|
||||
private static boolean sInitialized = false;
|
||||
|
||||
// These are used for the identification hack.
|
||||
private final static String MAGIC = "magic";
|
||||
private final static int FOURTYTWO = 42;
|
||||
|
||||
/** Basic authentication scheme. */
|
||||
public final static String BASIC = "Basic";
|
||||
|
||||
/** The hastable that keeps track of the PasswordAuthentications. */
|
||||
protected Map<AuthKey, PasswordAuthentication> passwordAuthentications = null;
|
||||
|
||||
/** The hastable that keeps track of the Authenticators. */
|
||||
protected Map<PasswordAuthenticator, AuthenticatorFilter> authenticators = null;
|
||||
|
||||
/** Creates a SimpleAuthenticator. */
|
||||
private SimpleAuthenticator() {
|
||||
passwordAuthentications = new HashMap<AuthKey, PasswordAuthentication>();
|
||||
authenticators = new HashMap<PasswordAuthenticator, AuthenticatorFilter>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SimpleAuthenticator instance and registers it through the
|
||||
* Authenticator.setDefault(). If there is no current instance
|
||||
* of the SimpleAuthenticator in the VM, one is created. This method will
|
||||
* try to figure out if the setDefault() succeeded (a hack), and will
|
||||
* return null if it was not able to register the instance as default.
|
||||
*
|
||||
* @return The single instance of this class, or null, if another
|
||||
* Authenticator is allready registered as default.
|
||||
*/
|
||||
public static synchronized SimpleAuthenticator getInstance() {
|
||||
if (!sInitialized) {
|
||||
// Create an instance
|
||||
sInstance = new SimpleAuthenticator();
|
||||
|
||||
// Try to set default (this may quietly fail...)
|
||||
Authenticator.setDefault(sInstance);
|
||||
|
||||
// A hack to figure out if we really did set the authenticator
|
||||
PasswordAuthentication pa = Authenticator.requestPasswordAuthentication(null, FOURTYTWO, null, null, MAGIC);
|
||||
|
||||
// If this test returns false, we didn't succeed, so we set the
|
||||
// instance back to null.
|
||||
if (pa == null || !MAGIC.equals(pa.getUserName()) || !("" + FOURTYTWO).equals(new String(pa.getPassword()))) {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
// Done
|
||||
sInitialized = true;
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PasswordAuthentication for the request. Called when password
|
||||
* authorization is needed.
|
||||
*
|
||||
* @return The PasswordAuthentication collected from the user, or null if
|
||||
* none is provided.
|
||||
*/
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
// Don't worry, this is just a hack to figure out if we were able
|
||||
// to set this Authenticator through the setDefault method.
|
||||
if (!sInitialized && MAGIC.equals(getRequestingScheme()) && getRequestingPort() == FOURTYTWO) {
|
||||
return new PasswordAuthentication(MAGIC, ("" + FOURTYTWO).toCharArray());
|
||||
}
|
||||
/*
|
||||
System.err.println("getPasswordAuthentication");
|
||||
System.err.println(getRequestingSite());
|
||||
System.err.println(getRequestingPort());
|
||||
System.err.println(getRequestingProtocol());
|
||||
System.err.println(getRequestingPrompt());
|
||||
System.err.println(getRequestingScheme());
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// Look for a more specific PasswordAuthenticatior before using
|
||||
// Default:
|
||||
//
|
||||
// if (...)
|
||||
// return pa.requestPasswordAuthentication(getRequestingSite(),
|
||||
// getRequestingPort(),
|
||||
// getRequestingProtocol(),
|
||||
// getRequestingPrompt(),
|
||||
// getRequestingScheme());
|
||||
|
||||
return passwordAuthentications.get(new AuthKey(getRequestingSite(),
|
||||
getRequestingPort(),
|
||||
getRequestingProtocol(),
|
||||
getRequestingPrompt(),
|
||||
getRequestingScheme()));
|
||||
}
|
||||
|
||||
/** Registers a PasswordAuthentication with a given URL address. */
|
||||
public PasswordAuthentication registerPasswordAuthentication(URL pURL, PasswordAuthentication pPA) {
|
||||
return registerPasswordAuthentication(NetUtil.createInetAddressFromURL(pURL),
|
||||
pURL.getPort(),
|
||||
pURL.getProtocol(),
|
||||
null, // Prompt/Realm
|
||||
BASIC,
|
||||
pPA);
|
||||
}
|
||||
|
||||
/** Registers a PasswordAuthentication with a given net address. */
|
||||
public PasswordAuthentication registerPasswordAuthentication(InetAddress pAddress, int pPort, String pProtocol, String pPrompt, String pScheme, PasswordAuthentication pPA) {
|
||||
/*
|
||||
System.err.println("registerPasswordAuthentication");
|
||||
System.err.println(pAddress);
|
||||
System.err.println(pPort);
|
||||
System.err.println(pProtocol);
|
||||
System.err.println(pPrompt);
|
||||
System.err.println(pScheme);
|
||||
*/
|
||||
|
||||
return passwordAuthentications.put(new AuthKey(pAddress, pPort, pProtocol, pPrompt, pScheme), pPA);
|
||||
}
|
||||
|
||||
/** Unregisters a PasswordAuthentication with a given URL address. */
|
||||
public PasswordAuthentication unregisterPasswordAuthentication(URL pURL) {
|
||||
return unregisterPasswordAuthentication(NetUtil.createInetAddressFromURL(pURL), pURL.getPort(), pURL.getProtocol(), null, BASIC);
|
||||
}
|
||||
|
||||
/** Unregisters a PasswordAuthentication with a given net address. */
|
||||
public PasswordAuthentication unregisterPasswordAuthentication(InetAddress pAddress, int pPort, String pProtocol, String pPrompt, String pScheme) {
|
||||
return passwordAuthentications.remove(new AuthKey(pAddress, pPort, pProtocol, pPrompt, pScheme));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Registers a PasswordAuthenticator that can answer authentication
|
||||
* requests.
|
||||
*
|
||||
* @see PasswordAuthenticator
|
||||
*/
|
||||
public void registerPasswordAuthenticator(PasswordAuthenticator pPA, AuthenticatorFilter pFilter) {
|
||||
authenticators.put(pPA, pFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Unregisters a PasswordAuthenticator that can answer authentication
|
||||
* requests.
|
||||
*
|
||||
* @see PasswordAuthenticator
|
||||
*/
|
||||
public void unregisterPasswordAuthenticator(PasswordAuthenticator pPA) {
|
||||
authenticators.remove(pPA);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class, used for caching the PasswordAuthentication objects.
|
||||
* Everything but address may be null
|
||||
*/
|
||||
class AuthKey {
|
||||
// TODO: Move this class to sandbox?
|
||||
|
||||
InetAddress address = null;
|
||||
int port = -1;
|
||||
String protocol = null;
|
||||
String prompt = null;
|
||||
String scheme = null;
|
||||
|
||||
AuthKey(InetAddress pAddress, int pPort, String pProtocol, String pPrompt, String pScheme) {
|
||||
Validate.notNull(pAddress, "address");
|
||||
|
||||
address = pAddress;
|
||||
port = pPort;
|
||||
protocol = pProtocol;
|
||||
prompt = pPrompt;
|
||||
scheme = pScheme;
|
||||
|
||||
// System.out.println("Created: " + this);
|
||||
}
|
||||
|
||||
/** Creates a string representation of this object. */
|
||||
|
||||
public String toString() {
|
||||
return "AuthKey[" + address + ":" + port + "/" + protocol + " \"" + prompt + "\" (" + scheme + ")]";
|
||||
}
|
||||
|
||||
public boolean equals(Object pObj) {
|
||||
return (pObj instanceof AuthKey && equals((AuthKey) pObj));
|
||||
}
|
||||
|
||||
// Ahem.. Breaks the rule from Object.equals(Object):
|
||||
// It is transitive: for any reference values x, y, and z, if x.equals(y)
|
||||
// returns true and y.equals(z) returns true, then x.equals(z)
|
||||
// should return true.
|
||||
|
||||
public boolean equals(AuthKey pKey) {
|
||||
// Maybe allow nulls, and still be equal?
|
||||
return (address.equals(pKey.address)
|
||||
&& (port == -1
|
||||
|| pKey.port == -1
|
||||
|| port == pKey.port)
|
||||
&& (protocol == null
|
||||
|| pKey.protocol == null
|
||||
|| protocol.equals(pKey.protocol))
|
||||
&& (prompt == null
|
||||
|| pKey.prompt == null
|
||||
|| prompt.equals(pKey.prompt))
|
||||
&& (scheme == null
|
||||
|| pKey.scheme == null
|
||||
|| scheme.equalsIgnoreCase(pKey.scheme)));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
// There won't be too many pr address, will it? ;-)
|
||||
return address.hashCode();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user