Example usage for java.security Permissions Permissions

List of usage examples for java.security Permissions Permissions

Introduction

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

Prototype

public Permissions() 

Source Link

Document

Creates a new Permissions object containing no PermissionCollections.

Usage

From source file:de.innovationgate.wgpublisher.expressions.tmlscript.IsolatedJARLoader.java

@Override
protected PermissionCollection getPermissions(CodeSource arg0) {
    Permissions permissions = new Permissions();
    permissions.add(new AllPermission());
    return permissions;
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.PermissionsListProtectionDomainProvider.java

protected PermissionCollection getPermissionCollection() {
    Permissions permissionCollection = new Permissions();
    if (permissions != null) {
        for (Permission permission : permissions) {
            permissionCollection.add(permission);
        }//from  ww  w.  j  a va2 s .  co  m
    }
    return permissionCollection;
}

From source file:com.sun.socialsite.business.impl.JPAPermissionManagerImpl.java

private Permissions getPermissions(SecurityToken token) throws SocialSiteException {

    try {/*from www  . ja v  a 2 s .  c  om*/

        Permissions permissions = new Permissions();
        List<PermissionGrant> permissionGrants = new ArrayList<PermissionGrant>();

        if (token != null) {
            if (token instanceof SocialSiteToken && ((SocialSiteToken) token).isForContainerPage()) {
                permissions.add(new FeaturePermission("*"));
            }
            if (token.getAppId() != null) {
                App app = Factory.getSocialSite().getAppManager().getApp(token.getAppId());
                permissionGrants.addAll(getPermissionGrants(app, 0, -1));
                permissionGrants.addAll(getPermissionGrants(app.getURL().getHost(), 0, -1));
            }
            if (token.getViewerId() != null) {
                Profile viewer = Factory.getSocialSite().getProfileManager()
                        .getProfileByUserId(token.getViewerId());
                permissionGrants.addAll(getPermissionGrants(viewer, 0, -1));
            }
        }

        for (PermissionGrant permissionGrant : permissionGrants) {
            String type = permissionGrant.getType();
            String name = permissionGrant.getName();
            String actions = permissionGrant.getActions();
            try {
                Class<?> clazz = Class.forName(type);
                Permission permission = null;
                if (actions == null) {
                    Constructor constructor = clazz.getConstructor(String.class);
                    permission = (Permission) (constructor.newInstance(name));
                } else {
                    Constructor constructor = clazz.getConstructor(String.class, String.class);
                    permission = (Permission) (constructor.newInstance(name, actions));
                }
                permissions.add(permission);
            } catch (Exception e) {
                String msg = String.format("Failed to construct Permission(type=%s,name=%s,actions=%s)", type,
                        name, actions);
                log.error(msg, e);
            }
        }

        return permissions;

    } catch (Exception e) {
        log.error("token=" + token);
        throw (SocialSiteException) ((e instanceof SocialSiteException) ? e : new SocialSiteException(e));
    }

}

From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java

/**
 * @see org.apache.jetspeed.security.PermissionManager#getPermissions(java.security.Principal)
 *//*  w  ww  . ja  va 2  s .  c o  m*/
public Permissions getPermissions(Principal principal) {
    String fullPath = SecurityHelper.getPreferencesFullPath(principal);
    ArgUtil.notNull(new Object[] { fullPath }, new String[] { "fullPath" },
            "removePermission(java.security.Principal)");

    // Remove permissions on principal.
    InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath);
    Collection internalPermissions = new ArrayList();
    if (null != internalPrincipal) {
        internalPermissions = internalPrincipal.getPermissions();
    }
    Permissions permissions = new Permissions();
    appendSecurityPermissions(internalPermissions, permissions);
    return permissions;
}

From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java

/**
 * @see org.apache.jetspeed.security.PermissionManager#getPermissions(java.util.Collection)
 *//*from   w w  w  .java  2 s.  c  o m*/
