Exemplo n.º 1
0
  static Krb5InitCredential getInstance(int caller, Krb5NameElement name, int initLifetime)
      throws GSSException {

    KerberosTicket tgt = getTgt(caller, name, initLifetime);
    if (tgt == null)
      throw new GSSException(GSSException.NO_CRED, -1, "Failed to find any Kerberos tgt");

    if (name == null) {
      String fullName = tgt.getClient().getName();
      name = Krb5NameElement.getInstance(fullName, Krb5MechFactory.NT_GSS_KRB5_PRINCIPAL);
    }

    return new Krb5InitCredential(
        name,
        tgt.getEncoded(),
        tgt.getClient(),
        tgt.getServer(),
        tgt.getSessionKey().getEncoded(),
        tgt.getSessionKeyType(),
        tgt.getFlags(),
        tgt.getAuthTime(),
        tgt.getStartTime(),
        tgt.getEndTime(),
        tgt.getRenewTill(),
        tgt.getClientAddresses());
  }
Exemplo n.º 2
0
  static Krb5InitCredential getInstance(Krb5NameElement name, Credentials delegatedCred)
      throws GSSException {

    EncryptionKey sessionKey = delegatedCred.getSessionKey();

    /*
     * all of the following data is optional in a KRB-CRED
     * messages. This check for each field.
     */

    PrincipalName cPrinc = delegatedCred.getClient();
    PrincipalName sPrinc = delegatedCred.getServer();

    KerberosPrincipal client = null;
    KerberosPrincipal server = null;

    Krb5NameElement credName = null;

    if (cPrinc != null) {
      String fullName = cPrinc.getName();
      credName = Krb5NameElement.getInstance(fullName, Krb5MechFactory.NT_GSS_KRB5_PRINCIPAL);
      client = new KerberosPrincipal(fullName);
    }

    // XXX Compare name to credName

    if (sPrinc != null) {
      server = new KerberosPrincipal(sPrinc.getName(), KerberosPrincipal.KRB_NT_SRV_INST);
    }

    return new Krb5InitCredential(
        credName,
        delegatedCred,
        delegatedCred.getEncoded(),
        client,
        server,
        sessionKey.getBytes(),
        sessionKey.getEType(),
        delegatedCred.getFlags(),
        delegatedCred.getAuthTime(),
        delegatedCred.getStartTime(),
        delegatedCred.getEndTime(),
        delegatedCred.getRenewTill(),
        delegatedCred.getClientAddresses());
  }