Search in sources :

Example 1 with AppPermission

use of org.onosproject.security.AppPermission in project onos by opennetworkinglab.

the class DefaultPolicyBuilderTest method testConvertToOnosPermissions.

@Test
public void testConvertToOnosPermissions() {
    Permission testJavaPerm = new AppPermission("testName");
    List<org.onosproject.security.Permission> result = Lists.newArrayList();
    org.onosproject.security.Permission onosPerm = new org.onosproject.security.Permission(AppPermission.class.getName(), testJavaPerm.getName(), "");
    result.add(onosPerm);
    assertTrue(!result.isEmpty());
    assertEquals("TESTNAME", result.get(0).getName());
}
Also used : AppPermission(org.onosproject.security.AppPermission) ConfigurationPermission(org.osgi.service.cm.ConfigurationPermission) PackagePermission(org.osgi.framework.PackagePermission) AppPermission(org.onosproject.security.AppPermission) Permission(java.security.Permission) AdminPermission(org.osgi.framework.AdminPermission) ServicePermission(org.osgi.framework.ServicePermission) AdaptPermission(org.osgi.framework.AdaptPermission) Test(org.junit.Test)

Example 2 with AppPermission

use of org.onosproject.security.AppPermission in project onos by opennetworkinglab.

the class DefaultPolicyBuilder method getAdminApplicationPermissions.

public static List<Permission> getAdminApplicationPermissions(Set<org.onosproject.security.Permission> permissions) {
    List<Permission> perms = Lists.newArrayList();
    perms.addAll(defaultPermissions);
    perms.addAll(adminServicePermissions);
    for (AppPermission.Type perm : serviceDirectory.keySet()) {
        perms.add(new AppPermission(perm));
    }
    perms.addAll(convertToJavaPermissions(permissions));
    return optimizePermissions(perms);
}
Also used : Type(org.onosproject.security.AppPermission.Type) AppPermission(org.onosproject.security.AppPermission) PropertyPermission(java.util.PropertyPermission) FilePermission(java.io.FilePermission) AudioPermission(javax.sound.sampled.AudioPermission) SocketPermission(java.net.SocketPermission) ReflectPermission(java.lang.reflect.ReflectPermission) SSLPermission(javax.net.ssl.SSLPermission) Permission(java.security.Permission) ConfigurationPermission(org.osgi.service.cm.ConfigurationPermission) DelegationPermission(javax.security.auth.kerberos.DelegationPermission) CapabilityPermission(org.osgi.framework.CapabilityPermission) SerializablePermission(java.io.SerializablePermission) PackagePermission(org.osgi.framework.PackagePermission) NetPermission(java.net.NetPermission) AdminPermission(org.osgi.framework.AdminPermission) BundlePermission(org.osgi.framework.BundlePermission) PrivateCredentialPermission(javax.security.auth.PrivateCredentialPermission) SQLPermission(java.sql.SQLPermission) AppPermission(org.onosproject.security.AppPermission) LoggingPermission(java.util.logging.LoggingPermission) ServicePermission(org.osgi.framework.ServicePermission) AdaptPermission(org.osgi.framework.AdaptPermission) AuthPermission(javax.security.auth.AuthPermission)

Example 3 with AppPermission

use of org.onosproject.security.AppPermission in project onos by opennetworkinglab.

the class DefaultPolicyBuilder method getPermission.

