Home » Java programming language

Java SecurityManager getSecurityContext() method with example

SecurityManager Class getSecurityContext() method: Here, we are going to learn about the getSecurityContext() method of SecurityManager Class with its syntax and example.
Submitted by Preeti Jain, on December 18, 2019

SecurityManager Class getSecurityContext() method

  • getSecurityContext() method is available in java.lang package.
  • getSecurityContext() method is used to return an object that encapsulates or binds the current execution environment and we don't override this method so it returns an object of "AccessControlContext".
  • getSecurityContext() method is required to determine whether the untrusted method is eligible to execute on its own or not.
  • getSecurityContext() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getSecurityContext() method does not throw an exception at the time returning an object of executing the environment.


    public Object getSecurityContext();


  • It does not accept any parameter.

Return value:

The return type of this method is Object, it returns an object that encapsulates enough information of an environment executing currently to operate some security validations.


// Java program to demonstrate the example 
// of Object getSecurityContext() method of
// SecurityManager 


public class GetSecurityContext {
    public static void main(String[] args) {
        // By using setProperty() method is to set the policy property 
        // with security manager

        System.setProperty("", "file:/C:/java.policy");

        // Instantiating a SecurityManager object
        SecurityManager smgr = new SecurityManager();

        // By using setSecurityManager() method is to set the
        // security manager

        // By using getSecurityContext() method is to return the
        // object of security context
        Object ob = smgr.getSecurityContext();

        // Display ob
        System.out.println("Ob = " + ob);


Ob = [email protected]


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.