ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/engine/RightOwner.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/engine/RightOwner.java
Status
scanned
Type
file
Name
RightOwner.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
7600 (7.4 KB)
MD5
d46d55e9fe6d320dfa15164c21e12046
SHA1
3c34915febc54a0721df38016a25ebb3f8bf2640
SHA256
e211757cdbf1f45724bcb7ebbc0aa04144a449fdc37b279eae3678e8029e2536
SHA512

      
    
SHA1_git
307a2fac050585e3841977aa1971e1a7e2076b92
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
RightOwner.java | 7.4 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.engine; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import org.h2.api.ErrorCode; import org.h2.message.DbException; import org.h2.schema.Schema; import org.h2.table.Table; import org.h2.util.StringUtils; /** * A right owner (sometimes called principal). */ public abstract class RightOwner extends DbObject { /** * The map of granted roles. */ private HashMap<Role, Right> grantedRoles; /** * The map of granted rights. */ private HashMap<DbObject, Right> grantedRights; protected RightOwner(Database database, int id, String name, int traceModuleId) { super(database, id, StringUtils.toUpperEnglish(name), traceModuleId); } @Override public void rename(String newName) { super.rename(StringUtils.toUpperEnglish(newName)); } /** * Check if a role has been granted for this right owner. * * @param grantedRole the role * @return true if the role has been granted */ public boolean isRoleGranted(Role grantedRole) { if (grantedRole == this) { return true; } if (grantedRoles != null) { for (Role role : grantedRoles.keySet()) { if (role == grantedRole) { return true; } if (role.isRoleGranted(grantedRole)) { return true; } } } return false; } /** * Checks if a right is already granted to this object or to objects that * were granted to this object. The rights of schemas will be valid for * every each table in the related schema. The ALTER ANY SCHEMA right gives * all rights to all tables. * * @param table * the table to check * @param rightMask * the right mask to check * @return true if the right was already granted */ final boolean isTableRightGrantedRecursive(Table table, int rightMask) { Schema schema = table.getSchema(); if (schema.getOwner() == this) { return true; } if (grantedRights != null) { Right right = grantedRights.get(null); if (right != null && (right.getRightMask() & Right.ALTER_ANY_SCHEMA) == Right.ALTER_ANY_SCHEMA) { return true; } right = grantedRights.get(schema); if (right != null && (right.getRightMask() & rightMask) == rightMask) { return true; } right = grantedRights.get(table); if (right != null && (right.getRightMask() & rightMask) == rightMask) { return true; } } if (grantedRoles != null) { for (Role role : grantedRoles.keySet()) { if (role.isTableRightGrantedRecursive(table, rightMask)) { return true; } } } return false; } /** * Checks if a schema owner right is already granted to this object or to * objects that were granted to this object. The ALTER ANY SCHEMA right * gives rights to all schemas. * * @param schema * the schema to check, or {@code null} to check for ALTER ANY * SCHEMA right only * @return true if the right was already granted */ final boolean isSchemaRightGrantedRecursive(Schema schema) { if (schema != null && schema.getOwner() == this) { return true; } if (grantedRights != null) { Right right = grantedRights.get(null); if (right != null && (right.getRightMask() & Right.ALTER_ANY_SCHEMA) == Right.ALTER_ANY_SCHEMA) { return true; } } if (grantedRoles != null) { for (Role role : grantedRoles.keySet()) { if (role.isSchemaRightGrantedRecursive(schema)) { return true; } } } return false; } /** * Grant a right for the given table. Only one right object per table is * supported. * * @param object the object (table or schema) * @param right the right */ public void grantRight(DbObject object, Right right) { if (grantedRights == null) { grantedRights = new HashMap<>(); } grantedRights.put(object, right); } /** * Revoke the right for the given object (table or schema). * * @param object the object */ void revokeRight(DbObject object) { if (grantedRights == null) { return; } grantedRights.remove(object); if (grantedRights.size() == 0) { grantedRights = null; } } /** * Grant a role to this object. * * @param role the role * @param right the right to grant */ public void grantRole(Role role, Right right) { if (grantedRoles == null) { grantedRoles = new HashMap<>(); } grantedRoles.put(role, right); } /** * Remove the right for the given role. * * @param role the role to revoke */ void revokeRole(Role role) { if (grantedRoles == null) { return; } Right right = grantedRoles.get(role); if (right == null) { return; } grantedRoles.remove(role); if (grantedRoles.size() == 0) { grantedRoles = null; } } /** * Remove all the temporary rights granted on roles */ public void revokeTemporaryRightsOnRoles() { if (grantedRoles == null) { return; } List<Role> rolesToRemove= new ArrayList<>(); for (Entry<Role,Right> currentEntry : grantedRoles.entrySet()) { if ( currentEntry.getValue().isTemporary() || !currentEntry.getValue().isValid()) { rolesToRemove.add(currentEntry.getKey()); } } for (Role currentRoleToRemove : rolesToRemove) { revokeRole(currentRoleToRemove); } } /** * Get the 'grant schema' right of this object. * * @param object the granted object (table or schema) * @return the right or null if the right has not been granted */ public Right getRightForObject(DbObject object) { if (grantedRights == null) { return null; } return grantedRights.get(object); } /** * Get the 'grant role' right of this object. * * @param role the granted role * @return the right or null if the right has not been granted */ public Right getRightForRole(Role role) { if (grantedRoles == null) { return null; } return grantedRoles.get(role); } /** * Check that this right owner does not own any schema. An exception is * thrown if it owns one or more schemas. * * @throws DbException * if this right owner owns a schema */ public final void checkOwnsNoSchemas() { for (Schema s : database.getAllSchemas()) { if (this == s.getOwner()) { throw DbException.get(ErrorCode.CANNOT_DROP_2, getName(), s.getName()); } } } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
1.46
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220