private static Permission getPermission(org.onosproject.security.Permission permission) {
    String classname = permission.getClassName();
    String name = permission.getName();
    String actions = permission.getActions();
    if (classname == null || name == null) {
        return null;
    }
    classname = classname.trim();
    name = name.trim();
    actions = actions.trim();
    if (AppPermission.class.getName().equals(classname)) {
        return new AppPermission(name);
    } else if (FilePermission.class.getName().equals(classname)) {
        return new FilePermission(name, actions);
    } else if (SerializablePermission.class.getName().equals(classname)) {
        return new SerializablePermission(name, actions);
    } else if (NetPermission.class.getName().equals(classname)) {
        return new NetPermission(name, actions);
    } else if (RuntimePermission.class.getName().equals(classname)) {
        return new RuntimePermission(name, actions);
    } else if (SocketPermission.class.getName().equals(classname)) {
        return new SocketPermission(name, actions);
    } else if (SQLPermission.class.getName().equals(classname)) {
        return new SQLPermission(name, actions);
    } else if (PropertyPermission.class.getName().equals(classname)) {
        return new PropertyPermission(name, actions);
    } else if (LoggingPermission.class.getName().equals(classname)) {
        return new LoggingPermission(name, actions);
    } else if (SSLPermission.class.getName().equals(classname)) {
        return new SSLPermission(name, actions);
    } else if (AuthPermission.class.getName().equals(classname)) {
        return new AuthPermission(name, actions);
    } else if (PrivateCredentialPermission.class.getName().equals(classname)) {
        return new PrivateCredentialPermission(name, actions);
    } else if (DelegationPermission.class.getName().equals(classname)) {
        return new DelegationPermission(name, actions);
    } else if (javax.security.auth.kerberos.ServicePermission.class.getName().equals(classname)) {
        return new javax.security.auth.kerberos.ServicePermission(name, actions);
    } else if (AudioPermission.class.getName().equals(classname)) {
        return new AudioPermission(name, actions);
    } else if (AdaptPermission.class.getName().equals(classname)) {
        return new AdaptPermission(name, actions);
    } else if (BundlePermission.class.getName().equals(classname)) {
        return new BundlePermission(name, actions);
    } else if (CapabilityPermission.class.getName().equals(classname)) {
        return new CapabilityPermission(name, actions);
    } else if (PackagePermission.class.getName().equals(classname)) {
        return new PackagePermission(name, actions);
    } else if (ServicePermission.class.getName().equals(classname)) {
        return new ServicePermission(name, actions);
    } else if (AdminPermission.class.getName().equals(classname)) {
        return new AdminPermission(name, actions);
    // } else if (ConfigurationPermission.class.getName().equals(classname)) {
    // return new ConfigurationPermission(name, actions);
    } else if (ReflectPermission.class.getName().equals(classname)) {
        return new ReflectPermission(name, actions);
    }
    // AWTPermission,  ReflectPermission not allowed
    return null;
}
Also used : PropertyPermission(java.util.PropertyPermission) FilePermission(java.io.FilePermission) SQLPermission(java.sql.SQLPermission) BundlePermission(org.osgi.framework.BundlePermission) LoggingPermission(java.util.logging.LoggingPermission) AudioPermission(javax.sound.sampled.AudioPermission) SerializablePermission(java.io.SerializablePermission) PrivateCredentialPermission(javax.security.auth.PrivateCredentialPermission) AdminPermission(org.osgi.framework.AdminPermission) AuthPermission(javax.security.auth.AuthPermission) SocketPermission(java.net.SocketPermission) CapabilityPermission(org.osgi.framework.CapabilityPermission) SSLPermission(javax.net.ssl.SSLPermission) PackagePermission(org.osgi.framework.PackagePermission) DelegationPermission(javax.security.auth.kerberos.DelegationPermission) AppPermission(org.onosproject.security.AppPermission) NetPermission(java.net.NetPermission) ServicePermission(org.osgi.framework.ServicePermission) ReflectPermission(java.lang.reflect.ReflectPermission) AdaptPermission(org.osgi.framework.AdaptPermission)

Example 4 with AppPermission

use of org.onosproject.security.AppPermission in project onos by opennetworkinglab.

