org.teiid.adminapi.impl.DataPolicyMetadata Maven / Gradle / Ivy
/*
* Copyright Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags and
* the COPYRIGHT.txt file distributed with this work.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teiid.adminapi.impl;
import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import org.teiid.adminapi.AdminPlugin;
import org.teiid.adminapi.DataPolicy;
import org.teiid.core.TeiidRuntimeException;
public class DataPolicyMetadata implements DataPolicy, Serializable {
private static final long serialVersionUID = -4119646357275977190L;
protected String name;
protected String description;
protected boolean anyAuthenticated;
protected Boolean allowCreateTemporaryTables;
protected Map permissions = new TreeMap(String.CASE_INSENSITIVE_ORDER);
protected Map languagePermissions = new HashMap(2);
protected List mappedRoleNames = new CopyOnWriteArrayList();
private Set hasRowPermissions = new TreeSet(String.CASE_INSENSITIVE_ORDER);
private boolean grantAll;
private Set schemas;
@Override
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
@Override
public String getDescription() {
return description;
}
public void setDescription(String value) {
this.description = value;
}
@Override
public List getPermissions() {
List result = new ArrayList(this.permissions.values());
result.addAll(this.languagePermissions.values());
return result;
}
public Map getPermissionMap() {
return permissions;
}
public boolean hasRowSecurity(String resourceName) {
return hasRowPermissions.contains(resourceName);
}
public void setPermissions(List permissions) {
this.permissions.clear();
for (DataPermission permission:permissions) {
addPermissionMetadata((PermissionMetaData)permission);
}
}
public void addPermission(PermissionMetaData... perms) {
for (PermissionMetaData permission:perms) {
addPermissionMetadata(permission);
}
}
private void addPermissionMetadata(PermissionMetaData permission) {
PermissionMetaData previous = null;
if (permission.getAllowLanguage() != null) {
previous = this.languagePermissions.put(permission.getResourceName(), permission);
} else {
previous = permissions.put(permission.getResourceName().toLowerCase(), permission);
}
if (permission.getCondition() != null) {
this.hasRowPermissions.add(permission.getResourceName());
}
if (permission.getMask() != null) {
String resourceName = permission.getResourceName();
int lastSegment = permission.getResourceName().lastIndexOf('.');
if (lastSegment > 0) {
resourceName = resourceName.substring(0, lastSegment);
}
this.hasRowPermissions.add(resourceName);
}
if (previous != null) {
permission.bits |= previous.bits;
permission.bitsSet |= previous.bitsSet;
if (previous.getCondition() != null) {
if (permission.getCondition() == null) {
permission.setCondition(previous.getCondition());
permission.setConstraint(previous.getConstraint());
} else {
throw new TeiidRuntimeException(AdminPlugin.Event.TEIID70053, AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70053, this.getName(), permission.getResourceName()));
}
}
if (previous.getMask() != null) {
if (permission.getMask() != null) {
throw new TeiidRuntimeException(AdminPlugin.Event.TEIID70053, AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70053, this.getName(), permission.getResourceName()));
}
permission.setMask(previous.getMask());
permission.setOrder(previous.getOrder());
}
}
}
@Override
public List getMappedRoleNames() {
return mappedRoleNames;
}
public void setMappedRoleNames(List names) {
this.mappedRoleNames.clear();
this.mappedRoleNames.addAll(names);
}
public void addMappedRoleName(String mappedName) {
this.mappedRoleNames.add(mappedName);
}
public void removeMappedRoleName(String mappedName) {
this.mappedRoleNames.remove(mappedName);
}
public Boolean allows(String resourceName, DataPolicy.PermissionType type) {
PermissionMetaData p = null;
if (type == PermissionType.LANGUAGE) {
p = this.languagePermissions.get(resourceName);
} else {
p = this.permissions.get(resourceName);
}
if (p != null) {
return p.allows(type);
}
return null;
}
private static class RowSecurityState {
private String condition;
private volatile SoftReference
© 2015 - 2024 Weber Informatics LLC | Privacy Policy