java.security.Permissions类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中java.security.Permissions类的一些代码示例,展示了Permissions类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Permissions类的具体详情如下:
包路径:java.security.Permissions
类名称:Permissions

Permissions介绍

[英]Legacy security code; do not use.
[中]遗留安全代码;不要使用。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

  1. protected PermissionCollection getPermissions(CodeSource codeSource) {
  2. PermissionCollection perms;
  3. try {
  4. try {
  5. perms = super.getPermissions(codeSource);
  6. } catch (SecurityException e) {
  7. // We lied about our CodeSource and that makes URLClassLoader unhappy.
  8. perms = new Permissions();
  9. }
  10. ProtectionDomain myDomain = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
  11. public ProtectionDomain run() {
  12. return getClass().getProtectionDomain();
  13. }
  14. });
  15. PermissionCollection myPerms = myDomain.getPermissions();
  16. if (myPerms != null) {
  17. for (Enumeration<Permission> elements = myPerms.elements(); elements.hasMoreElements();) {
  18. perms.add(elements.nextElement());
  19. }
  20. }
  21. } catch (Throwable e) {
  22. // We lied about our CodeSource and that makes URLClassLoader unhappy.
  23. perms = new Permissions();
  24. }
  25. perms.setReadOnly();
  26. return perms;
  27. }

代码示例来源:origin: dlew/joda-time-android

  1. public PermissionCollection getPermissions(CodeSource codesource) {
  2. Permissions p = new Permissions();
  3. p.add(new AllPermission()); // enable everything
  4. return p;
  5. }
  6. public void refresh() {

代码示例来源:origin: org.apache.ant/ant

  1. /**
  2. * The central point in checking permissions.
  3. * Overridden from java.lang.SecurityManager
  4. *
  5. * @param perm The permission requested.
  6. */
  7. @Override
  8. public void checkPermission(final java.security.Permission perm) {
  9. if (active) {
  10. if (delegateToOldSM && !perm.getName().equals("exitVM")) {
  11. boolean permOK = false;
  12. if (granted.implies(perm)) {
  13. permOK = true;
  14. }
  15. checkRevoked(perm);
  16. /*
  17. if the permission was not explicitly granted or revoked
  18. the original security manager will do its work
  19. */
  20. if (!permOK && origSm != null) {
  21. origSm.checkPermission(perm);
  22. }
  23. } else {
  24. if (!granted.implies(perm)) {
  25. throw new SecurityException("Permission " + perm + " was not granted.");
  26. }
  27. checkRevoked(perm);
  28. }
  29. }
  30. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Get a read-only collection of the given permissions.
  3. *
  4. * @param permissions the permissions to assign
  5. * @return the read-only collection
  6. */
  7. public static PermissionCollection readOnlyCollectionOf(Permission... permissions) {
  8. final int length = permissions.length;
  9. if (length == 0) {
  10. return EMPTY_PERMISSION_COLLECTION;
  11. } else {
  12. Permissions collection = new Permissions();
  13. addAll(collection, Arrays.asList(permissions));
  14. collection.setReadOnly();
  15. return collection;
  16. }
  17. }
  18. }

代码示例来源:origin: wildfly/wildfly

  1. @Override
  2. public void addToRole(String roleName, Permission permission) throws PolicyContextException {
  3. checkNotNullParam("roleName", roleName);
  4. checkNotNullParam("permission", permission);
  5. synchronized (this) { // prevents state change while adding
  6. checkIfInOpenState();
  7. this.rolePermissions.computeIfAbsent(roleName, s -> new Permissions()).add(permission);
  8. }
  9. }

代码示例来源:origin: org.jboss.modules/jboss-modules

  1. private static PermissionCollection copyPermissions(PermissionCollection permissionCollection) {
  2. final Permissions permissions = new Permissions();
  3. final Enumeration<Permission> elements = permissionCollection.elements();
  4. while (elements.hasMoreElements()) {
  5. permissions.add(elements.nextElement());
  6. }
  7. permissions.setReadOnly();
  8. return permissions;
  9. }

代码示例来源:origin: ben-manes/caffeine

  1. @Override
  2. public String toString() {
  3. List<Permission> ps = new ArrayList<Permission>();
  4. for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) {
  5. ps.add(e.nextElement());
  6. }
  7. return "AdjustablePolicy with permissions " + ps;
  8. }
  9. }

代码示例来源:origin: weld/core

  1. private ProtectionDomain create(ProtectionDomain domain) {
  2. if (domain.implies(ACCESS_DECLARED_MEMBERS_PERMISSION)) {
  3. return domain;
  4. }
  5. PermissionCollection permissions = domain.getPermissions();
  6. PermissionCollection proxyPermissions = new Permissions();
  7. if (permissions != null) {
  8. Enumeration<Permission> permissionElements = permissions.elements();
  9. while (permissionElements.hasMoreElements()) {
  10. proxyPermissions.add(permissionElements.nextElement());
  11. }
  12. }
  13. proxyPermissions.add(ACCESS_DECLARED_MEMBERS_PERMISSION);
  14. return new ProtectionDomain(domain.getCodeSource(), proxyPermissions);
  15. }

代码示例来源:origin: org.glassfish.security/security

  1. private static boolean grantedIsExcluded(Permission granted, Permissions excluded) {
  2. boolean isExcluded = false;
  3. if (excluded != null) {
  4. if (!excluded.implies(granted)) {
  5. Enumeration e = excluded.elements();
  6. while (!isExcluded && e.hasMoreElements()) {
  7. Permission excludedPerm = (Permission) e.nextElement();
  8. if (granted.implies(excludedPerm)) {
  9. isExcluded = true;
  10. }
  11. }
  12. } else {
  13. isExcluded = true;
  14. }
  15. }
  16. if (logger.isLoggable(Level.FINEST)){
  17. if (isExcluded) {
  18. logger.finest("JACC Policy Provider: permission is excluded: "+granted);
  19. }
  20. }
  21. return isExcluded;
  22. }

