edu.internet2.middleware.grouper.abac.GrouperAbacEntity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grouper Show documentation
Show all versions of grouper Show documentation
Internet2 Groups Management Toolkit
package edu.internet2.middleware.grouper.abac;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.Member;
import edu.internet2.middleware.grouper.MemberFinder;
import edu.internet2.middleware.grouper.dataField.GrouperDataEngine;
import edu.internet2.middleware.grouper.dataField.GrouperDataFieldConfig;
import edu.internet2.middleware.grouper.dataField.GrouperDataRowConfig;
import edu.internet2.middleware.grouper.dataField.GrouperDataRowWrapper;
import edu.internet2.middleware.grouper.util.GrouperUtil;
import edu.internet2.middleware.subject.Subject;
public class GrouperAbacEntity {
private Map singleValuedGroupExtensionInFolder = null;
public Map getSingleValuedGroupExtensionInFolder() {
return singleValuedGroupExtensionInFolder;
}
private Map>> dataRowAssignInternalIdToDataFieldAliasToValues = null;
// ${ entity.singleValuedEntityAttribute('personLdap', 'activeFlag') == 'T' }
public Map>> getDataRowAssignInternalIdToDataFieldAliasToValues() {
return dataRowAssignInternalIdToDataFieldAliasToValues;
}
public void setDataRowAssignInternalIdToDataFieldAliasToValues(
Map>> dataRowAssignInternalIdToDataFieldAliasToValues) {
this.dataRowAssignInternalIdToDataFieldAliasToValues = dataRowAssignInternalIdToDataFieldAliasToValues;
}
public void setSingleValuedGroupExtensionInFolder(Map singleValuedGroupExtensionInFolder) {
this.singleValuedGroupExtensionInFolder = singleValuedGroupExtensionInFolder;
}
// basis:affiliation:staff
// basis:affiliation:student
// ${ entity.multiValuedGroupExtensionInFolder('basis:affiliation').containsRegex('^(stu)|(fac).*$') }
private Map> multiValuedGroupExtensionInFolder = null;
public Map> multiValuedGroupExtensionInFolder(String folderName) {
return multiValuedGroupExtensionInFolder;
}
public void setMultiValuedGroupExtensionInFolder(Map> multiValuedGroupExtensionInFolder) {
this.multiValuedGroupExtensionInFolder = multiValuedGroupExtensionInFolder;
}
private Set memberOfGroupNames;
public void setMemberOfGroupNames(Set memberOfGroupNames) {
this.memberOfGroupNames = memberOfGroupNames;
}
public boolean memberOf(String groupName) {
return this.memberOfGroupNames.contains(groupName);
}
private Map> dataAliasToValues = new HashMap<>();
public Map> getDataAliasToValues() {
return dataAliasToValues;
}
public void setDataAliasToValues(
Map> dataFieldInternalIdToValues) {
this.dataAliasToValues = GrouperUtil.nonNull(dataFieldInternalIdToValues);
}
private String memberId;
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
/**
*
* @param aliasName
* @param valueOrScript
* @return
*/
public boolean hasAttribute(String aliasName, String valueOrScript) {
String aliasLowerCase = aliasName.toLowerCase();
GrouperDataFieldConfig grouperDataFieldConfig = this.grouperDataEngine.getFieldConfigByAlias().get(aliasLowerCase);
GrouperDataRowConfig grouperDataRowConfig = this.grouperDataEngine.getRowConfigByAlias().get(aliasLowerCase);
if (grouperDataFieldConfig != null) {
Object value = grouperDataFieldConfig.getFieldDataType().convertValue(valueOrScript);
return this.dataAliasToValues.get(aliasLowerCase).contains(value);
} else if (grouperDataRowConfig != null) {
if (this.dataRowAssignInternalIdToDataFieldAliasToValues != null) {
for (Long rowAssignId : this.dataRowAssignInternalIdToDataFieldAliasToValues.keySet()) {
GrouperDataRowWrapper grouperDataRowWrapper = this.grouperDataEngine.getGrouperDataProviderIndex().getRowWrapperByLowerAlias().get(aliasLowerCase);
if (StringUtils.equals(grouperDataRowConfig.getConfigId(), grouperDataRowWrapper.getGrouperDataRowConfig().getConfigId())) {
Map variableMap = new HashMap();
Map> dataFieldAliasToValues = this.dataRowAssignInternalIdToDataFieldAliasToValues.get(rowAssignId);
GrouperAbacRow grouperAbacRow = new GrouperAbacRow();
grouperAbacRow.setMemberId(this.memberId);
grouperAbacRow.setGrouperDataEngine(this.grouperDataEngine);
grouperAbacRow.setDataAliasToValues(dataFieldAliasToValues);
variableMap.put(aliasName, grouperAbacRow);
if (!valueOrScript.trim().startsWith("${")) {
valueOrScript = "${" + valueOrScript + "}";
}
Object result = GrouperUtil.substituteExpressionLanguageScript(valueOrScript, variableMap, true, false, true);
boolean isTrue = GrouperUtil.booleanValue(result);
return isTrue;
}
}
}
}
return false;
}
/** logger */
private static final Log LOG = GrouperUtil.getLog(GrouperAbacEntity.class);
private GrouperDataEngine grouperDataEngine;
public void setGrouperDataEngine(GrouperDataEngine grouperDataEngine) {
this.grouperDataEngine = grouperDataEngine;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy