src/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package sun.net.www.protocol.http;
  27 
  28 import java.io.IOException;
  29 
  30 import org.ietf.jgss.GSSContext;
  31 import org.ietf.jgss.GSSException;
  32 import org.ietf.jgss.GSSName;
  33 import org.ietf.jgss.Oid;
  34 


  35 import sun.security.jgss.GSSManagerImpl;
  36 import sun.security.jgss.GSSUtil;
  37 import sun.security.jgss.HttpCaller;
  38 
  39 /**
  40  * This class encapsulates all JAAS and JGSS API calls in a separate class
  41  * outside NegotiateAuthentication.java so that J2SE build can go smoothly
  42  * without the presence of it.
  43  *
  44  * @author weijun.wang@sun.com
  45  * @since 1.6
  46  */
  47 public class NegotiatorImpl extends Negotiator {
  48 
  49     private static final boolean DEBUG =
  50         java.security.AccessController.doPrivileged(
  51               new sun.security.action.GetBooleanAction("sun.security.krb5.debug"));
  52 
  53     private GSSContext context;
  54     private byte[] oneToken;


 116      */
 117     public NegotiatorImpl(HttpCallerInfo hci) throws IOException {
 118         try {
 119             init(hci);
 120         } catch (GSSException e) {
 121             if (DEBUG) {
 122                 System.out.println("Negotiate support not initiated, will " +
 123                         "fallback to other scheme if allowed. Reason:");
 124                 e.printStackTrace();
 125             }
 126             IOException ioe = new IOException("Negotiate support not initiated");
 127             ioe.initCause(e);
 128             throw ioe;
 129         }
 130     }
 131 
 132     /**
 133      * Return the first token of GSS, in SPNEGO, it's called NegTokenInit
 134      * @return the first token
 135      */

 136     public byte[] firstToken() {
 137         return oneToken;
 138     }
 139 
 140     /**
 141      * Return the rest tokens of GSS, in SPNEGO, it's called NegTokenTarg
 142      * @param token the token received from server
 143      * @return the next token
 144      * @throws java.io.IOException if the token cannot be created successfully
 145      */

 146     public byte[] nextToken(byte[] token) throws IOException {
 147         try {
 148             return context.initSecContext(token, 0, token.length);
 149         } catch (GSSException e) {
 150             if (DEBUG) {
 151                 System.out.println("Negotiate support cannot continue. Reason:");
 152                 e.printStackTrace();
 153             }
 154             IOException ioe = new IOException("Negotiate support cannot continue");
 155             ioe.initCause(e);
 156             throw ioe;
 157         }
 158     }
 159 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package sun.net.www.protocol.http.spnego;
  27 
  28 import java.io.IOException;
  29 
  30 import org.ietf.jgss.GSSContext;
  31 import org.ietf.jgss.GSSException;
  32 import org.ietf.jgss.GSSName;
  33 import org.ietf.jgss.Oid;
  34 
  35 import sun.net.www.protocol.http.HttpCallerInfo;
  36 import sun.net.www.protocol.http.Negotiator;
  37 import sun.security.jgss.GSSManagerImpl;
  38 import sun.security.jgss.GSSUtil;
  39 import sun.security.jgss.HttpCaller;
  40 
  41 /**
  42  * This class encapsulates all JAAS and JGSS API calls in a separate class
  43  * outside NegotiateAuthentication.java so that J2SE build can go smoothly
  44  * without the presence of it.
  45  *
  46  * @author weijun.wang@sun.com
  47  * @since 1.6
  48  */
  49 public class NegotiatorImpl extends Negotiator {
  50 
  51     private static final boolean DEBUG =
  52         java.security.AccessController.doPrivileged(
  53               new sun.security.action.GetBooleanAction("sun.security.krb5.debug"));
  54 
  55     private GSSContext context;
  56     private byte[] oneToken;


 118      */
 119     public NegotiatorImpl(HttpCallerInfo hci) throws IOException {
 120         try {
 121             init(hci);
 122         } catch (GSSException e) {
 123             if (DEBUG) {
 124                 System.out.println("Negotiate support not initiated, will " +
 125                         "fallback to other scheme if allowed. Reason:");
 126                 e.printStackTrace();
 127             }
 128             IOException ioe = new IOException("Negotiate support not initiated");
 129             ioe.initCause(e);
 130             throw ioe;
 131         }
 132     }
 133 
 134     /**
 135      * Return the first token of GSS, in SPNEGO, it's called NegTokenInit
 136      * @return the first token
 137      */
 138     @Override
 139     public byte[] firstToken() {
 140         return oneToken;
 141     }
 142 
 143     /**
 144      * Return the rest tokens of GSS, in SPNEGO, it's called NegTokenTarg
 145      * @param token the token received from server
 146      * @return the next token
 147      * @throws java.io.IOException if the token cannot be created successfully
 148      */
 149     @Override
 150     public byte[] nextToken(byte[] token) throws IOException {
 151         try {
 152             return context.initSecContext(token, 0, token.length);
 153         } catch (GSSException e) {
 154             if (DEBUG) {
 155                 System.out.println("Negotiate support cannot continue. Reason:");
 156                 e.printStackTrace();
 157             }
 158             IOException ioe = new IOException("Negotiate support cannot continue");
 159             ioe.initCause(e);
 160             throw ioe;
 161         }
 162     }
 163 }