private void loadTokens()

in src/main/java/org/apache/sling/auth/saml2/impl/TokenStore.java [321:369]


    private void loadTokens() {
        if (tokenFile.isFile() && tokenFile.canRead()) {
            DataInputStream keyInputStream = null;
            try(FileInputStream fin = new FileInputStream(tokenFile)) {
                keyInputStream = new DataInputStream(fin);
                int newCurrentToken = keyInputStream.readInt();
                long newNextUpdate = keyInputStream.readLong();
                SecretKey[] newKeys = new SecretKey[TOKEN_BUFFER_SIZE];
                for (int i = 0; i < newKeys.length; i++) {
                    int isNull = keyInputStream.readInt();
                    if (isNull == 1) {
                        int l = keyInputStream.readInt();
                        byte[] b = new byte[l];
                        int readBytes = keyInputStream.read(b);
                        if (readBytes != l){
                            throw new IOException("could not confirm bytes read");
                        }
                        newKeys[i] = new SecretKeySpec(b, ALGORITHM);
                    } else {
                        newKeys[i] = null;
                    }
                }

                // assign the tokes and schedule a next update
                nextUpdate = newNextUpdate;
                currentToken = newCurrentToken;
                currentTokens = newKeys;

            } catch (IOException e) {
                log.error("Failed to load cookie keys {}", e.getMessage());
            } finally {

                if (keyInputStream != null) {
                    try {
                        keyInputStream.close();
                    } catch (IOException e) {
                        log.warn("failed to close steam {}", e.getMessage());
                    }
                }
            }
        }

        // if there was a failure to read the current tokens, create new ones
        if (currentTokens == null) {
            currentTokens = new SecretKey[TOKEN_BUFFER_SIZE];
            nextUpdate = System.currentTimeMillis();
            currentToken = 0;
        }
    }