Visitar URL original
Java GSS (#7541) · pratikgithub/tutorials@243882b · GitHub
Skip to content

Commit 243882b

Browse files
kcacademicpivovarit
authored andcommitted
Java GSS (eugenp#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.
1 parent 43ec1a7 commit 243882b

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

‎core-java-modules/core-java-security/src/test/java/com/baeldung/jgss/JgssIntegrationTest.java‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@Ignore
2121
public class JgssIntegrationTest {
22-
22+
2323
private static final String SERVER_PRINCIPAL = "HTTP/localhost@EXAMPLE.COM";
2424
private static final String MECHANISM = "1.2.840.113554.1.2.2";
2525

@@ -33,36 +33,45 @@ public void setUp() throws SaslException, GSSException {
3333
String serverPrinciple = SERVER_PRINCIPAL;
3434
GSSName serverName = manager.createName(serverPrinciple, null);
3535
Oid krb5Oid = new Oid(MECHANISM);
36-
clientContext = manager.createContext(
37-
serverName, krb5Oid, (GSSCredential) null, GSSContext.DEFAULT_LIFETIME);
36+
clientContext = manager.createContext(serverName, krb5Oid, (GSSCredential) null, GSSContext.DEFAULT_LIFETIME);
3837
clientContext.requestMutualAuth(true);
3938
clientContext.requestConf(true);
4039
clientContext.requestInteg(true);
4140
}
4241

4342
@Test
4443
public void givenCredential_whenStarted_thenAutenticationWorks() throws SaslException, GSSException {
45-
byte[] serverToken = new byte[0];
46-
byte[] clientToken = new byte[0];
47-
clientToken = clientContext.initSecContext(clientToken, 0, clientToken.length);
48-
serverToken = clientToken;
49-
serverToken = serverContext.acceptSecContext(serverToken, 0, serverToken.length);
50-
clientToken = serverToken;
51-
clientToken = clientContext.initSecContext(clientToken, 0, clientToken.length);
44+
byte[] serverToken;
45+
byte[] clientToken;
46+
47+
// On the client-side
48+
clientToken = clientContext.initSecContext(new byte[0], 0, 0);
49+
// sendToServer(clientToken); // This is supposed to be send over the network
50+
51+
// On the server-side
52+
serverToken = serverContext.acceptSecContext(clientToken, 0, clientToken.length);
53+
// sendToClient(serverToken); // This is supposed to be send over the network
54+
55+
// Back on the client-side
56+
clientContext.initSecContext(serverToken, 0, serverToken.length);
57+
5258
assertTrue(serverContext.isEstablished());
5359
assertTrue(clientContext.isEstablished());
5460
}
5561

5662
@Test
5763
public void givenContext_whenStarted_thenSecurityWorks() throws SaslException, GSSException {
64+
// On the client-side
5865
byte[] messageBytes = "Baeldung".getBytes();
5966
MessageProp clientProp = new MessageProp(0, true);
6067
byte[] clientToken = clientContext.wrap(messageBytes, 0, messageBytes.length, clientProp);
61-
byte[] serverToken = clientToken;
68+
// sendToServer(clientToken); // This is supposed to be send over the network
69+
70+
// On the server-side
6271
MessageProp serverProp = new MessageProp(0, false);
63-
byte[] bytes = serverContext.unwrap(serverToken, 0, serverToken.length, serverProp);
64-
clientContext.verifyMIC(serverToken, 0, serverToken.length, bytes, 0, bytes.length, serverProp);
72+
byte[] bytes = serverContext.unwrap(clientToken, 0, clientToken.length, serverProp);
6573
String string = new String(bytes);
74+
6675
assertEquals("Baeldung", string);
6776
}
6877

0 commit comments

Comments
 (0)