use of org.structr.core.entity.Principal in project structr by structr.
the class StructrFileAttributes method owner.
@Override
public UserPrincipal owner() {
if (file == null) {
return null;
}
UserPrincipal owner = null;
try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
final Principal fileOwner = file.getOwnerNode();
if (fileOwner == null) {
owner = securityContext.getUser(false)::getName;
} else {
owner = fileOwner::getName;
}
tx.success();
} catch (FrameworkException fex) {
logger.error("", fex);
}
return owner;
}
use of org.structr.core.entity.Principal in project structr by structr.
the class DOMNode method getSecurityInstructions.
static void getSecurityInstructions(final DOMNode thisNode, final Set<String> instructions) {
final Principal _owner = thisNode.getOwnerNode();
if (_owner != null) {
instructions.add("@structr:owner(" + _owner.getProperty(AbstractNode.name) + ")");
}
for (final Security security : thisNode.getSecurityRelationships()) {
if (security != null) {
final Principal grantee = security.getSourceNode();
final Set<String> perms = security.getPermissions();
final StringBuilder shortPerms = new StringBuilder();
// first character only
for (final String perm : perms) {
if (perm.length() > 0) {
shortPerms.append(perm.substring(0, 1));
}
}
if (shortPerms.length() > 0) {
// ignore SECURITY-relationships without permissions
instructions.add("@structr:grant(" + grantee.getProperty(AbstractNode.name) + "," + shortPerms.toString() + ")");
}
}
}
}
use of org.structr.core.entity.Principal in project structr by structr.
the class AbstractPrimitiveProperty method updateAccessInformation.
// ----- private methods -----
private void updateAccessInformation(final SecurityContext securityContext, final PropertyContainer propertyContainer) throws FrameworkException {
try {
if (securityContext.modifyAccessTime()) {
final Principal user = securityContext.getUser(false);
String modifiedById = null;
if (user != null) {
if (user instanceof SuperUser) {
// "virtual" UUID of superuser
modifiedById = Principal.SUPERUSER_ID;
} else {
modifiedById = user.getUuid();
}
propertyContainer.setProperty(AbstractNode.lastModifiedBy.dbName(), modifiedById);
}
propertyContainer.setProperty(AbstractNode.lastModifiedDate.dbName(), System.currentTimeMillis());
}
} catch (Throwable t) {
// fail without throwing an exception here
logger.warn("", t);
}
}
use of org.structr.core.entity.Principal in project structr by structr.
the class MeResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
Principal user = securityContext.getUser(true);
if (user != null) {
List<GraphObject> resultList = new LinkedList<>();
resultList.add(user);
return new Result(resultList, null, isCollectionResource(), isPrimitiveArray());
} else {
throw new NotAllowedException("No user");
}
}
use of org.structr.core.entity.Principal in project structr by structr.
the class MeResource method checkAndConfigure.
@Override
public boolean checkAndConfigure(String part, SecurityContext securityContext, HttpServletRequest request) throws FrameworkException {
this.securityContext = securityContext;
if ("me".equalsIgnoreCase(part)) {
this.typeResource = new TypeResource();
this.typeResource.setSecurityContext(securityContext);
this.typeResource.checkAndConfigure("user", securityContext, request);
Principal user = securityContext.getUser(true);
if (user != null) {
// we need to create synthetic nested constraints
this.idResource = new UuidResource();
this.idResource.setSecurityContext(securityContext);
this.idResource.checkAndConfigure(user.getProperty(GraphObject.id), securityContext, request);
}
}
return true;
}
Aggregations