List of usage examples for java.security AccessController getContext
public static AccessControlContext getContext()
From source file:org.elasticsearch.hadoop.script.GroovyScriptEngineService.java
public GroovyScriptEngineService(Settings settings) { super(settings); deprecationLogger.deprecated("[groovy] scripts are deprecated, use [painless] scripts instead"); // Creates the classloader here in order to isolate Groovy-land code final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); }/*from www. j ava 2 s . c o m*/ this.loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { // snapshot our context (which has permissions for classes), since the script has none AccessControlContext context = AccessController.getContext(); return new ClassLoader(getClass().getClassLoader()) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (sm != null) { try { context.checkPermission(new ClassPermission(name)); } catch (SecurityException e) { throw new ClassNotFoundException(name, e); } } return super.loadClass(name, resolve); } }; }); }
From source file:org.jbpm.security.authentication.SubjectAuthenticationService.java
public String getActorId() { if (actorId == null) { Subject subject = Subject.getSubject(AccessController.getContext()); if (subject == null) { log.warn("no subject exists! cannot get actorId"); return null; }/*from w ww. j ava 2 s .c o m*/ Set principals = subject.getPrincipals(principalClass); if (principals != null && !principals.isEmpty()) { // always use the first one (so be patient what Principal classes are used) Principal principal = (Principal) principals.iterator().next(); actorId = principal.getName(); } } return actorId; }