public Permissions getPermissions(Collection principals) {
    ArgUtil.notNull(new Object[] { principals }, new String[] { "principals" },
            "getPermissions(java.util.Collection)");

    Permissions permissions = new Permissions();
    Collection principalsFullPath = getPrincipalsFullPath(principals);
    if ((null != principalsFullPath) && principalsFullPath.size() > 0) {
        Criteria filter = new Criteria();
        filter.addIn("fullPath", principalsFullPath);
        Query query = QueryFactory.newQuery(InternalPrincipalImpl.class, filter);
        Collection internalPrincipals = broker.getCollectionByQuery(query);
        Iterator internalPrincipalsIter = internalPrincipals.iterator();
        while (internalPrincipalsIter.hasNext()) {
            InternalPrincipal internalPrincipal = (InternalPrincipal) internalPrincipalsIter.next();
            Collection internalPermissions = internalPrincipal.getPermissions();
            if (null != internalPermissions) {
                permissions = appendSecurityPermissions(internalPermissions, permissions);
            }
        }
    }
    return permissions;
}

From source file:org.pegadi.client.ApplicationLauncher.java

private static void setAllPermissions() {
    // give all permissions. needed when run from java web start, because
    // the rmi classloaders don't heed the security settings in the .jnlp
    // file.//from  w  w w . j av  a 2s  .  com
    try {
        Policy.setPolicy(new Policy() {
            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                return (perms);
            }

            public void refresh() {
            }
        });
    } catch (Exception wse) {
        LoggerFactory.getLogger(ApplicationLauncher.class).error("Error setting policies", wse);
        System.exit(-1);
    }
}

From source file:com.googlecode.onevre.utils.ServerClassLoader.java

/**
 *
 * @see java.security.SecureClassLoader#getPermissions(
 *     java.security.CodeSource)//from  w  w  w .  j ava2 s .  co  m
 */
protected PermissionCollection getPermissions(CodeSource codesource) {
    boolean isAcceptable = false;
    if (!CHECKED.containsKey(codesource.getLocation())) {
        Certificate[] certs = codesource.getCertificates();
        if (certs == null || certs.length == 0) {
            JOptionPane.showMessageDialog(null, "The jar at " + codesource.getLocation() + " is not signed!",
                    "Security Error", JOptionPane.ERROR_MESSAGE);
            isAcceptable = false;
        } else {
            isAcceptable = true;
            for (int i = 0; (i < certs.length) && isAcceptable; i++) {
                if (!verifyCertificate((X509Certificate) certs[i])) {
                    isAcceptable = false;
                }
            }
        }
        CHECKED.put(codesource.getLocation(), isAcceptable);
    } else {
        isAcceptable = CHECKED.get(codesource.getLocation());
    }

    Permissions permissions = new Permissions();
    if (isAcceptable) {
        permissions.add(new AllPermission());
        return permissions;
    }
    throw new SecurityException("Access denied to " + codesource.getLocation());
}

From source file:com.seeburger.vfs2.util.VFSClassLoader.java

/**
 * Calls super.getPermissions both for the code source and also
 * adds the permissions granted to the parent layers.
 * @param cs the CodeSource./*ww  w.  j  av  a  2 s . c  o m*/
 * @return The PermissionCollections.
 */
@Override
protected PermissionCollection getPermissions(final CodeSource cs) {
    try {
        final String url = cs.getLocation().toString();
        FileObject file = lookupFileObject(url);
        if (file == null) {
            return super.getPermissions(cs);
        }

        FileObject parentLayer = file.getFileSystem().getParentLayer();
        if (parentLayer == null) {
            return super.getPermissions(cs);
        }

        Permissions combi = new Permissions();
        PermissionCollection permCollect = super.getPermissions(cs);
        copyPermissions(permCollect, combi);

        for (FileObject parent = parentLayer; parent != null; parent = parent.getFileSystem()
                .getParentLayer()) {
            final CodeSource parentcs = new CodeSource(parent.getURL(), parent.getContent().getCertificates());
            permCollect = super.getPermissions(parentcs);
            copyPermissions(permCollect, combi);
        }

        return combi;
    } catch (final FileSystemException fse) {
        throw new SecurityException(fse.getMessage());
    }
}

From source file:net.datenwerke.sandbox.SandboxLoader.java

