@Override
    public <T> Optional<T> execute(final Object lockKey, final Supplier<T> consumer) {
        return Unchecked.supplier(() -> {
            val lock = lockRegistry.obtain(lockKey);
            val lockFound = lock.tryLock(LOCK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            return Optional.of(lockFound)
                .filter(Boolean::booleanValue)
                .map(result -> {
                    try {
                        return consumer.get();
                    } finally {
                        lock.unlock();
                    }
                });
        }).get();
    }
This is {@link DefaultLockRepository}.

@author Misagh Moayyed
@since 6.5.0
api/cas-server-core-api-util/src/main/java/org/apereo/cas/util/lock/DefaultLockRepository.java