Repository: cxf
Updated Branches:
  refs/heads/master 5bac26a13 -> 5583b99e0


Fixing failing JAX-RS kerberos system tests


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5583b99e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5583b99e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5583b99e

Branch: refs/heads/master
Commit: 5583b99e0eb3185741c18eec82f40e124e5649e3
Parents: 5bac26a
Author: Colm O hEigeartaigh <[email protected]>
Authored: Thu Dec 18 16:23:11 2014 +0000
Committer: Colm O hEigeartaigh <[email protected]>
Committed: Thu Dec 18 16:23:30 2014 +0000

----------------------------------------------------------------------
 .../http/auth/AbstractSpnegoAuthSupplier.java   | 78 ++++++++------------
 1 file changed, 32 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5583b99e/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/AbstractSpnegoAuthSupplier.java
----------------------------------------------------------------------
diff --git 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/AbstractSpnegoAuthSupplier.java
 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/AbstractSpnegoAuthSupplier.java
index e1180e1..95239cc 100644
--- 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/AbstractSpnegoAuthSupplier.java
+++ 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/AbstractSpnegoAuthSupplier.java
@@ -86,50 +86,6 @@ public abstract class AbstractSpnegoAuthSupplier {
     }
 
     /**
-     * Create and return service ticket token
-     * 
-     * @param authPolicy
-     * @param context
-     * @return
-     * @throws GSSException
-     * @throws LoginException
-     */
-    private byte[] getToken(AuthorizationPolicy authPolicy,
-                            final GSSContext context) throws GSSException,
-        LoginException {
-        
-        final byte[] token = new byte[0];
-        if (authPolicy == null) {
-            return context.initSecContext(token, 0, token.length);
-        }
-
-        String contextName = authPolicy.getAuthorization();
-        if (contextName == null) {
-            contextName = "";
-        }
-        
-        if (StringUtils.isEmpty(authPolicy.getUserName())
-            && StringUtils.isEmpty(contextName) && loginConfig == null) {
-            return context.initSecContext(token, 0, token.length);
-        }
-        
-        CallbackHandler callbackHandler = getUsernamePasswordHandler(
-            authPolicy.getUserName(), authPolicy.getPassword());
-        LoginContext lc = new LoginContext(contextName, null, callbackHandler, 
loginConfig);
-        lc.login();
-        
-        try {
-            return (byte[])Subject.doAs(lc.getSubject(), new 
CreateServiceTicketAction(context, token));
-        } catch (PrivilegedActionException e) {
-            if (e.getCause() instanceof GSSException) {
-                throw (GSSException) e.getCause();
-            }
-            LOG.log(Level.SEVERE, "initSecContext", e);
-            return null;
-        }
-    }
-
-    /**
      * Create and return a service ticket token for a given service principal
      * name
      * 
@@ -144,6 +100,24 @@ public abstract class AbstractSpnegoAuthSupplier {
                             Oid oid,
                             Message message) throws GSSException, 
         LoginException {
+        
+        Subject subject = null;
+        if (authPolicy != null) {
+            String contextName = authPolicy.getAuthorization();
+            if (contextName == null) {
+                contextName = "";
+            }
+        
+            if (!(StringUtils.isEmpty(authPolicy.getUserName())
+                && StringUtils.isEmpty(contextName) && loginConfig == null)) {
+                CallbackHandler callbackHandler = getUsernamePasswordHandler(
+                    authPolicy.getUserName(), authPolicy.getPassword());
+                LoginContext lc = new LoginContext(contextName, null, 
callbackHandler, loginConfig);
+                lc.login();
+                subject = lc.getSubject();
+            }
+        }
+                                                                 
         GSSManager manager = GSSManager.getInstance();
         GSSName serverName = manager.createName(spn, serviceNameType);
 
@@ -158,8 +132,20 @@ public abstract class AbstractSpnegoAuthSupplier {
         // If the delegated cred is not null then we only need the context to
         // immediately return a ticket based on this credential without 
attempting
         // to log on again 
-        return getToken(delegatedCred == null ? authPolicy : null, 
-                        context);
+        final byte[] token = new byte[0];
+        if (delegatedCred != null) {
+            return context.initSecContext(token, 0, token.length);
+        }
+        
+        try {
+            return (byte[])Subject.doAs(subject, new 
CreateServiceTicketAction(context, token));
+        } catch (PrivilegedActionException e) {
+            if (e.getCause() instanceof GSSException) {
+                throw (GSSException) e.getCause();
+            }
+            LOG.log(Level.SEVERE, "initSecContext", e);
+            return null;
+        }
     }
     
     protected boolean isCredDelegationRequired(Message message) { 

Reply via email to