sun.security.krb5.internal.KerberosTime Java Examples

The following examples show how to use sun.security.krb5.internal.KerberosTime. 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: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #2
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #3
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #4
Source File: MemoryCache.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #5
Source File: MemoryCache.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #6
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #7
Source File: DflCache.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #8
Source File: DflCache.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #9
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #10
Source File: MemoryCache.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #11
Source File: DflCache.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #12
Source File: DflCache.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #13
Source File: DflCache.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #14
Source File: MicroTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #15
Source File: DflCache.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #16
Source File: MemoryCache.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #17
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #18
Source File: MemoryCache.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #19
Source File: DflCache.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #20
Source File: MicroTime.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 {
    // We count how many different KerberosTime values
    // can be acquired within one second.
    KerberosTime t1 = KerberosTime.now();
    KerberosTime last = t1;
    int count = 0;
    while (true) {
        KerberosTime t2 = KerberosTime.now();
        if (t2.getTime() - t1.getTime() > 1000) break;
        if (!last.equals(t2)) {
            last = t2;
            count++;
        }
    }
    // We believe a nice KerberosTime can at least tell the
    // difference of 100 musec.
    if (count < 10000) {
        throw new Exception("What? only " + (1000000/count) +
                " musec precision?");
    }
}
 
Example #21
Source File: MemoryCache.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #22
Source File: DflCache.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #23
Source File: DflCache.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #24
Source File: MemoryCache.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    AuthList rc = content.get(key);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    if (rc == null) {
        rc = new AuthList(lifespan);
        rc.put(time, currTime);
        if (!rc.isEmpty()) {
            content.put(key, rc);
        }
    } else {
        if (DEBUG) {
            System.out.println("MemoryCache: Existing AuthList:\n" + rc);
        }
        rc.put(time, currTime);
        if (rc.isEmpty()) {
            content.remove(key);
        }
    }
}
 
Example #25
Source File: DflCache.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #26
Source File: DflCache.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #27
Source File: DflCache.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void checkAndStore0(KerberosTime currTime, AuthTimeWithHash time)
        throws IOException, KrbApErrException {
    Path p = getFileName(source, time.server);
    int missed = 0;
    try (Storage s = new Storage()) {
        try {
            missed = s.loadAndCheck(p, time, currTime);
        } catch (IOException ioe) {
            // Non-existing or invalid file
            Storage.create(p);
            missed = s.loadAndCheck(p, time, currTime);
        }
        s.append(time);
    }
    if (missed > EXCESSREPS) {
        Storage.expunge(p, currTime);
    }
}
 
Example #28
Source File: MemoryCache.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    String key = time.client + "|" + time.server;
    content.computeIfAbsent(key, k -> new AuthList(lifespan))
            .put(time, currTime);
    if (DEBUG) {
        System.out.println("MemoryCache: add " + time + " to " + key);
    }
    // TODO: clean up AuthList entries with only expired AuthTimeWithHash objects.
}
 
Example #29
Source File: DflCache.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    try {
        checkAndStore0(currTime, time);
    } catch (IOException ioe) {
        KrbApErrException ke = new KrbApErrException(Krb5.KRB_ERR_GENERIC);
        ke.initCause(ioe);
        throw ke;
    }
}
 
Example #30
Source File: DflCache.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static SeekableByteChannel createNoClose(Path p)
        throws IOException {
    SeekableByteChannel newChan = Files.newByteChannel(
            p, StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING,
                StandardOpenOption.WRITE);
    ByteBuffer buffer = ByteBuffer.allocate(6);
    buffer.putShort((short)KRB5_RV_VNO);
    buffer.order(ByteOrder.nativeOrder());
    buffer.putInt(KerberosTime.getDefaultSkew());
    buffer.flip();
    newChan.write(buffer);
    return newChan;
}