Skip to content
Snippets Groups Projects
Unverified Commit ecd4c289 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

STY: formatting

parent fa1d99a5
Branches
Tags
No related merge requests found
package caosdb.server.jobs.extension; package caosdb.server.jobs.extension;
import static caosdb.server.permissions.Role.ANONYMOUS_ROLE; import static caosdb.server.permissions.Role.ANONYMOUS_ROLE;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import caosdb.server.CaosDBServer; import caosdb.server.CaosDBServer;
import caosdb.server.accessControl.UserSources; import caosdb.server.accessControl.UserSources;
import caosdb.server.entity.Entity; import caosdb.server.entity.Entity;
...@@ -25,6 +23,9 @@ import caosdb.server.transaction.Update; ...@@ -25,6 +23,9 @@ import caosdb.server.transaction.Update;
import caosdb.server.utils.EntityStatus; import caosdb.server.utils.EntityStatus;
import caosdb.server.utils.ServerMessages; import caosdb.server.utils.ServerMessages;
import caosdb.server.utils.Utils; import caosdb.server.utils.Utils;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@JobAnnotation(transaction = caosdb.server.transaction.WriteTransaction.class, loadAlways = true) @JobAnnotation(transaction = caosdb.server.transaction.WriteTransaction.class, loadAlways = true)
public class AWIBoxLoan extends ContainerJob { public class AWIBoxLoan extends ContainerJob {
...@@ -34,8 +35,12 @@ public class AWIBoxLoan extends ContainerJob { ...@@ -34,8 +35,12 @@ public class AWIBoxLoan extends ContainerJob {
private static final Message BOX_HAS_LOAN = private static final Message BOX_HAS_LOAN =
new Message( new Message(
"This box cannot be be requested right now because it appears to have a Loan property attached to it. This usually means, that the box is already requested or borrowed by someone."); "This box cannot be be requested right now because it appears to have a Loan property attached to it. This usually means, that the box is already requested or borrowed by someone.");
private static final Message PROPERTY_NOT_ALLOWED_REQUEST_RETURN = new Message("It is not allowed to update this property during a return request as an anonymous user."); private static final Message PROPERTY_NOT_ALLOWED_REQUEST_RETURN =
private static final Message MULTIPLE_PROPERTIES = new Message("This property appears multiple times in this return request and is marked for an update. This is not allowed for an anonymous user."); new Message(
"It is not allowed to update this property during a return request as an anonymous user.");
private static final Message MULTIPLE_PROPERTIES =
new Message(
"This property appears multiple times in this return request and is marked for an update. This is not allowed for an anonymous user.");
@Override @Override
protected void run() { protected void run() {
...@@ -249,18 +254,21 @@ public class AWIBoxLoan extends ContainerJob { ...@@ -249,18 +254,21 @@ public class AWIBoxLoan extends ContainerJob {
/** Is Record an has single box parent. */ /** Is Record an has single box parent. */
boolean isBoxRecord(EntityInterface e) { boolean isBoxRecord(EntityInterface e) {
return e.getRole() == Role.Record && e.getParents().size() == 1 return e.getRole() == Role.Record
&& e.getParents().size() == 1
&& retrieveValidIDByName(e.getParents().get(0).getName()) == getBoxId(); && retrieveValidIDByName(e.getParents().get(0).getName()) == getBoxId();
} }
/** Is Record and has single loan parent */ /** Is Record and has single loan parent */
private boolean isLoanRecord(EntityInterface e) { private boolean isLoanRecord(EntityInterface e) {
return e.getRole() == Role.Record && e.getParents().size() == 1 return e.getRole() == Role.Record
&& e.getParents().size() == 1
&& retrieveValidIDByName(e.getParents().get(0).getName()) == getLoanId(); && retrieveValidIDByName(e.getParents().get(0).getName()) == getLoanId();
} }
/** /**
* Has only 5/6 new/updated properties: content, returnRequested, destination, Borrower, comment * Has only 5/6 new/updated properties: content, returnRequested, destination, Borrower, comment
* (optional), location * (optional), location
*
* @throws Message * @throws Message
*/ */
boolean hasOnlyAllowedLoanProperties4RequestReturn(EntityInterface e) { boolean hasOnlyAllowedLoanProperties4RequestReturn(EntityInterface e) {
...@@ -274,7 +282,11 @@ public class AWIBoxLoan extends ContainerJob { ...@@ -274,7 +282,11 @@ public class AWIBoxLoan extends ContainerJob {
return false; return false;
} }
found.add(p.getId()); found.add(p.getId());
if (!(p.getId() == getContentId()|| p.getId() == getDestinationId() || p.getId() == getBorrowerId() || p.getId() == getCommentId() || p.getId() == getLocationId())) { if (!(p.getId() == getContentId()
|| p.getId() == getDestinationId()
|| p.getId() == getBorrowerId()
|| p.getId() == getCommentId()
|| p.getId() == getLocationId())) {
p.addError(PROPERTY_NOT_ALLOWED_REQUEST_RETURN); p.addError(PROPERTY_NOT_ALLOWED_REQUEST_RETURN);
return false; // this is not a property which may be updated by anonymous. return false; // this is not a property which may be updated by anonymous.
} }
......
...@@ -31,14 +31,10 @@ import java.util.Map.Entry; ...@@ -31,14 +31,10 @@ import java.util.Map.Entry;
public abstract class AbstractEntityACLFactory<T extends EntityACL> { public abstract class AbstractEntityACLFactory<T extends EntityACL> {
private final Map<ResponsibleAgent, Long> normalGrants = private final Map<ResponsibleAgent, Long> normalGrants = new HashMap<>();
new HashMap<>(); private final Map<ResponsibleAgent, Long> priorityGrants = new HashMap<>();
private final Map<ResponsibleAgent, Long> priorityGrants = private final Map<ResponsibleAgent, Long> normalDenials = new HashMap<>();
new HashMap<>(); private final Map<ResponsibleAgent, Long> priorityDenials = new HashMap<>();
private final Map<ResponsibleAgent, Long> normalDenials =
new HashMap<>();
private final Map<ResponsibleAgent, Long> priorityDenials =
new HashMap<>();
public void grant(final ResponsibleAgent role, final int... permissionBitNumber) { public void grant(final ResponsibleAgent role, final int... permissionBitNumber) {
grant(role, false, permissionBitNumber); grant(role, false, permissionBitNumber);
...@@ -183,8 +179,7 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> { ...@@ -183,8 +179,7 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> {
set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue()); set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue());
} }
if (this.normalGrants.containsKey(set.getKey())) { if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put( this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
} }
} }
for (final Entry<ResponsibleAgent, Long> set : this.priorityGrants.entrySet()) { for (final Entry<ResponsibleAgent, Long> set : this.priorityGrants.entrySet()) {
...@@ -193,14 +188,12 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> { ...@@ -193,14 +188,12 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> {
set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue()); set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue());
} }
if (this.normalGrants.containsKey(set.getKey())) { if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put( this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
} }
} }
for (final Entry<ResponsibleAgent, Long> set : this.normalDenials.entrySet()) { for (final Entry<ResponsibleAgent, Long> set : this.normalDenials.entrySet()) {
if (this.normalGrants.containsKey(set.getKey())) { if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put( this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
} }
} }
} }
......
...@@ -24,6 +24,10 @@ package caosdb.server.permissions; ...@@ -24,6 +24,10 @@ package caosdb.server.permissions;
import static caosdb.server.permissions.Role.OTHER_ROLE; import static caosdb.server.permissions.Role.OTHER_ROLE;
import static caosdb.server.permissions.Role.OWNER_ROLE; import static caosdb.server.permissions.Role.OWNER_ROLE;
import caosdb.server.accessControl.AuthenticationUtils;
import caosdb.server.accessControl.Principal;
import caosdb.server.database.exceptions.TransactionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collection; import java.util.Collection;
...@@ -36,9 +40,6 @@ import org.apache.shiro.subject.Subject; ...@@ -36,9 +40,6 @@ import org.apache.shiro.subject.Subject;
import org.eclipse.jetty.util.ajax.JSON; import org.eclipse.jetty.util.ajax.JSON;
import org.jdom2.DataConversionException; import org.jdom2.DataConversionException;
import org.jdom2.Element; import org.jdom2.Element;
import caosdb.server.accessControl.AuthenticationUtils;
import caosdb.server.accessControl.Principal;
import caosdb.server.database.exceptions.TransactionException;
public class EntityACL { public class EntityACL {
...@@ -153,7 +154,8 @@ public class EntityACL { ...@@ -153,7 +154,8 @@ public class EntityACL {
private static boolean subjectIsOwner( private static boolean subjectIsOwner(
final Subject subject, final List<ResponsibleAgent> owners) { final Subject subject, final List<ResponsibleAgent> owners) {
for (final ResponsibleAgent owner : owners) { for (final ResponsibleAgent owner : owners) {
if ((owner instanceof Role && subject.hasRole(owner.toString())) || (owner instanceof Principal && subject.getPrincipal().equals(owner))) { if ((owner instanceof Role && subject.hasRole(owner.toString()))
|| (owner instanceof Principal && subject.getPrincipal().equals(owner))) {
return true; return true;
} }
} }
......
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
*/ */
package caosdb.server.permissions; package caosdb.server.permissions;
import caosdb.server.accessControl.UserSources;
import java.util.HashMap; import java.util.HashMap;
import org.jdom2.Attribute; import org.jdom2.Attribute;
import org.jdom2.Element; import org.jdom2.Element;
import caosdb.server.accessControl.UserSources;
public class Role implements ResponsibleAgent { public class Role implements ResponsibleAgent {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment