@Override
    public Optional<ExpirationPolicy> toExpirationPolicy() {
        val clientInfo = ClientInfoHolder.getClientInfo();
        
        if (clientInfo != null && !userAgents.isEmpty() && StringUtils.isNotBlank(clientInfo.getUserAgent())) {
            val timeToLive = userAgents
                .keySet()
                .stream()
                .filter(u -> RegexUtils.find(u, clientInfo.getUserAgent()))
                .findFirst()
                .map(u -> userAgents.get(u))
                .orElse(-1L);
            if (timeToLive >= 0) {
                return Optional.of(new HardTimeoutExpirationPolicy(timeToLive));
            }
        }

        if (clientInfo != null && !ipAddresses.isEmpty() && StringUtils.isNotBlank(clientInfo.getClientIpAddress())) {
            val timeToLive = ipAddresses
                .keySet()
                .stream()
                .filter(u -> RegexUtils.find(u, clientInfo.getClientIpAddress()))
                .findFirst()
                .map(u -> ipAddresses.get(u))
                .orElse(-1L);
            if (timeToLive >= 0) {
                return Optional.of(new HardTimeoutExpirationPolicy(timeToLive));
            }
        }

        return getMaxTimeToLiveInSeconds() > 0
            ? Optional.of(new HardTimeoutExpirationPolicy(getMaxTimeToLiveInSeconds()))
            : Optional.empty();
    }
This is {@link DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy}.

@author Misagh Moayyed
@since 6.3.0
core/cas-server-core-services-api/src/main/java/org/apereo/cas/services/DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy.java