use of org.structr.core.entity.Principal in project structr by structr.
the class FtpFilePageWrapper method getGroupName.
@Override
public String getGroupName() {
String name = "";
try (Tx tx = StructrApp.getInstance().tx()) {
Principal owner = getOwner();
if (owner != null) {
List<Principal> parents = owner.getParents();
if (!parents.isEmpty()) {
name = parents.get(0).getProperty(AbstractNode.name);
}
}
tx.success();
} catch (FrameworkException fex) {
logger.error("Error while getting group name of " + this, fex);
}
return name;
}
use of org.structr.core.entity.Principal in project structr by structr.
the class StructrUserManager method getAllUserNames.
@Override
public String[] getAllUserNames() throws FtpException {
try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
List<String> userNames = new ArrayList();
Result<Principal> result = Result.EMPTY_RESULT;
try {
result = StructrApp.getInstance(securityContext).nodeQuery(Principal.class).getResult();
} catch (FrameworkException ex) {
logger.warn("Error while searching for principal", ex);
}
if (!result.isEmpty()) {
for (Principal p : result.getResults()) {
userNames.add(p.getProperty(Principal.name));
}
}
tx.success();
return (String[]) userNames.toArray(new String[userNames.size()]);
} catch (FrameworkException fex) {
logger.error("Unable to get user by its name", fex);
}
return null;
}
use of org.structr.core.entity.Principal in project structr by structr.
the class SSHService method authenticate.
@Override
public boolean authenticate(final String username, final PublicKey key, final ServerSession session) {
boolean isValid = false;
if (key == null) {
return isValid;
}
try (final Tx tx = StructrApp.getInstance().tx()) {
final Principal principal = StructrApp.getInstance().nodeQuery(Principal.class).andName(username).getFirst();
if (principal != null) {
securityContext = SecurityContext.getInstance(principal, AccessMode.Backend);
// check single (main) pubkey
final String pubKeyData = principal.getProperty(StructrApp.key(Principal.class, "publicKey"));
if (pubKeyData != null) {
final PublicKey pubKey = PublicKeyEntry.parsePublicKeyEntry(pubKeyData).resolvePublicKey(PublicKeyEntryResolver.FAILING);
isValid = KeyUtils.compareKeys(pubKey, key);
}
// check array of pubkeys for this user
final String[] pubKeysData = principal.getProperty(StructrApp.key(Principal.class, "publicKeys"));
if (pubKeysData != null) {
for (final String k : pubKeysData) {
if (k != null) {
final PublicKey pubKey = PublicKeyEntry.parsePublicKeyEntry(k).resolvePublicKey(PublicKeyEntryResolver.FAILING);
if (KeyUtils.compareKeys(pubKey, key)) {
isValid = true;
break;
}
}
}
}
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
isValid = false;
}
try {
if (isValid) {
session.setAuthenticated();
}
} catch (IOException ex) {
logger.error("Unable to authenticate session", ex);
}
return isValid;
}
use of org.structr.core.entity.Principal in project structr by structr.
the class StructrFileAttributes method group.
@Override
public GroupPrincipal group() {
if (file == null) {
return null;
}
final List<Group> groups = new LinkedList<>();
try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
final Principal owner = file.getOwnerNode();
if (owner != null) {
groups.addAll(owner.getGroups());
}
tx.success();
} catch (FrameworkException fex) {
logger.error("", fex);
}
return groups.size() > 0 ? groups.get(0)::getName : null;
}
use of org.structr.core.entity.Principal in project structr by structr.
the class StructrCMISServicesFactory method checkAuthentication.
// ----- private methods -----
private SecurityContext checkAuthentication(final CallContext callContext) {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
final String username = callContext.getUsername();
final String password = callContext.getPassword();
final Principal principal = AuthHelper.getPrincipalForPassword(Principal.name, username, password);
SecurityContext securityContext = null;
if (principal != null) {
if (principal instanceof SuperUser) {
securityContext = SecurityContext.getSuperUserInstance();
} else {
securityContext = SecurityContext.getInstance(principal, AccessMode.Backend);
}
}
tx.success();
if (securityContext != null) {
return securityContext;
}
} catch (AuthenticationException aex) {
throw new CmisUnauthorizedException(aex.getMessage());
} catch (FrameworkException fex) {
logger.warn("", fex);
}
throw new CmisUnauthorizedException();
}
Aggregations