@Override
protected Class<?> loadClass(final String name, boolean resolve) throws ClassNotFoundException {
    Class clazz = null;/*from w  w  w. jav  a2  s .  c o  m*/

    if (debug)
        logger.log(Level.INFO,
                getName() + "(" + System.identityHashCode(this) + ")" + " about to load class: " + name);

    if (null != enhancer)
        enhancer.classtoBeLoaded(this, name, resolve);

    boolean trustedSource = false;

    if (name.startsWith("java.") || bypassClazz(name)) {
        clazz = super.loadClass(name, resolve);

        /* check if it comes from an available jar */
        if (!name.startsWith("java.") && null != whitelistedUcp) {
            String path = name.replace('.', '/').concat(".class");

            Resource res = whitelistedUcp.getResource(path, false);
            if (res != null)
                trustedSource = true;
        }

    } else {
        /* check subcontext */
        if (hasSubloaders) {
            SandboxLoader subLoader = doGetSubLoaderByClassContext(name);
            if (null != subLoader)
                return subLoader.loadClass(name, resolve);
        }

        /* check if we have already handeled this class */
        clazz = findLoadedClass(name);
        if (clazz != null) {
            if (null != whitelistedUcp) {
                String path = name.replace('.', '/').concat(".class");
                Resource res = whitelistedUcp.getResource(path, false);
                if (res != null)
                    trustedSource = true;
            }
        } else {
            try {
                String basePath = name.replace('.', '/');
                String path = basePath.concat(".class");

                ProtectionDomain domain = null;
                try {
                    CodeSource codeSource = new CodeSource(new URL("file", "", codesource.concat(basePath)),
                            (java.security.cert.Certificate[]) null);
                    domain = new ProtectionDomain(codeSource, new Permissions(), this, null);
                } catch (MalformedURLException e) {
                    throw new RuntimeException("Could not create protection domain.");
                }

                /* define package */
                int i = name.lastIndexOf('.');
                if (i != -1) {
                    String pkgName = name.substring(0, i);
                    java.lang.Package pkg = getPackage(pkgName);
                    if (pkg == null) {
                        definePackage(pkgName, null, null, null, null, null, null, null);
                    }
                }

                /* first strategy .. check jars */
                if (null != whitelistedUcp) {
                    Resource res = whitelistedUcp.getResource(path, false);
                    if (res != null) {
                        byte[] cBytes = enhance(name, res.getBytes());
                        clazz = defineClass(name, cBytes, 0, cBytes.length, domain);
                        trustedSource = true;
                    }
                }

                /* load class */
                if (clazz == null) {
                    InputStream in = null;
                    try {
                        /* we only load from local sources */
                        in = parent.getResourceAsStream(path);
                        byte[] cBytes = null;
                        if (in != null)
                            cBytes = IOUtils.toByteArray(in);

                        if (null == cBytes && null != enhancer)
                            cBytes = enhancer.loadClass(this, name);
                        if (null == cBytes)
                            throw new ClassNotFoundException("Could not find " + name);

                        /* load and define class */
                        cBytes = enhance(name, cBytes);
                        clazz = defineClass(name, cBytes, 0, cBytes.length, domain);
                    } finally {
                        if (null != in) {
                            try {
                                in.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }

                /* do we need to resolve */
                if (resolve)
                    resolveClass(clazz);
            } catch (IOException e) {
                throw new ClassNotFoundException("Could not load " + name, e);
            } catch (Exception e) {
                throw new ClassNotFoundException("Could not load " + name, e);
            }
        }
    }

    if (!trustedSource && null != clazz && null != securityManager)
        securityManager.checkClassAccess(name);

    if (null != enhancer)
        enhancer.classLoaded(this, name, clazz);

    return clazz;
}

From source file:net.datenwerke.sandbox.SandboxLoader.java

public Class<?> defineClass(String name, byte[] classBytes, boolean enhanceClass) {
    securityManager.checkPermission(new SandboxRuntimePermission("defineClass"));

    Class<?> clazz = findLoadedClass(name);
    if (null != clazz)
        return clazz;

    if (enhanceClass) {
        try {/*from w  ww.  j a  va 2 s . co  m*/
            classBytes = enhance(name, classBytes);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    ProtectionDomain domain = null;
    try {
        CodeSource codeSource = new CodeSource(new URL("file", "", codesource),
                (java.security.cert.Certificate[]) null);
        domain = new ProtectionDomain(codeSource, new Permissions(), this, null);
    } catch (MalformedURLException e) {
        throw new RuntimeException("Could not create protection domain.");
    }

    return defineClass(name, classBytes, 0, classBytes.length, domain);
}