All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nimbusds.openid.connect.provider.spi.impl.common.RefreshTokenConfig Maven / Gradle / Ivy

package com.nimbusds.openid.connect.provider.spi.impl.common;


import com.thetransactioncompany.util.PropertyParseException;
import com.thetransactioncompany.util.PropertyRetriever;
import net.jcip.annotations.Immutable;

import java.util.Optional;
import java.util.Properties;


/**
 * Refresh token configuration.
 */
@Immutable
public final class RefreshTokenConfig {


        /**
         * Enables / disables refresh token issue.
         */
        public final boolean issue;


        /**
         * The refresh token lifetime, in seconds. If -1 the default configured
         * Connect2id server setting applies.
         */
        public final long lifetime;


        /**
         * The maximum refresh token idle time, in seconds. If zero no maximum
         * idle time expiration.
         */
        public final long maxIdleTime;


        /**
         * Enables / disables refresh token rotation. If empty the default
         * configured Connect2id server setting applies.
         */
        public final Optional rotate;


        /**
         * Creates a new refresh token configuration from the specified
         * properties.
         *
         * @param prefix The properties prefix. Must not be {@code null}.
         * @param props  The properties. Must not be {@code null}.
         *
         * @throws PropertyParseException On a missing or invalid property.
         */
        public RefreshTokenConfig(final String prefix, final Properties props)
                throws PropertyParseException {

                var pr = new PropertyRetriever(props, true);
                issue = pr.getOptBoolean(prefix + "refreshToken.issue", true);
                lifetime = pr.getOptLong(prefix + "refreshToken.lifetime", -1);
                maxIdleTime = pr.getOptLong(prefix + "refreshToken.maxIdleTime", 0);
                rotate = pr.getOptBoolean(prefix + "refreshToken.rotate", Optional.empty());
        }


        /**
         * Logs the configuration.
         *
         * @param logPrefix The log prefix to use.
         */
        public void log(final String logPrefix) {

                Loggers.MAIN.info("[" + logPrefix + "0106] Refresh token issue: {}", issue);

                if (! issue) {
                        return;
                }

                Loggers.MAIN.info("[" + logPrefix + "0107] Refresh token lifetime: {}", lifetime > -1 ? lifetime : "default");
                Loggers.MAIN.info("[" + logPrefix + "0108] Refresh token max idle time: {}", maxIdleTime);
                Loggers.MAIN.info("[" + logPrefix + "0109] Refresh token rotate: {}", rotate.isPresent() ? rotate.get() : "default");
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy