jdk.jfr.FlightRecorderPermission Java Examples

The following examples show how to use jdk.jfr.FlightRecorderPermission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long newRecording() {
    MBeanUtils.checkControl();
    getRecorder(); // ensure notification listener is setup
    return AccessController.doPrivileged(new PrivilegedAction<Recording>() {
        @Override
        public Recording run() {
            return new Recording();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder")).getId();
}
 
Example #2
Source File: PrivateAccess.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static PrivateAccess getInstance() {
    // Can't be initialized in <clinit> because it may
    // deadlock with FlightRecordeerPermission.<clinit>
    if (instance == null) {
        // Will trigger
        // FlightRecordeerPermission.<clinit>
        // which will call PrivateAccess.setPrivateAccess
        new FlightRecorderPermission(Utils.REGISTER_EVENT);
    }
    return instance;
}
 
Example #3
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
    MXBeanListener mxbeanListener = new MXBeanListener(listener, filter, handback);
    listeners.add(mxbeanListener);
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        @Override
        public Void run(){
            FlightRecorder.addListener(mxbeanListener);
            return null;
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));
    super.addNotificationListener(listener, filter, handback);
}
 
Example #4
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private FlightRecorder getRecorder() throws SecurityException {
    // Synchronize on some private object that is always available
    synchronized (streamHandler) {
        if (recorder == null) {
            recorder = AccessController.doPrivileged(new PrivilegedAction<FlightRecorder>() {
                @Override
                public FlightRecorder run() {
                    return FlightRecorder.getFlightRecorder();
                }
            }, null, new FlightRecorderPermission("accessFlightRecorder"));
        }
        return recorder;
    }
}
 
Example #5
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long newRecording() {
    MBeanUtils.checkControl();
    getRecorder(); // ensure notification listener is setup
    return AccessController.doPrivileged(new PrivilegedAction<Recording>() {
        @Override
        public Recording run() {
            return new Recording();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder")).getId();
}
 
Example #6
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<EventTypeInfo> getEventTypes() {
    MBeanUtils.checkMonitor();
    List<EventType> eventTypes = AccessController.doPrivileged(new PrivilegedAction<List<EventType>>() {
        @Override
        public List<EventType> run() {
            return ManagementSupport.getEventTypes();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));

    return MBeanUtils.transformList(eventTypes, EventTypeInfo::new);
}
 
Example #7
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<EventTypeInfo> getEventTypes() {
    MBeanUtils.checkMonitor();
    List<EventType> eventTypes = AccessController.doPrivileged(new PrivilegedAction<List<EventType>>() {
        @Override
        public List<EventType> run() {
            return ManagementSupport.getEventTypes();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));

    return MBeanUtils.transformList(eventTypes, EventTypeInfo::new);
}
 
Example #8
Source File: PrivateAccess.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static PrivateAccess getInstance() {
    // Can't be initialized in <clinit> because it may
    // deadlock with FlightRecordeerPermission.<clinit>
    if (instance == null) {
        // Will trigger
        // FlightRecordeerPermission.<clinit>
        // which will call PrivateAccess.setPrivateAccess
        new FlightRecorderPermission(Utils.REGISTER_EVENT);
    }
    return instance;
}
 
Example #9
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
    MXBeanListener mxbeanListener = new MXBeanListener(listener, filter, handback);
    listeners.add(mxbeanListener);
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        @Override
        public Void run(){
            FlightRecorder.addListener(mxbeanListener);
            return null;
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));
    super.addNotificationListener(listener, filter, handback);
}
 
Example #10
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private FlightRecorder getRecorder() throws SecurityException {
    // Synchronize on some private object that is always available
    synchronized (streamHandler) {
        if (recorder == null) {
            recorder = AccessController.doPrivileged(new PrivilegedAction<FlightRecorder>() {
                @Override
                public FlightRecorder run() {
                    return FlightRecorder.getFlightRecorder();
                }
            }, null, new FlightRecorderPermission("accessFlightRecorder"));
        }
        return recorder;
    }
}
 
Example #11
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long newRecording() {
    MBeanUtils.checkControl();
    getRecorder(); // ensure notification listener is setup
    return AccessController.doPrivileged(new PrivilegedAction<Recording>() {
        @Override
        public Recording run() {
            return new Recording();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder")).getId();
}
 
Example #12
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<EventTypeInfo> getEventTypes() {
    MBeanUtils.checkMonitor();
    List<EventType> eventTypes = AccessController.doPrivileged(new PrivilegedAction<List<EventType>>() {
        @Override
        public List<EventType> run() {
            return ManagementSupport.getEventTypes();
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));

    return MBeanUtils.transformList(eventTypes, EventTypeInfo::new);
}
 
Example #13
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private FlightRecorder getRecorder() throws SecurityException {
    // Synchronize on some private object that is always available
    synchronized (streamHandler) {
        if (recorder == null) {
            recorder = AccessController.doPrivileged(new PrivilegedAction<FlightRecorder>() {
                @Override
                public FlightRecorder run() {
                    return FlightRecorder.getFlightRecorder();
                }
            }, null, new FlightRecorderPermission("accessFlightRecorder"));
        }
        return recorder;
    }
}
 
Example #14
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
    MXBeanListener mxbeanListener = new MXBeanListener(listener, filter, handback);
    listeners.add(mxbeanListener);
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
        @Override
        public Void run(){
            FlightRecorder.addListener(mxbeanListener);
            return null;
        }
    }, null, new FlightRecorderPermission("accessFlightRecorder"));
    super.addNotificationListener(listener, filter, handback);
}
 
Example #15
Source File: PrivateAccess.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static PrivateAccess getInstance() {
    // Can't be initialized in <clinit> because it may
    // deadlock with FlightRecordeerPermission.<clinit>
    if (instance == null) {
        // Will trigger
        // FlightRecordeerPermission.<clinit>
        // which will call PrivateAccess.setPrivateAccess
        new FlightRecorderPermission(Utils.REGISTER_EVENT);
    }
    return instance;
}
 
Example #16
Source File: JFRSecurityTestSuite.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void doInConstrainedEnvironment() throws Throwable {
    checkNoDirectAccess();

    assertPermission(() -> {
                FlightRecorder.getFlightRecorder();
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                FlightRecorder.register(MyEvent.class);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.unregister(MyEvent.class);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.addPeriodicEvent(MyEvent.class, periodicEvent);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.removePeriodicEvent(periodicEvent);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.addListener(frl);
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
            FlightRecorder.removeListener(frl);
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                new MyEvent().commit();
            }, FlightRecorderPermission.class, "registerEvent", true);

    assertPermission(() -> {
                    Configuration.create(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                EventFactory.create(new ArrayList<AnnotationElement>(),
                        new ArrayList<ValueDescriptor>());
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                new AnnotationElement(Name.class, "com.example.HelloWorld");
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
            new ValueDescriptor(MyEvent.class, "",
                    new ArrayList<AnnotationElement>());
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                new Recording();
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                    new RecordingFile(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                    RecordingFile.readAllEvents(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                    EventType.getEventType(MyEvent2.class);
            }, FlightRecorderPermission.class, "registerEvent", true);
}
 
Example #17
Source File: SecuritySupport.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void registerEvent(Class<? extends Event> eventClass) {
    doPrivileged(() -> FlightRecorder.register(eventClass), new FlightRecorderPermission(Utils.REGISTER_EVENT));
}
 
Example #18
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void checkRegisterPermission() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(REGISTER_EVENT));
    }
}
 
Example #19
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void checkAccessFlightRecorder() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(ACCESS_FLIGHT_RECORDER));
    }
}
 
Example #20
Source File: JFRSecurityTestSuite.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void doInConstrainedEnvironment() throws Throwable {
    checkNoDirectAccess();

    assertPermission(() -> {
                FlightRecorder.getFlightRecorder();
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                FlightRecorder.register(MyEvent.class);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.unregister(MyEvent.class);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.addPeriodicEvent(MyEvent.class, periodicEvent);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.removePeriodicEvent(periodicEvent);
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                FlightRecorder.addListener(frl);
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
            FlightRecorder.removeListener(frl);
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                new MyEvent().commit();
            }, FlightRecorderPermission.class, "registerEvent", true);

    assertPermission(() -> {
                    Configuration.create(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                EventFactory.create(new ArrayList<AnnotationElement>(),
                        new ArrayList<ValueDescriptor>());
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                new AnnotationElement(Name.class, "com.example.HelloWorld");
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
            new ValueDescriptor(MyEvent.class, "",
                    new ArrayList<AnnotationElement>());
            }, FlightRecorderPermission.class, "registerEvent", false);

    assertPermission(() -> {
                new Recording();
            }, FlightRecorderPermission.class, "accessFlightRecorder", false);

    assertPermission(() -> {
                    new RecordingFile(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                    RecordingFile.readAllEvents(Paths.get(protectedLocationPath));
            }, FilePermission.class, protectedLocationPath, false);

    assertPermission(() -> {
                    EventType.getEventType(MyEvent2.class);
            }, FlightRecorderPermission.class, "registerEvent", true);
}
 
Example #21
Source File: SecuritySupport.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void registerEvent(Class<? extends Event> eventClass) {
    doPrivileged(() -> FlightRecorder.register(eventClass), new FlightRecorderPermission(Utils.REGISTER_EVENT));
}
 
Example #22
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void checkRegisterPermission() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(REGISTER_EVENT));
    }
}
 
Example #23
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void checkAccessFlightRecorder() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(ACCESS_FLIGHT_RECORDER));
    }
}
 
Example #24
Source File: SecuritySupport.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void registerEvent(Class<? extends Event> eventClass) {
    doPrivileged(() -> FlightRecorder.register(eventClass), new FlightRecorderPermission(Utils.REGISTER_EVENT));
}
 
Example #25
Source File: Utils.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void checkRegisterPermission() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(REGISTER_EVENT));
    }
}
 
Example #26
Source File: Utils.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void checkAccessFlightRecorder() throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new FlightRecorderPermission(ACCESS_FLIGHT_RECORDER));
    }
}