jdk/test/sun/security/krb5/auto/Context.java
changeset 4336 4c792c19266e
parent 3483 a16fce1820ef
child 5506 202f599c92aa
equal deleted inserted replaced
4335:365eb4449319 4336:4c792c19266e
    70  *    static transmit(message, from, to)
    70  *    static transmit(message, from, to)
    71  */
    71  */
    72 public class Context {
    72 public class Context {
    73 
    73 
    74     private Subject s;
    74     private Subject s;
    75     private GSSContext x;
    75     private ExtendedGSSContext x;
    76     private boolean f;      // context established?
    76     private boolean f;      // context established?
    77     private String name;
    77     private String name;
    78     private GSSCredential cred;     // see static method delegated().
    78     private GSSCredential cred;     // see static method delegated().
    79 
    79 
    80     private Context() {}
    80     private Context() {}
   145     public void startAsClient(final String target, final Oid mech) throws Exception {
   145     public void startAsClient(final String target, final Oid mech) throws Exception {
   146         doAs(new Action() {
   146         doAs(new Action() {
   147             @Override
   147             @Override
   148             public byte[] run(Context me, byte[] dummy) throws Exception {
   148             public byte[] run(Context me, byte[] dummy) throws Exception {
   149                 GSSManager m = GSSManager.getInstance();
   149                 GSSManager m = GSSManager.getInstance();
   150                 me.x = m.createContext(
   150                 me.x = (ExtendedGSSContext)m.createContext(
   151                         target.indexOf('@') < 0 ?
   151                           target.indexOf('@') < 0 ?
   152                             m.createName(target, null) :
   152                             m.createName(target, null) :
   153                             m.createName(target, GSSName.NT_HOSTBASED_SERVICE),
   153                             m.createName(target, GSSName.NT_HOSTBASED_SERVICE),
   154                         mech,
   154                         mech,
   155                         cred,
   155                         cred,
   156                         GSSContext.DEFAULT_LIFETIME);
   156                         GSSContext.DEFAULT_LIFETIME);
   168     public void startAsServer(final Oid mech) throws Exception {
   168     public void startAsServer(final Oid mech) throws Exception {
   169         doAs(new Action() {
   169         doAs(new Action() {
   170             @Override
   170             @Override
   171             public byte[] run(Context me, byte[] dummy) throws Exception {
   171             public byte[] run(Context me, byte[] dummy) throws Exception {
   172                 GSSManager m = GSSManager.getInstance();
   172                 GSSManager m = GSSManager.getInstance();
   173                 me.x = m.createContext(m.createCredential(
   173                 me.x = (ExtendedGSSContext)m.createContext(m.createCredential(
   174                         null,
   174                         null,
   175                         GSSCredential.INDEFINITE_LIFETIME,
   175                         GSSCredential.INDEFINITE_LIFETIME,
   176                         mech,
   176                         mech,
   177                         GSSCredential.ACCEPT_ONLY));
   177                         GSSCredential.ACCEPT_ONLY));
   178                 return null;
   178                 return null;
   191      * object, please use doAs(). Otherwise, it can be done directly. The
   191      * object, please use doAs(). Otherwise, it can be done directly. The
   192      * methods listed above are all non-privileged calls.
   192      * methods listed above are all non-privileged calls.
   193      *
   193      *
   194      * @return the GSSContext object
   194      * @return the GSSContext object
   195      */
   195      */
   196     public GSSContext x() {
   196     public ExtendedGSSContext x() {
   197         return x;
   197         return x;
   198     }
   198     }
   199 
   199 
   200     /**
   200     /**
   201      * Disposes the GSSContext within
   201      * Disposes the GSSContext within
   252             if (x.getReplayDetState()) {
   252             if (x.getReplayDetState()) {
   253                 sb.append("rep det, ");
   253                 sb.append("rep det, ");
   254             }
   254             }
   255             if (x.getSequenceDetState()) {
   255             if (x.getSequenceDetState()) {
   256                 sb.append("seq det, ");
   256                 sb.append("seq det, ");
       
   257             }
       
   258             if (x instanceof ExtendedGSSContext) {
       
   259                 if (((ExtendedGSSContext)x).getDelegPolicyState()) {
       
   260                     sb.append("deleg policy, ");
       
   261                 }
   257             }
   262             }
   258             System.out.println("Context status of " + name + ": " + sb.toString());
   263             System.out.println("Context status of " + name + ": " + sb.toString());
   259             System.out.println(x.getSrcName() + " -> " + x.getTargName());
   264             System.out.println(x.getSrcName() + " -> " + x.getTargName());
   260         } catch (Exception e) {
   265         } catch (Exception e) {
   261             ;// Don't care
   266             ;// Don't care