Java Code Examples for org.ietf.jgss.GSSCredential#getRemainingLifetime()

The following examples show how to use org.ietf.jgss.GSSCredential#getRemainingLifetime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LifeTimeInSeconds.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 2
Source File: LifeTimeInSeconds.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 3
Source File: LifeTimeInSeconds.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 4
Source File: LifeTimeInSeconds.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 5
Source File: LifeTimeInSeconds.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 6
Source File: LifeTimeInSeconds.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 7
Source File: LifeTimeInSeconds.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 8
Source File: LifeTimeInSeconds.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 9
Source File: LifeTimeInSeconds.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 10
Source File: LifeTimeInSeconds.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 11
Source File: LifeTimeInSeconds.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 12
Source File: LifeTimeInSeconds.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 13
Source File: LifeTimeInSeconds.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
Example 14
Source File: LongLife.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void test(
        KDC kdc,
        String ticketLifetime,
        boolean forceTill, // if true, KDC will not try RENEWABLE
        int expectedLifeTime,
        boolean expectedRenewable) throws Exception {

    KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
    Config.refresh();

    System.setProperty("test.kdc.ttl.value", ticketLifetime);

    if (forceTill) {
        System.setProperty("test.kdc.force.till", "");
    } else {
        System.clearProperty("test.kdc.force.till");
    }

    Context c = Context.fromJAAS("client");

    GSSCredential cred = Subject.doAs(c.s(),
            (PrivilegedExceptionAction<GSSCredential>)
            ()-> {
                GSSManager m = GSSManager.getInstance();
                return m.createCredential(GSSCredential.INITIATE_ONLY);
            });

    KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)
            .iterator().next();
    System.out.println(tgt);

    int actualLifeTime = cred.getRemainingLifetime();
    if (actualLifeTime < (expectedLifeTime - 60 )
            || actualLifeTime > (expectedLifeTime + 60)) {
        throw new Exception("actualLifeTime is " + actualLifeTime +
                  " ExpectedLifeTime is " + expectedLifeTime);
    }

    if (tgt.isRenewable() != expectedRenewable) {
        throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());
    }
}
 
Example 15
Source File: LongLife.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void test(
        KDC kdc,
        String ticketLifetime,
        boolean forceTill, // if true, KDC will not try RENEWABLE
        int expectedLifeTime,
        boolean expectedRenewable) throws Exception {

    KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
    Config.refresh();

    System.setProperty("test.kdc.ttl.value", ticketLifetime);

    if (forceTill) {
        System.setProperty("test.kdc.force.till", "");
    } else {
        System.clearProperty("test.kdc.force.till");
    }

    Context c = Context.fromJAAS("client");

    GSSCredential cred = Subject.doAs(c.s(),
            (PrivilegedExceptionAction<GSSCredential>)
            ()-> {
                GSSManager m = GSSManager.getInstance();
                return m.createCredential(GSSCredential.INITIATE_ONLY);
            });

    KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)
            .iterator().next();
    System.out.println(tgt);

    int actualLifeTime = cred.getRemainingLifetime();
    if (actualLifeTime < (expectedLifeTime - 60 )
            || actualLifeTime > (expectedLifeTime + 60)) {
        throw new Exception("actualLifeTime is " + actualLifeTime +
                  " ExpectedLifeTime is " + expectedLifeTime);
    }

    if (tgt.isRenewable() != expectedRenewable) {
        throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());
    }
}
 
Example 16
Source File: LongLife.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void test(
        KDC kdc,
        String ticketLifetime,
        boolean forceTill, // if true, KDC will not try RENEWABLE
        int expectedLifeTime,
        boolean expectedRenewable) throws Exception {

    KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
    Config.refresh();

    System.setProperty("test.kdc.ttl.value", ticketLifetime);

    if (forceTill) {
        System.setProperty("test.kdc.force.till", "");
    } else {
        System.clearProperty("test.kdc.force.till");
    }

    Context c = Context.fromJAAS("client");

    GSSCredential cred = Subject.doAs(c.s(),
            (PrivilegedExceptionAction<GSSCredential>)
            ()-> {
                GSSManager m = GSSManager.getInstance();
                return m.createCredential(GSSCredential.INITIATE_ONLY);
            });

    KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)
            .iterator().next();
    System.out.println(tgt);

    int actualLifeTime = cred.getRemainingLifetime();
    if (actualLifeTime < (expectedLifeTime - 60 )
            || actualLifeTime > (expectedLifeTime + 60)) {
        throw new Exception("actualLifeTime is " + actualLifeTime +
                  " ExpectedLifeTime is " + expectedLifeTime);
    }

    if (tgt.isRenewable() != expectedRenewable) {
        throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());
    }
}
 
Example 17
Source File: LongLife.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void test(
        KDC kdc,
        String ticketLifetime,
        boolean forceTill, // if true, KDC will not try RENEWABLE
        int expectedLifeTime,
        boolean expectedRenewable) throws Exception {

    KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
    Config.refresh();

    System.setProperty("test.kdc.ttl.value", ticketLifetime);

    if (forceTill) {
        System.setProperty("test.kdc.force.till", "");
    } else {
        System.clearProperty("test.kdc.force.till");
    }

    Context c = Context.fromJAAS("client");

    GSSCredential cred = Subject.doAs(c.s(),
            (PrivilegedExceptionAction<GSSCredential>)
            ()-> {
                GSSManager m = GSSManager.getInstance();
                return m.createCredential(GSSCredential.INITIATE_ONLY);
            });

    KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)
            .iterator().next();
    System.out.println(tgt);

    int actualLifeTime = cred.getRemainingLifetime();
    if (actualLifeTime < (expectedLifeTime - 60 )
            || actualLifeTime > (expectedLifeTime + 60)) {
        throw new Exception("actualLifeTime is " + actualLifeTime +
                  " ExpectedLifeTime is " + expectedLifeTime);
    }

    if (tgt.isRenewable() != expectedRenewable) {
        throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());
    }
}