File tree 2 files changed +44
-6
lines changed
main/java/org/asynchttpclient/spnego
test/java/org/asynchttpclient/spnego
2 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -256,18 +256,18 @@ public String generateToken(String host) throws SpnegoEngineException {
256
256
}
257
257
}
258
258
259
- protected String getCompleteServicePrincipalName (String host ) {
259
+ String getCompleteServicePrincipalName (String host ) {
260
260
String name ;
261
261
if (servicePrincipalName == null ) {
262
262
if (useCanonicalHostname ) {
263
263
host = getCanonicalHostname (host );
264
264
}
265
- name = "HTTP/ " + host ;
265
+ name = "HTTP@ " + host ;
266
266
} else {
267
267
name = servicePrincipalName ;
268
- }
269
- if ( realmName != null ) {
270
- name += "@" + realmName ;
268
+ if ( realmName != null && ! name . contains ( "@" )) {
269
+ name += "@" + realmName ;
270
+ }
271
271
}
272
272
log .debug ("Service Principal Name is {}" , name );
273
273
return name ;
@@ -285,7 +285,7 @@ private String getCanonicalHostname(String hostname) {
285
285
return canonicalHostname ;
286
286
}
287
287
288
- public CallbackHandler getUsernamePasswordHandler () {
288
+ private CallbackHandler getUsernamePasswordHandler () {
289
289
if (username == null ) {
290
290
return null ;
291
291
}
Original file line number Diff line number Diff line change @@ -113,6 +113,44 @@ public void testSpnegoGenerateTokenWithCustomLoginConfig() throws Exception {
113
113
Assert .assertTrue (token .startsWith ("YII" ));
114
114
}
115
115
116
+ @ Test
117
+ public void testGetCompleteServicePrincipalName () throws Exception {
118
+ {
119
+ SpnegoEngine spnegoEngine = new SpnegoEngine (null ,
120
+ null ,
121
+ "bob" ,
122
+ "service.ws.apache.org" ,
123
+ false ,
124
+ null ,
125
+ null ,
126
+ null );
127
+ Assert .
assertEquals (
"[email protected] " ,
spnegoEngine .
getCompleteServicePrincipalName (
"localhost" ));
128
+ }
129
+ {
130
+ SpnegoEngine spnegoEngine = new SpnegoEngine (null ,
131
+ null ,
132
+ null ,
133
+ "service.ws.apache.org" ,
134
+ true ,
135
+ null ,
136
+ null ,
137
+ null );
138
+ Assert .assertNotEquals ("HTTP@localhost" , spnegoEngine .getCompleteServicePrincipalName ("localhost" ));
139
+ Assert .assertTrue (spnegoEngine .getCompleteServicePrincipalName ("localhost" ).startsWith ("HTTP@" ));
140
+ }
141
+ {
142
+ SpnegoEngine spnegoEngine = new SpnegoEngine (null ,
143
+ null ,
144
+ null ,
145
+ "service.ws.apache.org" ,
146
+ false ,
147
+ null ,
148
+ null ,
149
+ null );
150
+ Assert .assertEquals ("HTTP@localhost" , spnegoEngine .getCompleteServicePrincipalName ("localhost" ));
151
+ }
152
+ }
153
+
116
154
@ AfterClass
117
155
public static void cleanup () throws Exception {
118
156
if (kerbyServer != null ) {
You can’t perform that action at this time.
0 commit comments