Java GSS (#7541)
* Adding source code for tutorial tracked under BAEL-3171. * Incorporated review comments on the article. * Resolved merge conflicts. * Incorporated review comments on the article.
This commit is contained in:
parent
43ec1a7a60
commit
243882bf15
@ -33,8 +33,7 @@ public class JgssIntegrationTest {
|
|||||||
String serverPrinciple = SERVER_PRINCIPAL;
|
String serverPrinciple = SERVER_PRINCIPAL;
|
||||||
GSSName serverName = manager.createName(serverPrinciple, null);
|
GSSName serverName = manager.createName(serverPrinciple, null);
|
||||||
Oid krb5Oid = new Oid(MECHANISM);
|
Oid krb5Oid = new Oid(MECHANISM);
|
||||||
clientContext = manager.createContext(
|
clientContext = manager.createContext(serverName, krb5Oid, (GSSCredential) null, GSSContext.DEFAULT_LIFETIME);
|
||||||
serverName, krb5Oid, (GSSCredential) null, GSSContext.DEFAULT_LIFETIME);
|
|
||||||
clientContext.requestMutualAuth(true);
|
clientContext.requestMutualAuth(true);
|
||||||
clientContext.requestConf(true);
|
clientContext.requestConf(true);
|
||||||
clientContext.requestInteg(true);
|
clientContext.requestInteg(true);
|
||||||
@ -42,27 +41,37 @@ public class JgssIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCredential_whenStarted_thenAutenticationWorks() throws SaslException, GSSException {
|
public void givenCredential_whenStarted_thenAutenticationWorks() throws SaslException, GSSException {
|
||||||
byte[] serverToken = new byte[0];
|
byte[] serverToken;
|
||||||
byte[] clientToken = new byte[0];
|
byte[] clientToken;
|
||||||
clientToken = clientContext.initSecContext(clientToken, 0, clientToken.length);
|
|
||||||
serverToken = clientToken;
|
// On the client-side
|
||||||
serverToken = serverContext.acceptSecContext(serverToken, 0, serverToken.length);
|
clientToken = clientContext.initSecContext(new byte[0], 0, 0);
|
||||||
clientToken = serverToken;
|
// sendToServer(clientToken); // This is supposed to be send over the network
|
||||||
clientToken = clientContext.initSecContext(clientToken, 0, clientToken.length);
|
|
||||||
|
// On the server-side
|
||||||
|
serverToken = serverContext.acceptSecContext(clientToken, 0, clientToken.length);
|
||||||
|
// sendToClient(serverToken); // This is supposed to be send over the network
|
||||||
|
|
||||||
|
// Back on the client-side
|
||||||
|
clientContext.initSecContext(serverToken, 0, serverToken.length);
|
||||||
|
|
||||||
assertTrue(serverContext.isEstablished());
|
assertTrue(serverContext.isEstablished());
|
||||||
assertTrue(clientContext.isEstablished());
|
assertTrue(clientContext.isEstablished());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenContext_whenStarted_thenSecurityWorks() throws SaslException, GSSException {
|
public void givenContext_whenStarted_thenSecurityWorks() throws SaslException, GSSException {
|
||||||
|
// On the client-side
|
||||||
byte[] messageBytes = "Baeldung".getBytes();
|
byte[] messageBytes = "Baeldung".getBytes();
|
||||||
MessageProp clientProp = new MessageProp(0, true);
|
MessageProp clientProp = new MessageProp(0, true);
|
||||||
byte[] clientToken = clientContext.wrap(messageBytes, 0, messageBytes.length, clientProp);
|
byte[] clientToken = clientContext.wrap(messageBytes, 0, messageBytes.length, clientProp);
|
||||||
byte[] serverToken = clientToken;
|
// sendToServer(clientToken); // This is supposed to be send over the network
|
||||||
|
|
||||||
|
// On the server-side
|
||||||
MessageProp serverProp = new MessageProp(0, false);
|
MessageProp serverProp = new MessageProp(0, false);
|
||||||
byte[] bytes = serverContext.unwrap(serverToken, 0, serverToken.length, serverProp);
|
byte[] bytes = serverContext.unwrap(clientToken, 0, clientToken.length, serverProp);
|
||||||
clientContext.verifyMIC(serverToken, 0, serverToken.length, bytes, 0, bytes.length, serverProp);
|
|
||||||
String string = new String(bytes);
|
String string = new String(bytes);
|
||||||
|
|
||||||
assertEquals("Baeldung", string);
|
assertEquals("Baeldung", string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user