the class DefaultPolicyBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    List<Permission> permSet = Lists.newArrayList();
    permSet.add(new PackagePermission("*", PackagePermission.EXPORTONLY));
    permSet.add(new PackagePermission("*", PackagePermission.IMPORT));
    permSet.add(new AdaptPermission("*", AdaptPermission.ADAPT));
    permSet.add(new ConfigurationPermission("*", ConfigurationPermission.CONFIGURE));
    permSet.add(new AdminPermission("*", AdminPermission.METADATA));
    defaultPermissions = permSet;
    List<Permission> adminPermSet = Lists.newArrayList();
    adminPermSet.add(new ServicePermission(ApplicationAdminService.class.getName(), ServicePermission.GET));
    adminServicePermissions = adminPermSet;
    testPermission = new org.onosproject.security.Permission("testClass", "APP_READ", "testActions");
    testPermissions = new HashSet<org.onosproject.security.Permission>();
    testPermissions.add(testPermission);
    testJavaPerm = new AppPermission("testName");
    testJavaPerms = new HashSet<Permission>();
    testJavaPerms.add(testJavaPerm);
}
Also used : AdminPermission(org.osgi.framework.AdminPermission) PackagePermission(org.osgi.framework.PackagePermission) AppPermission(org.onosproject.security.AppPermission) ServicePermission(org.osgi.framework.ServicePermission) ConfigurationPermission(org.osgi.service.cm.ConfigurationPermission) PackagePermission(org.osgi.framework.PackagePermission) AppPermission(org.onosproject.security.AppPermission) Permission(java.security.Permission) AdminPermission(org.osgi.framework.AdminPermission) ServicePermission(org.osgi.framework.ServicePermission) AdaptPermission(org.osgi.framework.AdaptPermission) AdaptPermission(org.osgi.framework.AdaptPermission) ConfigurationPermission(org.osgi.service.cm.ConfigurationPermission) Before(org.junit.Before)

Example 5 with AppPermission

use of org.onosproject.security.AppPermission in project onos by opennetworkinglab.

the class DefaultPolicyBuilderTest method testConvertToJavaPermissions.

@Test
public void testConvertToJavaPermissions() {
    List<Permission> result = Lists.newArrayList();
    for (org.onosproject.security.Permission perm : testPermissions) {
        Permission javaPerm = new AppPermission(perm.getName());
        if (javaPerm != null) {
            if (javaPerm instanceof AppPermission) {
                if (((AppPermission) javaPerm).getType() != null) {
                    AppPermission ap = (AppPermission) javaPerm;
                    result.add(ap);
                }
            } else if (javaPerm instanceof ServicePermission) {
                if (!javaPerm.getName().contains(SecurityAdminService.class.getName())) {
                    result.add(javaPerm);
                }
            } else {
                result.add(javaPerm);
            }
        }
    }
    assertTrue(!result.isEmpty());
    assertEquals("APP_READ", result.get(0).getName());
}
Also used : AppPermission(org.onosproject.security.AppPermission) SecurityAdminService(org.onosproject.security.SecurityAdminService) ServicePermission(org.osgi.framework.ServicePermission) ConfigurationPermission(org.osgi.service.cm.ConfigurationPermission) PackagePermission(org.osgi.framework.PackagePermission) AppPermission(org.onosproject.security.AppPermission) Permission(java.security.Permission) AdminPermission(org.osgi.framework.AdminPermission) ServicePermission(org.osgi.framework.ServicePermission) AdaptPermission(org.osgi.framework.AdaptPermission) Test(org.junit.Test)

Aggregations

AppPermission (org.onosproject.security.AppPermission)6 AdaptPermission (org.osgi.framework.AdaptPermission)6 AdminPermission (org.osgi.framework.AdminPermission)6 PackagePermission (org.osgi.framework.PackagePermission)6 ServicePermission (org.osgi.framework.ServicePermission)6 Permission (java.security.Permission)5 ConfigurationPermission (org.osgi.service.cm.ConfigurationPermission)5 FilePermission (java.io.FilePermission)3 SerializablePermission (java.io.SerializablePermission)3 ReflectPermission (java.lang.reflect.ReflectPermission)3 NetPermission (java.net.NetPermission)3 SocketPermission (java.net.SocketPermission)3 SQLPermission (java.sql.SQLPermission)3 PropertyPermission (java.util.PropertyPermission)3 LoggingPermission (java.util.logging.LoggingPermission)3 SSLPermission (javax.net.ssl.SSLPermission)3 AuthPermission (javax.security.auth.AuthPermission)3 PrivateCredentialPermission (javax.security.auth.PrivateCredentialPermission)3 DelegationPermission (javax.security.auth.kerberos.DelegationPermission)3 AudioPermission (javax.sound.sampled.AudioPermission)3