private void onDbCreated(ODatabaseDocumentTx db, IOrientDbSettings settings) { if(OrientDbSettings.ADMIN_DEFAULT_USERNAME.equals(settings.getAdminUserName()) && !OrientDbSettings.ADMIN_DEFAULT_PASSWORD.equals(settings.getAdminPassword())) { OUser admin = db.getMetadata().getSecurity().getUser(OrientDbSettings.ADMIN_DEFAULT_USERNAME); admin.setPassword(settings.getAdminPassword()); admin.save(); } if(OrientDbSettings.READER_DEFAULT_USERNAME.equals(settings.getGuestUserName()) && !OrientDbSettings.READER_DEFAULT_PASSWORD.equals(settings.getGuestPassword())) { OUser reader = db.getMetadata().getSecurity().getUser(OrientDbSettings.READER_DEFAULT_USERNAME); reader.setPassword(settings.getGuestPassword()); reader.save(); } }
@Override public boolean checkPassword(String userId, String password) { OPersistenceSession session = (OPersistenceSession)getSession(PersistenceSession.class); OUser oUser = session.getDatabase().getMetadata().getSecurity().getUser(userId); return oUser!=null?oUser.checkPassword(password):false; }
public void internalOpen(final String iUserName, final String iUserPassword, boolean checkPassword) { try { OSecurity security = metadata.getSecurity(); if (user == null || user.getVersion() != security.getVersion() || !user.getName().equalsIgnoreCase(iUserName)) { final OUser usr; if (checkPassword) { usr = security.authenticate(iUserName, iUserPassword); } else { usr = security.getUser(iUserName); } if (usr != null) user = new OImmutableUser(security.getVersion(), usr); else user = null; checkSecurity(ORule.ResourceGeneric.DATABASE, ORole.PERMISSION_READ); } } catch (OException e) { ODatabaseRecordThreadLocal.instance().remove(); throw e; } catch (Exception e) { ODatabaseRecordThreadLocal.instance().remove(); throw OException.wrapException(new ODatabaseException("Cannot open database url=" + getURL()), e); } }
public void afterUpdateOperations(final OIdentifiable id) { if (id instanceof ODocument) { ODocument doc = (ODocument) id; OImmutableClass clazz = ODocumentInternal.getImmutableSchemaClass(this, doc); if (clazz != null) { OClassIndexManager.checkIndexesAfterUpdate((ODocument) id, this); if (clazz.isFunction()) { this.getSharedContext().getFunctionLibrary().updatedFunction(doc); Orient.instance().getScriptManager().close(this.getName()); } if (clazz.isOuser() || clazz.isOrole()) { getMetadata().getSecurity().incrementVersion(); } if (clazz.isSequence()) { ((OSequenceLibraryProxy) getMetadata().getSequenceLibrary()).getDelegate().onSequenceUpdated(this, doc); } if (clazz.isTriggered()) { OClassTrigger.onRecordAfterUpdate(doc, this); } } OLiveQueryHook.addOp(doc, ORecordOperation.UPDATED, this); OLiveQueryHookV2.addOp(doc, ORecordOperation.UPDATED, this); } callbackHooks(ORecordHook.TYPE.AFTER_UPDATE, id); }
public void afterCreateOperations(final OIdentifiable id) { if (id instanceof ODocument) { ODocument doc = (ODocument) id; OImmutableClass clazz = ODocumentInternal.getImmutableSchemaClass(this, doc); if (clazz != null) { OClassIndexManager.checkIndexesAfterCreate(doc, this); if (clazz.isFunction()) { this.getSharedContext().getFunctionLibrary().createdFunction(doc); Orient.instance().getScriptManager().close(this.getName()); } if (clazz.isOuser() || clazz.isOrole()) { getMetadata().getSecurity().incrementVersion(); } if (clazz.isSequence()) { ((OSequenceLibraryProxy) getMetadata().getSequenceLibrary()).getDelegate().onSequenceCreated(this, doc); } if (clazz.isScheduler()) { getMetadata().getScheduler().scheduleEvent(new OScheduledEvent(doc)); } if (clazz.isTriggered()) { OClassTrigger.onRecordAfterCreate(doc, this); } } OLiveQueryHook.addOp(doc, ORecordOperation.CREATED, this); OLiveQueryHookV2.addOp(doc, ORecordOperation.CREATED, this); } callbackHooks(ORecordHook.TYPE.AFTER_CREATE, id); }
public void afterDeleteOperations(final OIdentifiable id) { if (id instanceof ODocument) { ODocument doc = (ODocument) id; OImmutableClass clazz = ODocumentInternal.getImmutableSchemaClass(this, doc); if (clazz != null) { OClassIndexManager.checkIndexesAfterDelete(doc, this); if (clazz.isFunction()) { this.getSharedContext().getFunctionLibrary().droppedFunction(doc); Orient.instance().getScriptManager().close(this.getName()); } if (clazz.isOuser() || clazz.isOrole()) { getMetadata().getSecurity().incrementVersion(); } if (clazz.isSequence()) { ((OSequenceLibraryProxy) getMetadata().getSequenceLibrary()).getDelegate().onSequenceDropped(this, doc); } if (clazz.isScheduler()) { final String eventName = doc.field(OScheduledEvent.PROP_NAME); getSharedContext().getScheduler().removeEventInternal(eventName); } if (clazz.isTriggered()) { OClassTrigger.onRecordAfterDelete(doc, this); } } OLiveQueryHook.addOp(doc, ORecordOperation.DELETED, this); OLiveQueryHookV2.addOp(doc, ORecordOperation.DELETED, this); } callbackHooks(ORecordHook.TYPE.AFTER_DELETE, id); }