use of org.osgi.service.permissionadmin.PermissionInfo in project stanbol by apache.
the class PermissionDefinitionsTest method setUp.
@Before
public void setUp() {
final ImmutableGraph graph = Parser.getInstance().parse(getClass().getResourceAsStream("systemgraph.nt"), "text/rdf+n3");
this.permissionDefinitions = new PermissionDefinitions(new SimpleGraph(graph.iterator()));
this.allPermissions = new PermissionInfo[] { new PermissionInfo("(java.io.FilePermission \"file:///home/foo/-\" \"read,write,delete\")"), new PermissionInfo("(java.io.FilePermission \"file:///home/foo/*\" \"read,write\")"), new PermissionInfo("(java.io.FilePermission \"file:///home/*\" \"read,write\")") };
this.nullPermission = null;
}
use of org.osgi.service.permissionadmin.PermissionInfo in project stanbol by apache.
the class PermissionDefinitions method retrievePermissions.
/**
* Returns the permissions of a specified location.
* I.e. the permissions of all permission assignments matching <code>location</code>.
*
* @param location the location of a bundle
* @return an array with <code>PermissionInfo</code> elements
*/
PermissionInfo[] retrievePermissions(String location) {
List<PermissionInfo> permInfoList = new ArrayList<PermissionInfo>();
Iterator<Triple> ownerTriples = systemGraph.filter(new IRI(location), OSGI.owner, null);
if (ownerTriples.hasNext()) {
BlankNodeOrIRI user = (BlankNodeOrIRI) ownerTriples.next().getObject();
lookForPermissions(user, permInfoList);
}
if (permInfoList.isEmpty()) {
return null;
}
return permInfoList.toArray(new PermissionInfo[permInfoList.size()]);
}
use of org.osgi.service.permissionadmin.PermissionInfo in project stanbol by apache.
the class PermissionDefinitions method lookForPermissions.
/**
* Look for all permissions of a role and add them to a list.
* And if the role has another role, then execute this function recursively,
* until all permissions are found.
*
* @param role a <code>BlankNodeOrIRI</code> which is either a user or a role
* @param permInfoList a list with all the added permissions of this bundle
*/
private void lookForPermissions(BlankNodeOrIRI role, List<PermissionInfo> permInfoList) {
Iterator<Triple> permissionTriples = systemGraph.filter(role, PERMISSION.hasPermission, null);
while (permissionTriples.hasNext()) {
BlankNodeOrIRI permission = (BlankNodeOrIRI) permissionTriples.next().getObject();
Iterator<Triple> javaPermissionTriples = systemGraph.filter(permission, PERMISSION.javaPermissionEntry, null);
while (javaPermissionTriples.hasNext()) {
Triple t = javaPermissionTriples.next();
Literal permEntry = (Literal) t.getObject();
permInfoList.add(new PermissionInfo(permEntry.getLexicalForm()));
}
}
Iterator<Triple> roleTriples = systemGraph.filter(role, SIOC.has_function, null);
while (roleTriples.hasNext()) {
BlankNodeOrIRI anotherRole = (BlankNodeOrIRI) roleTriples.next().getObject();
this.lookForPermissions(anotherRole, permInfoList);
}
}
use of org.osgi.service.permissionadmin.PermissionInfo in project bnd by bndtools.
the class SimplePermissionPolicy method parse.
/**
* Parse a permission info file.
*/
public PermissionInfo[] parse(InputStream in) throws IOException {
PermissionInfo[] info = null;
if (in != null) {
List<PermissionInfo> permissions = new ArrayList<PermissionInfo>();
try (BufferedReader reader = IO.reader(in, UTF_8)) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if ((line.length() == 0) || line.startsWith("#") || line.startsWith("//"))
/* comments */
continue;
try {
permissions.add(new PermissionInfo(line));
} catch (IllegalArgumentException iae) {
/* incorrectly encoded permission */
System.err.println("Permission incorrectly encoded: " + line + " " + iae);
}
}
}
int size = permissions.size();
if (size > 0) {
info = permissions.toArray(new PermissionInfo[0]);
}
}
return info;
}
use of org.osgi.service.permissionadmin.PermissionInfo in project aries by apache.
the class PermissionAdmin method listDefaultPermissions.
/**
* @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#listDefaultPermissions()
*/
public String[] listDefaultPermissions() throws IOException {
PermissionInfo[] permissions = permAdmin.getDefaultPermissions();
if (permissions != null) {
String[] encoded = new String[permissions.length];
for (int i = 0; i < permissions.length; i++) {
PermissionInfo info = permissions[i];
encoded[i] = info.getEncoded();
}
return encoded;
}
return null;
}
Aggregations