Example usage for java.security Permission getName

List of usage examples for java.security Permission getName

Introduction

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

Prototype


public final String getName() 

Source Link

Document

Returns the name of this Permission.

Usage

From source file:com.linkedin.pinot.common.utils.KafkaStarterUtils.java

private static void invokeTopicCommand(String[] args) {
    // jfim: Use Java security to trap System.exit in Kafka 0.9's TopicCommand
    System.setSecurityManager(new SecurityManager() {
        @Override/*from  w w  w  .  j a  v  a2s .com*/
        public void checkPermission(Permission perm) {
            if (perm.getName().startsWith("exitVM")) {
                throw new SecurityException("System.exit is disabled");
            }
        }

        @Override
        public void checkPermission(Permission perm, Object context) {
            checkPermission(perm);
        }
    });

    try {
        TopicCommand.main(args);
    } catch (SecurityException ex) {
        // Do nothing, this is caused by our security manager that disables System.exit
    }

    System.setSecurityManager(null);
}

From source file:org.wildfly.test.security.common.elytron.PermissionRef.java

public static PermissionRef fromPermission(Permission perm, String module) {
    return builder().className(perm.getClass().getName()).action(perm.getActions()).targetName(perm.getName())
            .module(module).build();//from   ww  w .j a v  a  2s.co  m
}

From source file:it.unifi.rcl.chess.traceanalysis.Trace.java

private static void forbidSystemExitCall() {
    final SecurityManager securityManager = new SecurityManager() {
        public void checkPermission(Permission permission) {
            if (permission.getName().contains("exitVM")) {
                throw new ExitTrappedException();
            }//from  w w  w  . j av  a2s  . c  om
        }
    };
    System.setSecurityManager(securityManager);
}

From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java

