public ORID getUserRID(final String iUserName) { List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select rid from index:OUser.name where key = ? limit 1")).execute(iUserName); if (result != null && !result.isEmpty()) return result.get(0).rawField("rid"); return null; }
public OUser getUser(final ORID iRecordId) { if (iRecordId == null) return null; ODocument result; result = getDatabase().load(iRecordId, "roles:1"); if (!result.getClassName().equals(OUser.CLASS_NAME)) { result = null; } return new OUser(result); }
public boolean dropRole(final String iRoleName) { final Number removed = getDatabase().command("delete from ORole where name = '" + iRoleName + "'").next().getProperty("count"); return removed != null && removed.intValue() > 0; }
public ORole getRole(final String iRoleName) { if (iRoleName == null) return null; final List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select from ORole where name = ? limit 1")).execute(iRoleName); if (result != null && !result.isEmpty()) return new ORole(result.get(0)); return null; }
public ORID getRoleRID(final String iRoleName) { if (iRoleName == null) return null; final List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select rid from index:ORole.name where key = ? limit 1")).execute(iRoleName); if (result != null && !result.isEmpty()) return result.get(0).rawField("rid"); return null; }
public boolean dropUser(final String iUserName) { final Number removed = getDatabase().command("delete from OUser where name = ?", iUserName).next().getProperty("count"); return removed != null && removed.intValue() > 0; }
@Override public OUser getUser(final String iUserName) { List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select from OUser where name = ? limit 1").setFetchPlan("roles:1")).execute(iUserName); if (result != null && !result.isEmpty()) return new OUser(result.get(0)); return null; }
public List<ODocument> getAllUsers() { return getDatabase().<OCommandRequest>command(new OSQLSynchQuery<ODocument>("select from OUser")).execute(); }
public List<ODocument> getAllRoles() { return getDatabase().<OCommandRequest>command(new OSQLSynchQuery<ODocument>("select from ORole")).execute(); }
public OUser authenticate(final String iUserName, final String iUserPassword) { final String dbName = getDatabase().getName(); final OUser user = getUser(iUserName); if (user == null) throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'"); if (user.getAccountStatus() != OSecurityUser.STATUSES.ACTIVE) throw new OSecurityAccessException(dbName, "User '" + iUserName + "' is not active"); if (!(getDatabase().getStorage() instanceof OStorageProxy)) { // CHECK USER & PASSWORD if (!user.checkPassword(iUserPassword)) { // WAIT A BIT TO AVOID BRUTE FORCE try { Thread.sleep(200); } catch (InterruptedException ignore) { Thread.currentThread().interrupt(); } throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'"); } } return user; }
public OUser authenticate(final OToken authToken) { final String dbName = getDatabase().getName(); if (authToken.getIsValid() != true) { throw new OSecurityAccessException(dbName, "Token not valid"); } OUser user = authToken.getUser(getDatabase()); if (user == null && authToken.getUserName() != null) { // Token handler may not support returning an OUser so let's get username (subject) and query: user = getUser(authToken.getUserName()); } if (user == null) { throw new OSecurityAccessException(dbName, "Authentication failed, could not load user from token"); } if (user.getAccountStatus() != STATUSES.ACTIVE) throw new OSecurityAccessException(dbName, "User '" + user.getName() + "' is not active"); return user; }
final ODatabaseDocument database = getDatabase(); boolean createDefUsers = getDatabase().getStorage().getConfiguration().getContextConfiguration() .getValueAsBoolean(OGlobalConfiguration.CREATE_DEFAULT_USERS);
public void load() { final OClass userClass = getDatabase().getMetadata().getSchema().getClass("OUser"); if (userClass != null) { // @COMPATIBILITY <1.3.0 if (!userClass.existsProperty("status")) { userClass.createProperty("status", OType.STRING).setMandatory(true).setNotNull(true); } OProperty p = userClass.getProperty("name"); if (p == null) p = userClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true).setMin("1") .setRegexp("\\S+(.*\\S+)*"); if (userClass.getInvolvedIndexes("name") == null) p.createIndex(INDEX_TYPE.UNIQUE); // ROLE final OClass roleClass = getDatabase().getMetadata().getSchema().getClass("ORole"); final OProperty rules = roleClass.getProperty("rules"); if (rules != null && !OType.EMBEDDEDMAP.equals(rules.getType())) { roleClass.dropProperty("rules"); } if (!roleClass.existsProperty("inheritedRole")) { roleClass.createProperty("inheritedRole", OType.LINK, roleClass); } p = roleClass.getProperty("name"); if (p == null) p = roleClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true); if (roleClass.getInvolvedIndexes("name") == null) p.createIndex(INDEX_TYPE.UNIQUE); } }
public OUser create() { if (!getDatabase().getMetadata().getSchema().getClasses().isEmpty()) return null; boolean createDefUsers = getDatabase().getStorage().getConfiguration().getContextConfiguration() .getValueAsBoolean(OGlobalConfiguration.CREATE_DEFAULT_USERS);