Example usage for java.security AccessController doPrivilegedWithCombiner

List of usage examples for java.security AccessController doPrivilegedWithCombiner

Introduction

In this page you can find the example usage for java.security AccessController doPrivilegedWithCombiner.

Prototype

@CallerSensitive
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
        throws PrivilegedActionException 

Source Link

Document

Performs the specified PrivilegedExceptionAction with privileges enabled.

Usage

From source file:org.openremote.controller.service.Deployer.java

/**
 * Returns the system user login name, or an empty string if access to system user information
 * has been denied.//  ww w . j  av a 2  s . co m
 *
 * @return    system user login name or empty string
 */
private String getSystemUser() {
    try {
        // ----- BEGIN PRIVILEGED CODE BLOCK ------------------------------------------------------

        return AccessController.doPrivilegedWithCombiner(new PrivilegedAction<String>() {
            @Override
            public String run() {
                return System.getProperty("user.name");
            }
        });

        // ----- END PRIVILEGED CODE BLOCK --------------------------------------------------------
    }

    catch (SecurityException e) {
        log.info("Security manager has denied access to user login name: {0}", e, e.getMessage());

        return "";
    }
}