use of com.orientechnologies.orient.core.metadata.security.OSecurityUser in project wicket-orientdb by OrienteerBAP.
the class OrientResourceAuthorizationStrategy method checkResource.
/**
* Check that current user has access to mentioned resource
* @param resource resource check
* @param action {@link Action} to check for
* @param permissions {@link OrientPermission}s to check
* @return true if access is allowed
*/
public boolean checkResource(String resource, Action action, OrientPermission[] permissions) {
String actionName = action.getName();
int actionIndx = resource.indexOf(':');
if (actionIndx > 0) {
if (!(resource.endsWith(actionName) && resource.length() > actionName.length() && resource.charAt(resource.length() - actionName.length() - 1) == ':'))
return true;
else
// Should cut off action
resource = resource.substring(0, actionIndx);
} else // Default suffix is for render: so other should be skipped
if (!Component.RENDER.equals(action))
return true;
OSecurityUser user = OrientDbWebSession.get().getUser();
if (user == null)
return false;
ORule.ResourceGeneric generic = OSecurityHelper.getResourceGeneric(resource);
String specific = OSecurityHelper.getResourceSpecific(resource);
return user != null ? user.checkIfAllowed(generic, specific, OrientPermission.combinedPermission(permissions)) != null : false;
}
use of com.orientechnologies.orient.core.metadata.security.OSecurityUser in project wicket-orientdb by OrienteerBAP.
the class TransactionRequestCycleListener method start.
@Override
public void start(RequestCycle cycle) {
OrientDbWebSession session = OrientDbWebSession.get();
ODatabaseDocumentInternal db = session.getDatabaseDocumentInternal();
// It's required to have ability to check security rights locally
OSecurityUser oUser = session.getUser();
OSecurityUser dbUser = db.getUser();
if (oUser != null && oUser.getDocument() != null && oUser.getDocument().getIdentity() != null && (!oUser.getDocument().getIdentity().isValid() || dbUser == null || !Objects.equal(dbUser.getName(), oUser.getName()))) {
db.setUser(db.getMetadata().getSecurity().getUser(oUser.getName()));
}
db.begin();
}
use of com.orientechnologies.orient.core.metadata.security.OSecurityUser in project guice-persist-orient by xvik.
the class UserManager method checkSpecificUserConditions.
private boolean checkSpecificUserConditions(final String login) {
Preconditions.checkState(transactionManager.isTransactionActive(), "Tx user can't be changed outside of transaction");
final ODatabaseDocument db = connectionProvider.get();
final OSecurityUser original = db.getUser();
final boolean userChanged = !original.getName().equals(login);
Preconditions.checkState(specificTxUser.get() == null || !userChanged, "Specific user already defined for transaction as '%s'", specificTxUser.get() == null ? null : specificTxUser.get().getName());
return userChanged;
}
use of com.orientechnologies.orient.core.metadata.security.OSecurityUser in project orientdb-enterprise-agent by SAP.
the class OSecuritySymmetricKeyAuth method createServerUser.
// Derived implementations can override this method to provide new server user implementations.
@Override
protected OSecurityUser createServerUser(final ODocument userDoc) {
OSecurityUser userCfg = null;
try {
OSecuritySymmetricKeyUser user = new OSecuritySymmetricKeyUser(userDoc);
symmetricKeys.put(user.getName(), user);
OSecurityRole role = OSecurityShared.createRole(null, user);
userCfg = new OImmutableUser(user.getName(), user.getPassword(), OSecurityUser.SECURITY_USER_TYPE, role);
} catch (Exception ex) {
OLogManager.instance().error(this, "createServerUser()", ex);
}
return userCfg;
}
use of com.orientechnologies.orient.core.metadata.security.OSecurityUser in project orientdb-enterprise-agent by SAP.
the class OSystemSymmetricKeyAuth method authenticate.
// OSecurityAuthenticator
// Returns the actual username if successful, null otherwise.
// This will authenticate username using the system database.
public OSecurityUser authenticate(ODatabaseSession session, final String username, final String password) {
OSecurityUser principal = null;
try {
// dbName parameter is null because we don't need to filter any roles for this.
OSecurityUser user = getSecurity().getSystemUser(username, null);
if (user != null && user.getAccountStatus() == OSecurityUser.STATUSES.ACTIVE) {
ODocument doc = getSecurity().getContext().getSystemDatabase().executeWithDB((db) -> {
return db.load(user.getIdentity().getIdentity());
});
OUserSymmetricKeyConfig userConfig = new OUserSymmetricKeyConfig(doc);
OSymmetricKey sk = OSymmetricKey.fromConfig(userConfig);
String decryptedUsername = sk.decryptAsString(password);
if (OSecurityManager.instance().checkPassword(username, decryptedUsername)) {
principal = user;
}
}
} catch (Exception ex) {
OLogManager.instance().error(this, "authenticate()", ex);
}
return principal;
}
Aggregations