public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
public PermissionInfoCollection(PermissionInfo[] permInfos) { this.permInfos = permInfos; boolean tempAllPermissions = false; for (int i = 0; i < permInfos.length && !tempAllPermissions; i++) if (permInfos[i].getType().equals(AllPermission.class.getName())) tempAllPermissions = true; this.hasAllPermission = tempAllPermissions; setReadOnly(); // collections are managed with ConditionalPermissionAdmin }
Permissions(PermissionInfo[] permissionInfos, BundleContext context, SecureAction action) { m_context = context; m_permissionInfos = permissionInfos; m_cache = new HashMap(); m_queue = new ReferenceQueue(); m_action = action; for (int i = 0; i < m_permissionInfos.length; i++) { if (m_permissionInfos[i].getType().equals( AllPermission.class.getName())) { m_allPermission = true; return; } } m_allPermission = false; }
static Permission createPermission(BundleContext ctx, PermissionInfo pi) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { String type = pi.getType(); Class<?> cls = loadClass(ctx, type, Permission.class); Constructor<?> constr = cls.getConstructor(new Class<?>[]{String.class, String.class}); String name = pi.getName(); String actions = pi.getActions(); Permission perm = (Permission) constr.newInstance(name, actions); return perm; }
/** * Checks that the current user has the specified permission. * * @param permissionString * java.security.Permission encoded as (type name actions), * e.g., (java.io.FilePermission "*" "read") * @param uriInfo */ @GET @Path("check") public void checkPermission( @QueryParam(value = "permission") final String permissionString) { if (permissionString == null) { throw new WebApplicationException( Response.status(Response.Status.BAD_REQUEST).build()); } PermissionInfo pi = new PermissionInfo(permissionString); final Permission permission; try { Constructor<?> constructor = Class.forName(pi.getType()) .getConstructor(String.class, String.class); permission = (Permission) constructor .newInstance(pi.getName(), pi.getActions()); } catch (Exception ex) { throw new WebApplicationException(ex, Response.Status.BAD_REQUEST); } AccessController.checkPermission(permission); } }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null || !(bundle instanceof AbstractBundle)) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name File target = ((AbstractBundle) bundle).getBundleData().getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null || !(bundle instanceof AbstractBundle)) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name File target = ((AbstractBundle) bundle).getBundleData().getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) { if (permissionInfos == null) return permissionInfos; PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { File target = bundle.getDataFile(permissionInfos[i].getName()); if (target != null) results[i] = new PermissionInfo(permissionInfos[i].getType(), target.getPath(), permissionInfos[i].getActions()); } catch (IllegalStateException e) { // can happen if the bundle has been uninstalled; // we just keep the original permission in this case. } } } } } return results; }
@Override public boolean isDefaultPolicy(String permtype, String permname, String actions) { AppPermissionImpl ap = getDefaultPolicies(); ConcurrentHashMap<String, ConditionalPermissionInfo> granteds = ap.granted; Set<Entry<String, ConditionalPermissionInfo>> grantedsSet = granteds.entrySet(); for (Map.Entry<String, ConditionalPermissionInfo> entry : grantedsSet) { // Create new permission info object each new entry // Multiple entries with same name are not permitted. ConditionalPermissionInfo cpi = entry.getValue(); PermissionInfo perms[] = cpi.getPermissionInfos(); for (PermissionInfo pi : perms) { if (pi.getType().equals(permtype)) { String name = pi.getName(); if (permname != null && (name == null || name.equals(permname))) { String acts = pi.getActions(); if (actions != null && acts != null) { String[] tmpActions = acts.split(","); String[] actionsArr = actions.split(","); if (Util.containsAll(tmpActions, actionsArr)) return true; } } } } } return false; }