SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

190 lines
4.3 KiB

package de.memtext.rights;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import de.memtext.util.EqualsUtil;
import de.superx.common.OrgUnit;
import de.superx.common.OrgUnitMapping;
import de.superx.servlet.SxPools;
/**
* A class for managing rights.
*/
public class Rights implements Serializable {
private static final long serialVersionUID = 2;
private boolean isAdmin = false;
private boolean hasAllRights;
private Set<RightsKeyEntry> allowedRightKeyEntries = new TreeSet<RightsKeyEntry>();
public Rights() {
}
public Rights(boolean isAdmin, boolean hasAllRights) {
setAdmin(isAdmin);
setHasAllRights(hasAllRights);
}
public boolean isAdmin() {
return isAdmin;
}
public void setAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
public void addAllowed(RightsKeyEntry rke) {
allowedRightKeyEntries.add(rke);
}
public void clear() {
this.isAdmin = false;
hasAllRights = false;
allowedRightKeyEntries.clear();
}
public boolean isEmpty() {
return allowedRightKeyEntries.isEmpty();
}
public boolean hasNoRights() {
return !isAdmin && !hasAllRights && isEmpty();
}
public boolean hasAllRights() {
return hasAllRights;
}
public void setHasAllRights(boolean b) {
hasAllRights = b;
}
public boolean isAllowed(Object id) {
boolean result = false;
if (isAdmin || hasAllRights()) {
result = true;
} else {
for (Iterator it = allowedRightKeyEntries.iterator(); it.hasNext();) {
RightsKeyEntry entry = (RightsKeyEntry) it.next();
if (EqualsUtil.areEqual(entry.getKey(), id)) {
result = true;
break;
}
}
}
return result;
}
public boolean isSubordinatesAllowed(Object key) {
boolean result = false;
if (isAdmin || hasAllRights()) {
result = true;
} else {
for (Iterator it = allowedRightKeyEntries.iterator(); it.hasNext();) {
RightsKeyEntry entry = (RightsKeyEntry) it.next();
if (EqualsUtil.areEqual(entry.getKey(), key)) {
result = entry.isSubordinatesAllowed();
break;
}
}
}
return result;
}
@Override
public Object clone() throws CloneNotSupportedException {
Rights cl = new Rights(isAdmin, hasAllRights);
for (Iterator it = allowedRightKeyEntries.iterator(); it.hasNext();) {
RightsKeyEntry key = (RightsKeyEntry) it.next();
cl.allowedRightKeyEntries.add((RightsKeyEntry) key.clone());
}
return cl;
}
@Override
public String toString() {
StringBuffer result = new StringBuffer("Rechte: ");
for (RightsKeyEntry entry : allowedRightKeyEntries) {
result.append(entry.toString() + ",");
}
de.memtext.util.StringUtils.removeLastChar(result);
return result.toString();
}
public void add(Set<String> allowedKeys) {
for (String aKey : allowedKeys) {
allowedRightKeyEntries.add(new RightsKeyEntry(aKey, true));
}
}
public void add(String allowedKey) {
allowedRightKeyEntries.add(new RightsKeyEntry(allowedKey, true));
}
public void addOrgUnitRights(StringBuffer msg, Set<OrgUnit> orgUnits) {
for (OrgUnit ou : orgUnits) {
this.add(ou.getApnr());
msg.append(ou.getApnr() + ",");
}
}
public void addLiveMappingRights(StringBuffer msg, String mandantenID) {
msg.append(
" via LifeMapping :");
Set<String> lifeMappingApnrs = new TreeSet<String>();
Set<String> keysBefore=new HashSet<String>();
for (RightsKeyEntry re:allowedRightKeyEntries)
{
keysBefore.add((String)re.getKey());
OrgUnitMapping oum = SxPools.get(mandantenID).getOrgUnitMappings().get(re.getKey().toString());
if (oum != null) {
lifeMappingApnrs.add(oum.getUniquename());
for (String mappedId : oum.getMappedIds()) {
lifeMappingApnrs.add(mappedId);
}
}
}
lifeMappingApnrs.removeAll(keysBefore);
for (String mappedId : lifeMappingApnrs) {
this.add(mappedId);
msg.append(mappedId + ",");
}
}
/**
* Alle Rechte inkl. LiveMapping und implizierten Rechten wenn Methoden vorher aufgerufen
* @return
*/
public Set<String> getAllRightKeys()
{
Set<String> keys=new TreeSet<String>();
for (RightsKeyEntry re : allowedRightKeyEntries) {
keys.add(re.getKey().toString());
}
return keys;
}
public Iterator<RightsKeyEntry> iterator()
{
return allowedRightKeyEntries.iterator();
}
}
// Created on 07.09.2004 at 11:10:06