File tree Expand file tree Collapse file tree 2 files changed +44
-6
lines changed
main/java/org/asynchttpclient/spnego
test/java/org/asynchttpclient/spnego Expand file tree Collapse file tree 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 {
256256 }
257257 }
258258
259- protected String getCompleteServicePrincipalName (String host ) {
259+ String getCompleteServicePrincipalName (String host ) {
260260 String name ;
261261 if (servicePrincipalName == null ) {
262262 if (useCanonicalHostname ) {
263263 host = getCanonicalHostname (host );
264264 }
265- name = "HTTP/ " + host ;
265+ name = "HTTP@ " + host ;
266266 } else {
267267 name = servicePrincipalName ;
268- }
269- if ( realmName != null ) {
270- name += "@" + realmName ;
268+ if ( realmName != null && ! name . contains ( "@" )) {
269+ name += "@" + realmName ;
270+ }
271271 }
272272 log .debug ("Service Principal Name is {}" , name );
273273 return name ;
@@ -285,7 +285,7 @@ private String getCanonicalHostname(String hostname) {
285285 return canonicalHostname ;
286286 }
287287
288- public CallbackHandler getUsernamePasswordHandler () {
288+ private CallbackHandler getUsernamePasswordHandler () {
289289 if (username == null ) {
290290 return null ;
291291 }
Original file line number Diff line number Diff line change @@ -113,6 +113,44 @@ public void testSpnegoGenerateTokenWithCustomLoginConfig() throws Exception {
113113 Assert .assertTrue (token .startsWith ("YII" ));
114114 }
115115
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 ("bob@service.ws.apache.org" , 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+
116154 @ AfterClass
117155 public static void cleanup () throws Exception {
118156 if (kerbyServer != null ) {
You can’t perform that action at this time.
0 commit comments