diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java b/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java index 2340831c8..452516a88 100644 --- a/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java +++ b/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java @@ -56,7 +56,7 @@ import org.apache.http.util.CharArrayBuffer; @NotThreadSafe public abstract class AuthSchemeBase implements ContextAwareAuthScheme { - private ChallengeState challengeState; + protected ChallengeState challengeState; /** * Creates an instance of {@code AuthSchemeBase} with the given challenge diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java b/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java index 8415d4810..9475c03a4 100644 --- a/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java +++ b/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java @@ -158,6 +158,7 @@ public abstract class RFC2617Scheme extends AuthSchemeBase implements Serializab private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeUTF(this.credentialsCharset.name()); + out.writeObject(this.challengeState); } @SuppressWarnings("unchecked") @@ -167,6 +168,7 @@ public abstract class RFC2617Scheme extends AuthSchemeBase implements Serializab if (this.credentialsCharset == null) { this.credentialsCharset = Consts.ASCII; } + this.challengeState = (ChallengeState) in.readObject(); } private void readObjectNoData() throws ObjectStreamException { diff --git a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java index de8808ca2..8b5d05737 100644 --- a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java +++ b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java @@ -141,7 +141,25 @@ public class TestBasicScheme { Assert.assertEquals(basicScheme.getSchemeName(), authScheme.getSchemeName()); Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm()); Assert.assertEquals(basicScheme.isComplete(), authScheme.isComplete()); + Assert.assertEquals(true, basicScheme.isProxy()); + } + @Test + public void testSerializationUnchallenged() throws Exception { + final BasicScheme basicScheme = new BasicScheme(); + + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + final ObjectOutputStream out = new ObjectOutputStream(buffer); + out.writeObject(basicScheme); + out.flush(); + final byte[] raw = buffer.toByteArray(); + final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw)); + final BasicScheme authScheme = (BasicScheme) in.readObject(); + + Assert.assertEquals(basicScheme.getSchemeName(), authScheme.getSchemeName()); + Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm()); + Assert.assertEquals(basicScheme.isComplete(), authScheme.isComplete()); + Assert.assertEquals(false, basicScheme.isProxy()); } }