代码示例来源:origin: org.ow2.orchestra/orchestra-utils

  1. /**
  2. * @param permissions
  3. * @return
  4. */
  5. public static int getPermissionsSize(final Permissions permissions) {
  6. int size = 0;
  7. final Enumeration<Permission> p = permissions.elements();
  8. while (p.hasMoreElements()) {
  9. size++;
  10. }
  11. return size;
  12. }

代码示例来源:origin: org.eclipse.jetty/jetty-policy

  1. private PermissionCollection copyOf(final PermissionCollection in)
  2. {
  3. PermissionCollection out = new Permissions();
  4. synchronized (in)
  5. {
  6. for (Enumeration<Permission> el = in.elements() ; el.hasMoreElements() ;)
  7. {
  8. out.add((Permission)el.nextElement());
  9. }
  10. }
  11. return out;
  12. }

代码示例来源:origin: org.apache.geronimo.ext.openejb/openejb-core

  1. /**
  2. * Removes permissions from <code>toBeChecked</code> that are implied by
  3. * <code>permission</code>.
  4. *
  5. * @param toBeChecked the permissions that are to be checked and possibly culled
  6. * @param permission the permission that is to be used for culling
  7. * @return the culled set of permissions that are not implied by <code>permission</code>
  8. */
  9. private Permissions cullPermissions(Permissions toBeChecked, Permission permission) {
  10. Permissions result = new Permissions();
  11. for (Enumeration e = toBeChecked.elements(); e.hasMoreElements();) {
  12. Permission test = (Permission) e.nextElement();
  13. if (!permission.implies(test)) {
  14. result.add(test);
  15. }
  16. }
  17. return result;
  18. }
  19. }

代码示例来源:origin: wildfly/wildfly-core

  1. private static Permissions createPermissions(List<Permission> permissionsList, List<InjectedValue<Permissions>> permissionSetInjectors) throws StartException {
  2. Permissions allPermissions = createPermissions(permissionsList);
  3. for (InjectedValue<Permissions> permissionSetInjector : permissionSetInjectors) {
  4. Permissions permissionSet = permissionSetInjector.getValue();
  5. Enumeration<java.security.Permission> permissions = permissionSet.elements();
  6. while (permissions.hasMoreElements()) {
  7. allPermissions.add(permissions.nextElement());
  8. }
  9. }
  10. return allPermissions;
  11. }

代码示例来源:origin: org.apache.portals.jetspeed-2/jetspeed-security

  1. /**
  2. * @see java.security.Policy#getPermissions(java.security.ProtectionDomain)
  3. */
  4. public PermissionCollection getPermissions(ProtectionDomain domain)
  5. {
  6. PermissionCollection otherPerms = new Permissions();
  7. if (null != domain)
  8. {
  9. otherPerms = getPermissions(domain.getCodeSource());
  10. }
  11. return otherPerms;
  12. }

代码示例来源:origin: org.netbeans.api/org-openide-execution

  1. protected PermissionCollection createPermissions(CodeSource cs, InputOutput io) {
  2. PermissionCollection allPerms = new Permissions();
  3. allPerms.add(new AllPermission());
  4. allPerms.setReadOnly();
  5. return allPerms;
  6. }

代码示例来源:origin: spring-projects/spring-framework

  1. beanFactory.setSecurityContextProvider(null);
  2. Permissions perms = new Permissions();
  3. perms.add(new AuthPermission("getSubject"));
  4. ProtectionDomain pd = new ProtectionDomain(null, perms);

代码示例来源:origin: apache/stanbol

  1. @Override
  2. public PermissionCollection getPermissions(ProtectionDomain domain) {
  3. PermissionCollection result = new Permissions();
  4. result.add(new AllPermission());
  5. return result;
  6. }
  7. });

代码示例来源:origin: org.glassfish.main.security/security-ee

  1. static Permissions addToRoleMap(HashMap<String, Permissions> map,
  2. String roleName, Permission p) {
  3. Permissions collection = map.get(roleName);
  4. if (collection == null) {
  5. collection = new Permissions();
  6. map.put(roleName,collection);
  7. }
  8. collection.add(p);
  9. if (logger.isLoggable(Level.FINE)){
  10. logger.log(Level.FINE,"JACC: constraint capture: adding methods to role: "+ roleName+" methods: " + p.getActions());
  11. }
  12. return collection;
  13. }

代码示例来源:origin: stackoverflow.com

  1. private static final AccessControlContext allowedPermissionsAcc;
  2. static { // initialization of the allowed permissions
  3. PermissionCollection allowedPermissions = new Permissions();
  4. allowedPermissions.add(new RuntimePermission("accessDeclaredMembers"));
  5. // ... <many more permissions here> ...
  6. allowedPermissionsAcc = new AccessControlContext(new ProtectionDomain[] {
  7. new ProtectionDomain(null, allowedPermissions)});
  8. }

代码示例来源:origin: robovm/robovm

  1. /**
  2. * Returns the {@code PermissionCollection} for the specified {@code
  3. * CodeSource}.
  4. *
  5. * @param codesource
  6. * the code source.
  7. * @return the {@code PermissionCollection} for the specified {@code
  8. * CodeSource}.
  9. */
  10. protected PermissionCollection getPermissions(CodeSource codesource) {
  11. // Do nothing by default, ProtectionDomain will take care about
  12. // permissions in dynamic
  13. return new Permissions();
  14. }

相关文章