jdk/src/share/classes/sun/security/jgss/GSSContextImpl.java
changeset 4336 4c792c19266e
parent 3482 4aaa66ce712d
child 5506 202f599c92aa
equal deleted inserted replaced
4335:365eb4449319 4336:4c792c19266e
    87  * per-message operations are returned in an instance of the MessageProp
    87  * per-message operations are returned in an instance of the MessageProp
    88  * class, which is used as an argument in these calls.</dl>
    88  * class, which is used as an argument in these calls.</dl>
    89  */
    89  */
    90 class GSSContextImpl implements ExtendedGSSContext {
    90 class GSSContextImpl implements ExtendedGSSContext {
    91 
    91 
    92     private GSSManagerImpl gssManager = null;
    92     private final GSSManagerImpl gssManager;
       
    93     private final boolean initiator;
    93 
    94 
    94     // private flags for the context state
    95     // private flags for the context state
    95     private static final int PRE_INIT = 1;
    96     private static final int PRE_INIT = 1;
    96     private static final int IN_PROGRESS = 2;
    97     private static final int IN_PROGRESS = 2;
    97     private static final int READY = 3;
    98     private static final int READY = 3;
    98     private static final int DELETED = 4;
    99     private static final int DELETED = 4;
    99 
   100 
   100     // instance variables
   101     // instance variables
   101     private int currentState = PRE_INIT;
   102     private int currentState = PRE_INIT;
   102     private boolean initiator;
       
   103 
   103 
   104     private GSSContextSpi mechCtxt = null;
   104     private GSSContextSpi mechCtxt = null;
   105     private Oid mechOid = null;
   105     private Oid mechOid = null;
   106     private ObjectIdentifier objId = null;
   106     private ObjectIdentifier objId = null;
   107 
   107 
   108     private GSSCredentialImpl myCred = null;
   108     private GSSCredentialImpl myCred = null;
   109     private GSSCredentialImpl delegCred = null;
       
   110 
   109 
   111     private GSSNameImpl srcName = null;
   110     private GSSNameImpl srcName = null;
   112     private GSSNameImpl targName = null;
   111     private GSSNameImpl targName = null;
   113 
   112 
   114     private int reqLifetime = INDEFINITE_LIFETIME;
   113     private int reqLifetime = INDEFINITE_LIFETIME;
   119     private boolean reqMutualAuthState = true;
   118     private boolean reqMutualAuthState = true;
   120     private boolean reqReplayDetState = true;
   119     private boolean reqReplayDetState = true;
   121     private boolean reqSequenceDetState = true;
   120     private boolean reqSequenceDetState = true;
   122     private boolean reqCredDelegState = false;
   121     private boolean reqCredDelegState = false;
   123     private boolean reqAnonState = false;
   122     private boolean reqAnonState = false;
       
   123     private boolean reqDelegPolicyState = false;
   124 
   124 
   125     /**
   125     /**
   126      * Creates a GSSContextImp on the context initiator's side.
   126      * Creates a GSSContextImp on the context initiator's side.
   127      */
   127      */
   128     public GSSContextImpl(GSSManagerImpl gssManager, GSSName peer, Oid mech,
   128     public GSSContextImpl(GSSManagerImpl gssManager, GSSName peer, Oid mech,
   219                 mechCtxt.requestMutualAuth(reqMutualAuthState);
   219                 mechCtxt.requestMutualAuth(reqMutualAuthState);
   220                 mechCtxt.requestReplayDet(reqReplayDetState);
   220                 mechCtxt.requestReplayDet(reqReplayDetState);
   221                 mechCtxt.requestSequenceDet(reqSequenceDetState);
   221                 mechCtxt.requestSequenceDet(reqSequenceDetState);
   222                 mechCtxt.requestAnonymity(reqAnonState);
   222                 mechCtxt.requestAnonymity(reqAnonState);
   223                 mechCtxt.setChannelBinding(channelBindings);
   223                 mechCtxt.setChannelBinding(channelBindings);
       
   224                 mechCtxt.requestDelegPolicy(reqDelegPolicyState);
   224 
   225 
   225                 objId = new ObjectIdentifier(mechOid.toString());
   226                 objId = new ObjectIdentifier(mechOid.toString());
   226 
   227 
   227                 currentState = IN_PROGRESS;
   228                 currentState = IN_PROGRESS;
   228                 firstToken = true;
   229                 firstToken = true;
   463         }
   464         }
   464         return result;
   465         return result;
   465     }
   466     }
   466 
   467 
   467     public void requestMutualAuth(boolean state) throws GSSException {
   468     public void requestMutualAuth(boolean state) throws GSSException {
   468         if (mechCtxt == null)
   469         if (mechCtxt == null && initiator)
   469             reqMutualAuthState = state;
   470             reqMutualAuthState = state;
   470     }
   471     }
   471 
   472 
   472     public void requestReplayDet(boolean state) throws GSSException {
   473     public void requestReplayDet(boolean state) throws GSSException {
   473         if (mechCtxt == null)
   474         if (mechCtxt == null && initiator)
   474             reqReplayDetState = state;
   475             reqReplayDetState = state;
   475     }
   476     }
   476 
   477 
   477     public void requestSequenceDet(boolean state) throws GSSException {
   478     public void requestSequenceDet(boolean state) throws GSSException {
   478         if (mechCtxt == null)
   479         if (mechCtxt == null && initiator)
   479             reqSequenceDetState = state;
   480             reqSequenceDetState = state;
   480     }
   481     }
   481 
   482 
   482     public void requestCredDeleg(boolean state) throws GSSException {
   483     public void requestCredDeleg(boolean state) throws GSSException {
   483         if (mechCtxt == null)
   484         if (mechCtxt == null && initiator)
   484             reqCredDelegState = state;
   485             reqCredDelegState = state;
   485     }
   486     }
   486 
   487 
   487     public void requestAnonymity(boolean state) throws GSSException {
   488     public void requestAnonymity(boolean state) throws GSSException {
   488         if (mechCtxt == null)
   489         if (mechCtxt == null && initiator)
   489             reqAnonState = state;
   490             reqAnonState = state;
   490     }
   491     }
   491 
   492 
   492     public void requestConf(boolean state) throws GSSException {
   493     public void requestConf(boolean state) throws GSSException {
   493         if (mechCtxt == null)
   494         if (mechCtxt == null && initiator)
   494             reqConfState = state;
   495             reqConfState = state;
   495     }
   496     }
   496 
   497 
   497     public void requestInteg(boolean state) throws GSSException {
   498     public void requestInteg(boolean state) throws GSSException {
   498         if (mechCtxt == null)
   499         if (mechCtxt == null && initiator)
   499             reqIntegState = state;
   500             reqIntegState = state;
   500     }
   501     }
   501 
   502 
   502     public void requestLifetime(int lifetime) throws GSSException {
   503     public void requestLifetime(int lifetime) throws GSSException {
   503         if (mechCtxt == null)
   504         if (mechCtxt == null && initiator)
   504             reqLifetime = lifetime;
   505             reqLifetime = lifetime;
   505     }
   506     }
   506 
   507 
   507     public void setChannelBinding(ChannelBinding channelBindings)
   508     public void setChannelBinding(ChannelBinding channelBindings)
   508         throws GSSException {
   509         throws GSSException {
   628         myCred = null;
   629         myCred = null;
   629         srcName = null;
   630         srcName = null;
   630         targName = null;
   631         targName = null;
   631     }
   632     }
   632 
   633 
       
   634     // ExtendedGSSContext methods:
       
   635 
   633     @Override
   636     @Override
   634     public Object inquireSecContext(InquireType type) throws GSSException {
   637     public Object inquireSecContext(InquireType type) throws GSSException {
   635         SecurityManager security = System.getSecurityManager();
   638         SecurityManager security = System.getSecurityManager();
   636         if (security != null) {
   639         if (security != null) {
   637             security.checkPermission(new InquireSecContextPermission(type.toString()));
   640             security.checkPermission(new InquireSecContextPermission(type.toString()));
   639         if (mechCtxt == null) {
   642         if (mechCtxt == null) {
   640             throw new GSSException(GSSException.NO_CONTEXT);
   643             throw new GSSException(GSSException.NO_CONTEXT);
   641         }
   644         }
   642         return mechCtxt.inquireSecContext(type);
   645         return mechCtxt.inquireSecContext(type);
   643     }
   646     }
       
   647 
       
   648     @Override
       
   649     public void requestDelegPolicy(boolean state) throws GSSException {
       
   650         if (mechCtxt == null && initiator)
       
   651             reqDelegPolicyState = state;
       
   652     }
       
   653 
       
   654     @Override
       
   655     public boolean getDelegPolicyState() {
       
   656         if (mechCtxt != null)
       
   657             return mechCtxt.getDelegPolicyState();
       
   658         else
       
   659             return reqDelegPolicyState;
       
   660     }
   644 }
   661 }