static void disableSystemExitCall() {
    final SecurityManager securityManager = new SecurityManager() {

        @Override//from w w  w .ja v a2  s .co m
        public void checkPermission(Permission permission) {
            String name = permission.getName();
            if (name.startsWith("exitVM")) {
                throw new ExitTrapped(name);
            }
        }
    };

    oldSM = System.getSecurityManager();
    System.setSecurityManager(securityManager);
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

public static void remove(Acl policy, PolicyData pd) {
    Enumeration<AclEntry> entryEnum = policy.entries();

    while (entryEnum.hasMoreElements()) {
        AclEntry entry = entryEnum.nextElement();
        Principal principal = entry.getPrincipal();

        String principalClass = principal.getClass().getName();
        String principalName = principal.getName();

        if (principalClass == null || principalName == null)
            continue;
        if (principalClass.equals(pd.getPrincipalClass()) && principalName.equals(pd.getPrincipalName())) {
            Enumeration<Permission> permissEnum = entry.permissions();
            while (permissEnum.hasMoreElements()) {
                Permission permission = permissEnum.nextElement();

                String permissionClass = permission.getClass().getName();
                String permissionName = permission.getName();
                String permissionActions = permission.getActions();

                if (permissionClass == null || permissionName == null || permissionActions == null)
                    continue;
                if (permissionClass.equals(pd.getPermissionClass())
                        && permissionName.equals(pd.getPermissionName())
                        && permissionActions.equals(pd.getPermissionActions())) {
                    // 
                    AclEntry policyEntry = policy.getEntry(principal);
                    policyEntry.removePermission(permission);
                }//from ww w.  ja  va2  s  .c o m
            }
        }
    }
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

private static String permiss2PolicyString(Permission permission) {
    StringBuffer sb = new StringBuffer();
    sb.append("permission ").append(permission.getClass().getName()).append(" \"");
    if (permission instanceof UserPermission) {
        sb.append(((UserPermission) permission).getWiki());
    } else if (permission instanceof VWBPermission) {
        sb.append("*");
    } else if (permission instanceof PagePermission) {
        sb.append(((PagePermission) permission).getPage());
    } else if (permission instanceof AllPermission) {
        sb.append("*");
    } else {/*from   w ww.j a v a  2 s  . c  o  m*/
        sb.append(permission.getName());
    }
    sb.append("\"");
    String actions = permission.getActions();
    if (actions != null) {
        sb.append(" \"").append(actions).append("\"");
    }
    sb.append(";\n\r");
    return sb.toString();
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

public static PolicyData add(String voGroup, Acl policy, String principalAlias, String permissionAlias,
        String operation, String resource) {

    Principal principal = null;//from  w ww  .j av a 2s .  co  m
    if (principalAlias.equals("All")) {
        principal = new Role("All");
        principalAlias = "";
    } else if (principalAlias.equals("VO")) {
        principal = new GroupPrincipal(voGroup);
        principalAlias = "";
    } else {
        return null;
    }

    AclEntry policyEntry = policy.getEntry(principal);
    Permission permission = null;
    if (permissionAlias.equals("Page")) {
        permission = new PagePermission(resource, operation);
        permissionAlias = "?";
    } else if (permissionAlias.equals("VWB")) {
        permission = new VWBPermission(resource, operation);
        permissionAlias = "";
    } else {
        return null;
    }

    policyEntry.addPermission(permission);

    PolicyData pd = new PolicyData();
    pd.setPrincipalClass(principal.getClass().getName());
    pd.setPrincipalName(principal.getName());
    pd.setPrincipal(principalAlias);

    pd.setPermissionClass(permission.getClass().getName());
    pd.setPermissionName(permission.getName());
    pd.setPermissionActions(permission.getActions());
    pd.setPermission(permissionAlias);

    pd.setOperation(operation);
    pd.setResource(resource);

    return pd;
}

From source file:com.sun.socialsite.security.FeaturePermission.java

/**
 * Checks if the specified permission is "implied" by this object.  More specifically,
 * this method returns true if//from   w  w  w  .  ja  v a  2 s  .  c  o m
 * <ul>
 *  <li>
 *   <code>p</code>'s class is the same as this object's class, and
 *  </li>
 *  <li>
 *   <code>p</code>'s name equals or (in the case of wildcards) is implied by this object's name.
 *   Currently, the only supported wildcard is a single asterisk ("*"), which implies any value.
 *  </li>
 * </ul>
 *
 * @param p the permission to check against
 * @return true if the specified permission is equal to or implied by this permission, false otherwise.
 */
@Override
public boolean implies(Permission p) {
    if (p instanceof FeaturePermission) {
        return (("*".equals(getName())) || (p.getName().equals(getName())));
    } else {
        return false;
    }
}

From source file:ma.glasnost.orika.test.converter.CloneableConverterNoSetAccessibleTestCase.java

@Test
public void cloneableConverterWithoutSetAccessible() throws DatatypeConfigurationException {

    final SecurityManager initialSm = System.getSecurityManager();
    try {/*from   w  w w.  ja  va  2 s .  c om*/
        System.setSecurityManager(new SecurityManager() {
            public void checkPermission(java.security.Permission perm) {
                if ("suppressAccessChecks".equals(perm.getName())) {
                    for (StackTraceElement ste : new Throwable().getStackTrace()) {
                        if (ste.getClassName().equals(CloneableConverter.class.getCanonicalName())) {
                            throw new SecurityException("not permitted");
                        }
                    }
                }
            }
        });

        CloneableConverter cc = new CloneableConverter(SampleCloneable.class);

        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(cc);

        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.YEAR, 10);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar((GregorianCalendar) cal);
        cal.add(Calendar.MONTH, 3);

        ClonableHolder source = new ClonableHolder();
        source.value = new SampleCloneable();
        source.value.id = 5L;
        source.date = new Date(System.currentTimeMillis() + 100000);
        source.timestamp = new Timestamp(System.currentTimeMillis() + 50000);
        source.calendar = cal;
        source.xmlCalendar = xmlCal;

        ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
        Assert.assertEquals(source.value, dest.value);
        Assert.assertNotSame(source.value, dest.value);
        Assert.assertEquals(source.date, dest.date);
        Assert.assertNotSame(source.date, dest.date);
        Assert.assertEquals(source.timestamp, dest.timestamp);
        Assert.assertNotSame(source.timestamp, dest.timestamp);
        Assert.assertEquals(source.calendar, dest.calendar);
        Assert.assertNotSame(source.calendar, dest.calendar);
        Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
        Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
    } finally {
        System.setSecurityManager(initialSm);
    }
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

public static List<PolicyData> acl2PolicyData(Acl acl) {
    List<PolicyData> pdl = new ArrayList<PolicyData>();

    Enumeration<AclEntry> entryEnum = acl.entries();
    while (entryEnum.hasMoreElements()) {
        AclEntry entry = entryEnum.nextElement();
        Principal principal = entry.getPrincipal();
        String principalClass = principal.getClass().getName();
        String principalName = principal.getName();
        String objectname = null;
        if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role")
                && principalName.equalsIgnoreCase("All")) {
            objectname = "";
        }/*from   ww  w .j  av a  2s .  c  o m*/
        if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) {
            objectname = "";
        }
        if (objectname == null) {
            continue;
        }
        Enumeration<Permission> permissEnum = entry.permissions();
        while (permissEnum.hasMoreElements()) {
            Permission permission = permissEnum.nextElement();

            String permissionClass = permission.getClass().getName();
            String permissionType = null;
            if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.PagePermission")) {
                permissionType = "?";
            }
            if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.VWBPermission")) {
                permissionType = "";
            }
            if (permissionType == null) {
                continue;
            }

            String permissionActions = permission.getActions();
            String operations = permissionActions;

            String permissionName = permission.getName();

            String resource = null;
            if (permission instanceof UserPermission) {
                resource = ((UserPermission) permission).getWiki();
            } else if (permission instanceof VWBPermission) {
                resource = "*";
            } else if (permission instanceof PagePermission) {
                resource = ((PagePermission) permission).getPage();
            } else if (permission instanceof AllPermission) {
                resource = "*";
            } else {
                resource = permission.getName();
            }

            PolicyData pd = new PolicyData();

            pd.setId(pdl.size());
            pd.setPrincipalClass(principalClass);
            pd.setPrincipalName(principalName);

            pd.setPermissionClass(permissionClass);
            pd.setPermissionActions(permissionActions);
            pd.setPermissionName(permissionName);

            pd.setPrincipal(objectname);
            pd.setPermission(permissionType);
            pd.setOperation(operations);
            pd.setResource(resource);

            pdl.add(pd);
        }
    }

    return pdl;
}