
com.helger.commons.lang.priviledged.IPrivilegedAction Maven / Gradle / Ivy
/**
* Copyright (C) 2014-2019 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.commons.lang.priviledged;
import java.net.Authenticator;
import java.net.ProxySelector;
import java.security.PrivilegedAction;
import java.util.Properties;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.helger.commons.ValueEnforcer;
/**
* Extension to {@link PrivilegedAction} with an {@link #invokeSafe()} method
* that invokes the {@link java.security.AccessController} only if a security
* manager is present.
*
* @author Philip Helger
* @param
* The action return type.
*/
@FunctionalInterface
public interface IPrivilegedAction extends PrivilegedAction
{
/**
* @return The result of {@link #run()} dependent if a system manager is
* installed or not.
*/
@Nullable
default T invokeSafe ()
{
if (System.getSecurityManager () == null)
{
// No need to use AccessController
return run ();
}
return AccessControllerHelper.call (this);
}
@Nonnull
static IPrivilegedAction
© 2015 - 2025 Weber Informatics LLC | Privacy Policy