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

STY: formatting

parent fa1d99a5
No related branches found
No related tags found
No related merge requests found
package caosdb.server.jobs.extension;
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.accessControl.UserSources;
import caosdb.server.entity.Entity;
......@@ -25,6 +23,9 @@ import caosdb.server.transaction.Update;
import caosdb.server.utils.EntityStatus;
import caosdb.server.utils.ServerMessages;
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)
public class AWIBoxLoan extends ContainerJob {
......@@ -34,8 +35,12 @@ public class AWIBoxLoan extends ContainerJob {
private static final Message BOX_HAS_LOAN =
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.");
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 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.");
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 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
protected void run() {
......@@ -48,9 +53,9 @@ public class AWIBoxLoan extends ContainerJob {
addError(ServerMessages.AUTHORIZATION_ERROR);
return;
}
// special ACL for boxes, loans and persons
if(getTransaction() instanceof Insert){
if (getTransaction() instanceof Insert) {
for (EntityInterface e : getContainer()) {
if (isBoxRecord(e)) {
e.setEntityACL(EntityACL.combine(e.getEntityACL(), getBoxACL()));
......@@ -249,19 +254,22 @@ public class AWIBoxLoan extends ContainerJob {
/** Is Record an has single box parent. */
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();
}
/** Is Record and has single loan parent */
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();
}
/**
* Has only 5/6 new/updated properties: content, returnRequested, destination, Borrower, comment
* (optional), location
* @throws Message
*
* @throws Message
*/
boolean hasOnlyAllowedLoanProperties4RequestReturn(EntityInterface e) {
runJobFromSchedule(e, CheckPropValid.class);
......@@ -269,12 +277,16 @@ public class AWIBoxLoan extends ContainerJob {
Set<Integer> found = new HashSet<>();
for (Property p : e.getProperties()) {
if (p.getEntityStatus() == EntityStatus.QUALIFIED) { // this means update
if(found.contains(p.getId())){
if (found.contains(p.getId())) {
p.addError(MULTIPLE_PROPERTIES);
return false;
}
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);
return false; // this is not a property which may be updated by anonymous.
}
......
......@@ -31,14 +31,10 @@ import java.util.Map.Entry;
public abstract class AbstractEntityACLFactory<T extends EntityACL> {
private final Map<ResponsibleAgent, Long> normalGrants =
new HashMap<>();
private final Map<ResponsibleAgent, Long> priorityGrants =
new HashMap<>();
private final Map<ResponsibleAgent, Long> normalDenials =
new HashMap<>();
private final Map<ResponsibleAgent, Long> priorityDenials =
new HashMap<>();
private final Map<ResponsibleAgent, Long> normalGrants = new HashMap<>();
private final Map<ResponsibleAgent, Long> priorityGrants = 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) {
grant(role, false, permissionBitNumber);
......@@ -183,8 +179,7 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> {
set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue());
}
if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put(
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
}
}
for (final Entry<ResponsibleAgent, Long> set : this.priorityGrants.entrySet()) {
......@@ -193,14 +188,12 @@ public abstract class AbstractEntityACLFactory<T extends EntityACL> {
set.getKey(), this.normalDenials.get(set.getKey()) & ~set.getValue());
}
if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put(
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
}
}
for (final Entry<ResponsibleAgent, Long> set : this.normalDenials.entrySet()) {
if (this.normalGrants.containsKey(set.getKey())) {
this.normalGrants.put(
set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
this.normalGrants.put(set.getKey(), this.normalGrants.get(set.getKey()) & ~set.getValue());
}
}
}
......
......@@ -24,6 +24,10 @@ package caosdb.server.permissions;
import static caosdb.server.permissions.Role.OTHER_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.BitSet;
import java.util.Collection;
......@@ -36,9 +40,6 @@ import org.apache.shiro.subject.Subject;
import org.eclipse.jetty.util.ajax.JSON;
import org.jdom2.DataConversionException;
import org.jdom2.Element;
import caosdb.server.accessControl.AuthenticationUtils;
import caosdb.server.accessControl.Principal;
import caosdb.server.database.exceptions.TransactionException;
public class EntityACL {
......@@ -153,7 +154,8 @@ public class EntityACL {
private static boolean subjectIsOwner(
final Subject subject, final List<ResponsibleAgent> 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;
}
}
......
......@@ -22,10 +22,10 @@
*/
package caosdb.server.permissions;
import caosdb.server.accessControl.UserSources;
import java.util.HashMap;
import org.jdom2.Attribute;
import org.jdom2.Element;
import caosdb.server.accessControl.UserSources;
public class Role implements ResponsibleAgent {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment