mirror of https://github.com/apache/activemq.git
AMQ-1659 Fix want/needClientAuth code and test
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@646936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
507ef42e59
commit
1da24aafe1
|
@ -106,8 +106,11 @@ public class SslTransportServer extends TcpTransportServer {
|
||||||
*/
|
*/
|
||||||
public void bind() throws IOException {
|
public void bind() throws IOException {
|
||||||
super.bind();
|
super.bind();
|
||||||
((SSLServerSocket)this.serverSocket).setWantClientAuth(wantClientAuth);
|
if (needClientAuth) {
|
||||||
((SSLServerSocket)this.serverSocket).setNeedClientAuth(needClientAuth);
|
((SSLServerSocket)this.serverSocket).setNeedClientAuth(true);
|
||||||
|
} else if (wantClientAuth) {
|
||||||
|
((SSLServerSocket)this.serverSocket).setWantClientAuth(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,35 +52,41 @@ public class SslTransportServerTest extends TestCase {
|
||||||
|
|
||||||
public void testWantAndNeedClientAuthSetters() throws IOException {
|
public void testWantAndNeedClientAuthSetters() throws IOException {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
final boolean wantClientAuth = (i & 0x1) == 1;
|
String options = "";
|
||||||
final boolean needClientAuth = (i & 0x2) == 1;
|
singleTest(i, options);
|
||||||
|
}
|
||||||
final int expectedWantStatus = wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
|
|
||||||
final int expectedNeedStatus = needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
|
|
||||||
|
|
||||||
createAndBindTransportServer(wantClientAuth, needClientAuth, "");
|
|
||||||
|
|
||||||
assertEquals("Created ServerSocket did not have correct wantClientAuth status.", sslServerSocket.getWantClientAuthStatus(), expectedWantStatus);
|
|
||||||
|
|
||||||
assertEquals("Created ServerSocket did not have correct needClientAuth status.", sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWantAndNeedAuthReflection() throws IOException {
|
public void testWantAndNeedAuthReflection() throws IOException {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
final boolean wantClientAuth = (i & 0x1) == 1;
|
String options = "wantClientAuth=" + (getWantClientAuth(i) ? "true" : "false") +
|
||||||
final boolean needClientAuth = (i & 0x2) == 1;
|
"&needClientAuth=" + (getNeedClientAuth(i) ? "true" : "false");
|
||||||
|
singleTest(i, options);
|
||||||
final int expectedWantStatus = wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
|
|
||||||
final int expectedNeedStatus = needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
|
|
||||||
|
|
||||||
String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") + "&needClientAuth=" + (needClientAuth ? "true" : "false");
|
|
||||||
|
|
||||||
createAndBindTransportServer(wantClientAuth, needClientAuth, options);
|
|
||||||
|
|
||||||
assertEquals("Created ServerSocket did not have correct wantClientAuth status.", sslServerSocket.getWantClientAuthStatus(), expectedWantStatus);
|
|
||||||
|
|
||||||
assertEquals("Created ServerSocket did not have correct needClientAuth status.", sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void singleTest(int i, String options) throws IOException {
|
||||||
|
final boolean wantClientAuth = getWantClientAuth(i);
|
||||||
|
final boolean needClientAuth = getNeedClientAuth(i);
|
||||||
|
|
||||||
|
final int expectedWantStatus = (needClientAuth? StubSSLServerSocket.UNTOUCHED: wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED);
|
||||||
|
final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED );
|
||||||
|
|
||||||
|
|
||||||
|
createAndBindTransportServer(wantClientAuth, needClientAuth, options);
|
||||||
|
|
||||||
|
assertEquals("Created ServerSocket did not have correct wantClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth,
|
||||||
|
expectedWantStatus, sslServerSocket.getWantClientAuthStatus());
|
||||||
|
|
||||||
|
assertEquals("Created ServerSocket did not have correct needClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth,
|
||||||
|
expectedNeedStatus, sslServerSocket.getNeedClientAuthStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getNeedClientAuth(int i) {
|
||||||
|
return ((i & 0x2) == 0x2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getWantClientAuth(int i) {
|
||||||
|
return ((i & 0x1) == 0x1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue