Skip to content

Fix SpnegoEngine.getCompleteServicePrincipalName when servicePrincipalName is not specified. #1588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,18 @@ public String generateToken(String host) throws SpnegoEngineException {
}
}

protected String getCompleteServicePrincipalName(String host) {
String getCompleteServicePrincipalName(String host) {
String name;
if (servicePrincipalName == null) {
if (useCanonicalHostname) {
host = getCanonicalHostname(host);
}
name = "HTTP/" + host;
name = "HTTP@" + host;
} else {
name = servicePrincipalName;
}
if (realmName != null) {
name += "@" + realmName;
if (realmName != null && !name.contains("@")) {
name += "@" + realmName;
}
}
log.debug("Service Principal Name is {}", name);
return name;
Expand All @@ -285,7 +285,7 @@ private String getCanonicalHostname(String hostname) {
return canonicalHostname;
}

public CallbackHandler getUsernamePasswordHandler() {
private CallbackHandler getUsernamePasswordHandler() {
if (username == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,44 @@ public void testSpnegoGenerateTokenWithCustomLoginConfig() throws Exception {
Assert.assertTrue(token.startsWith("YII"));
}

@Test
public void testGetCompleteServicePrincipalName() throws Exception {
{
SpnegoEngine spnegoEngine = new SpnegoEngine(null,
null,
"bob",
"service.ws.apache.org",
false,
null,
null,
null);
Assert.assertEquals("[email protected]", spnegoEngine.getCompleteServicePrincipalName("localhost"));
}
{
SpnegoEngine spnegoEngine = new SpnegoEngine(null,
null,
null,
"service.ws.apache.org",
true,
null,
null,
null);
Assert.assertNotEquals("HTTP@localhost", spnegoEngine.getCompleteServicePrincipalName("localhost"));
Assert.assertTrue(spnegoEngine.getCompleteServicePrincipalName("localhost").startsWith("HTTP@"));
}
{
SpnegoEngine spnegoEngine = new SpnegoEngine(null,
null,
null,
"service.ws.apache.org",
false,
null,
null,
null);
Assert.assertEquals("HTTP@localhost", spnegoEngine.getCompleteServicePrincipalName("localhost"));
}
}

@AfterClass
public static void cleanup() throws Exception {
if (kerbyServer != null) {
Expand Down