jdk/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java
changeset 4336 4c792c19266e
parent 3482 4aaa66ce712d
child 4337 2a6d13ebbbed
equal deleted inserted replaced
4335:365eb4449319 4336:4c792c19266e
    61     private boolean mutualAuthState = true;
    61     private boolean mutualAuthState = true;
    62     private boolean replayDetState = true;
    62     private boolean replayDetState = true;
    63     private boolean sequenceDetState = true;
    63     private boolean sequenceDetState = true;
    64     private boolean confState = true;
    64     private boolean confState = true;
    65     private boolean integState = true;
    65     private boolean integState = true;
       
    66     private boolean delegPolicyState = false;
    66 
    67 
    67     private GSSNameSpi peerName = null;
    68     private GSSNameSpi peerName = null;
    68     private GSSNameSpi myName = null;
    69     private GSSNameSpi myName = null;
    69     private SpNegoCredElement myCred = null;
    70     private SpNegoCredElement myCred = null;
    70 
    71 
   152         if (state == STATE_NEW && isInitiator())
   153         if (state == STATE_NEW && isInitiator())
   153             integState  = value;
   154             integState  = value;
   154     }
   155     }
   155 
   156 
   156     /**
   157     /**
       
   158      * Requests that deleg policy be respected.
       
   159      */
       
   160     public final void requestDelegPolicy(boolean value) throws GSSException {
       
   161         if (state == STATE_NEW && isInitiator())
       
   162             delegPolicyState = value;
       
   163     }
       
   164 
       
   165     /**
   157      * Is integrity available?
   166      * Is integrity available?
   158      */
   167      */
   159     public final boolean getIntegState() {
   168     public final boolean getIntegState() {
   160         return integState;
   169         return integState;
       
   170     }
       
   171 
       
   172     /**
       
   173      * Is deleg policy respected?
       
   174      */
       
   175     public final boolean getDelegPolicyState() {
       
   176         if (isInitiator() && mechContext != null &&
       
   177                 mechContext instanceof ExtendedGSSContext &&
       
   178                 (state == STATE_IN_PROCESS || state == STATE_DONE)) {
       
   179             return ((ExtendedGSSContext)mechContext).getDelegPolicyState();
       
   180         } else {
       
   181             return delegPolicyState;
       
   182         }
   161     }
   183     }
   162 
   184 
   163     /**
   185     /**
   164      * Requests that credential delegation be done during context
   186      * Requests that credential delegation be done during context
   165      * establishment.
   187      * establishment.
   171 
   193 
   172     /**
   194     /**
   173      * Is credential delegation enabled?
   195      * Is credential delegation enabled?
   174      */
   196      */
   175     public final boolean getCredDelegState() {
   197     public final boolean getCredDelegState() {
   176         if (mechContext != null &&
   198         if (isInitiator() && mechContext != null &&
   177                 (state == STATE_IN_PROCESS || state == STATE_DONE)) {
   199                 (state == STATE_IN_PROCESS || state == STATE_DONE)) {
   178             return mechContext.getCredDelegState();
   200             return mechContext.getCredDelegState();
   179         } else {
   201         } else {
   180             return credDelegState;
   202             return credDelegState;
   181         }
   203         }
   197      * perspective, it essentially meas that the server is being
   219      * perspective, it essentially meas that the server is being
   198      * authenticated.
   220      * authenticated.
   199      */
   221      */
   200     public final boolean getMutualAuthState() {
   222     public final boolean getMutualAuthState() {
   201         return mutualAuthState;
   223         return mutualAuthState;
   202     }
       
   203 
       
   204     final void setCredDelegState(boolean state) {
       
   205         credDelegState = state;
       
   206     }
       
   207 
       
   208     final void setMutualAuthState(boolean state) {
       
   209         mutualAuthState = state;
       
   210     }
       
   211 
       
   212     final void setReplayDetState(boolean state) {
       
   213         replayDetState = state;
       
   214     }
       
   215 
       
   216     final void setSequenceDetState(boolean state) {
       
   217         sequenceDetState = state;
       
   218     }
       
   219 
       
   220     final void setConfState(boolean state) {
       
   221         confState = state;
       
   222     }
       
   223 
       
   224     final void setIntegState(boolean state) {
       
   225         integState = state;
       
   226     }
   224     }
   227 
   225 
   228     /**
   226     /**
   229      * Returns the mechanism oid.
   227      * Returns the mechanism oid.
   230      *
   228      *
   651                 new GSSException(GSSException.FAILURE, -1, e.getMessage());
   649                 new GSSException(GSSException.FAILURE, -1, e.getMessage());
   652             gssException.initCause(e);
   650             gssException.initCause(e);
   653             throw gssException;
   651             throw gssException;
   654         }
   652         }
   655 
   653 
       
   654         if (state == STATE_DONE) {
       
   655             // now set the context flags for acceptor
       
   656             setContextFlags();
       
   657         }
   656         return retVal;
   658         return retVal;
   657     }
   659     }
   658 
   660 
   659     /**
   661     /**
   660      * obtain the available mechanisms
   662      * obtain the available mechanisms
   701         if (getIntegState()) out.set(6, true);
   703         if (getIntegState()) out.set(6, true);
   702 
   704 
   703         return out;
   705         return out;
   704     }
   706     }
   705 
   707 
       
   708     // Only called on acceptor side. On the initiator side, most flags
       
   709     // are already set at request. For those that might get chanegd,
       
   710     // state from mech below is used.
   706     private void setContextFlags() {
   711     private void setContextFlags() {
   707 
   712 
   708         if (mechContext != null) {
   713         if (mechContext != null) {
   709             // default for cred delegation is false
   714             // default for cred delegation is false
   710             if (mechContext.getCredDelegState()) {
   715             if (mechContext.getCredDelegState()) {
   711                 setCredDelegState(true);
   716                 credDelegState = true;
   712             }
   717             }
   713             // default for the following are true
   718             // default for the following are true
   714             if (!mechContext.getMutualAuthState()) {
   719             if (!mechContext.getMutualAuthState()) {
   715                 setMutualAuthState(false);
   720                 mutualAuthState = false;
   716             }
   721             }
   717             if (!mechContext.getReplayDetState()) {
   722             if (!mechContext.getReplayDetState()) {
   718                 setReplayDetState(false);
   723                 replayDetState = false;
   719             }
   724             }
   720             if (!mechContext.getSequenceDetState()) {
   725             if (!mechContext.getSequenceDetState()) {
   721                 setSequenceDetState(false);
   726                 sequenceDetState = false;
   722             }
   727             }
   723             if (!mechContext.getIntegState()) {
   728             if (!mechContext.getIntegState()) {
   724                 setIntegState(false);
   729                 integState = false;
   725             }
   730             }
   726             if (!mechContext.getConfState()) {
   731             if (!mechContext.getConfState()) {
   727                 setConfState(false);
   732                 confState = false;
   728             }
   733             }
   729         }
   734         }
   730     }
   735     }
   731 
   736 
   732     /**
   737     /**
   835             mechContext.requestInteg(integState);
   840             mechContext.requestInteg(integState);
   836             mechContext.requestCredDeleg(credDelegState);
   841             mechContext.requestCredDeleg(credDelegState);
   837             mechContext.requestMutualAuth(mutualAuthState);
   842             mechContext.requestMutualAuth(mutualAuthState);
   838             mechContext.requestReplayDet(replayDetState);
   843             mechContext.requestReplayDet(replayDetState);
   839             mechContext.requestSequenceDet(sequenceDetState);
   844             mechContext.requestSequenceDet(sequenceDetState);
       
   845             if (mechContext instanceof ExtendedGSSContext) {
       
   846                 ((ExtendedGSSContext)mechContext).requestDelegPolicy(
       
   847                         delegPolicyState);
       
   848             }
   840         }
   849         }
   841 
   850 
   842         // pass token
   851         // pass token
   843         if (token != null) {
   852         if (token != null) {
   844             tok = token;
   853             tok = token;
  1200         } else {
  1209         } else {
  1201             throw new GSSException(GSSException.BAD_MECH, -1,
  1210             throw new GSSException(GSSException.BAD_MECH, -1,
  1202                     "inquireSecContext not supported by underlying mech.");
  1211                     "inquireSecContext not supported by underlying mech.");
  1203         }
  1212         }
  1204     }
  1213     }
  1205 
       
  1206 }
  1214 }
       
  1215