com.orientechnologies.orient.core.metadata.security.OUser Java Examples

The following examples show how to use com.orientechnologies.orient.core.metadata.security.OUser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testOQueryProvider()
{
	OQueryDataProvider<OUser> provider = new OQueryDataProvider<OUser>("select from OUser where name <> :other", OUser.class);
	provider.setSort("name", SortOrder.ASCENDING);
	provider.setParameter("other", Model.of("blalba"));
	Iterator<OUser> it = provider.iterator(0, -1);
	List<ODocument> allUsers = wicket.getTester().getMetadata().getSecurity().getAllUsers();
	assertTrue(provider.size()==allUsers.size());
	while(it.hasNext())
	{
		OUser oUser = it.next();
		assertTrue(allUsers.contains(provider.model(oUser).getObject().getDocument()));
	}
	provider.detach();
	assertTrue(provider.size()==allUsers.size());
}
 
Example #2
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testOQueryProviderContextVariables()
{
	OQueryDataProvider<OUser> provider = new OQueryDataProvider<OUser>("select from OUser where name = $name", OUser.class);
	provider.setSort("name", SortOrder.ASCENDING);
	provider.setContextVariable("name", Model.of("admin"));
	Iterator<OUser> it = provider.iterator(0, -1);
	assertEquals(1, provider.size());
	assertEquals("admin", it.next().getName());
}
 
Example #3
Source File: MainUtilsTest.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocumentWrapper() throws Exception
{
	ORID orid = new ORecordId("#5:0"); //Admin ORID
	ODocument adminDocument = orid.getRecord();
	OUser admin = wicket.getTester().getMetadata().getSecurity().getUser("admin");
	DocumentWrapperTransformer<OUser> transformer = new DocumentWrapperTransformer<OUser>(OUser.class);
	assertEquals(admin, transformer.apply(adminDocument));
}
 
Example #4
Source File: UserManager.java    From guice-persist-orient with MIT License 5 votes vote down vote up
/**
 * Changes current connection user. See {@link #executeWithTxUser(
 *com.orientechnologies.orient.core.metadata.security.OSecurityUser, SpecificUserAction)}.
 * <p>
 * LIMITATION: current user must have read right on users table.
 *
 * @param user       user login
 * @param userAction logic to execute with specific user
 * @param <T>        type of returned result (may be Void)
 * @return action result (may be null)
 */
public <T> T executeWithTxUser(final String user, final SpecificUserAction<T> userAction) {
    final boolean userChanged = checkSpecificUserConditions(user);
    final ODatabaseDocument db = connectionProvider.get();
    final T res;
    if (userChanged) {
        // this may cause security exception if current user has no access rights to users table
        final OUser specificUser = db.getMetadata().getSecurity().getUser(user);
        Preconditions.checkState(specificUser != null, "User '%s' not found", user);
        res = executeWithTxUser(specificUser, userAction);
    } else {
        res = executeWithTxUser(db.getUser(), userAction);
    }
    return res;
}
 
Example #5
Source File: OIdentityServiceProvider.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: RegistrationComponentTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@After
public void destroy() {
    DBClosure.sudoConsumer(db -> {
        String sql = String.format("delete from %s where %s = ?", OUser.CLASS_NAME, OrienteerUser.PROP_EMAIL);
        db.command(new OCommandSQL(sql)).execute(testUser.getEmail());
    });
    tester.signOut();
}
 
Example #7
Source File: RestorePasswordTest.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    DBClosure.sudoConsumer(db -> {
        user = new OrienteerUser(OUser.CLASS_NAME);
        user.setName(UUID.randomUUID().toString())
                .setPassword(UUID.randomUUID().toString())
                .setAccountStatus(OSecurityUser.STATUSES.ACTIVE);
        user.setEmail(UUID.randomUUID().toString() + "@gmail.com");
        user.save();

        OProperty property = user.getDocument().getSchemaClass().getProperty(OrienteerUser.PROP_RESTORE_ID);
        OrienteerUsersModule.REMOVE_CRON_RULE.setValue(property, "0/7 0/1 * 1/1 * ? *");
        OrienteerUsersModule.REMOVE_SCHEDULE_START_TIMEOUT.setValue(property, "3000");
    });
}
 
Example #8
Source File: UserOnlineModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public ODocument onInstall(OrienteerWebApplication app, ODatabaseDocument db) {
    super.onInstall(app, db);
    OSchemaHelper helper = OSchemaHelper.bind(db);

    helper.oClass(OUser.CLASS_NAME)
            .oProperty(PROP_ONLINE, OType.BOOLEAN)
            .oProperty(PROP_LAST_SESSION_FIELD, OType.STRING)
            .switchDisplayable(true, PROP_ONLINE, PROP_LAST_SESSION_FIELD);

    return null;
}
 
Example #9
Source File: UserOnlineModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private ISessionListener createUserOnlineListener() {
    return new ISessionListener() {
        @Override
        public void onCreated(Session session) {}

        @Override
        public void onUnbound(final String sessionId) {
            DBClosure.sudoConsumer(db -> {
                String sql = String.format("update %s set %s = ? where %s = ?", OUser.CLASS_NAME,
                        PROP_ONLINE, PROP_LAST_SESSION_FIELD);
                db.command(new OCommandSQL(sql)).execute(false, sessionId);
            });
        }
    };
}
 
Example #10
Source File: OrientDbWebSession.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
/**
 * @return currently signed in {@link OUser}. Returns null in case of no user was signed in.
 */
public OSecurityUser getUser()
{
	ODocument userDoc = getUserAsODocument();
	return userDoc!=null?new OUser(userDoc):null;
}
 
Example #11
Source File: OrienteerUserHook.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public OrienteerUserHook(ODatabaseDocument database) {
    super(database);
    setIncludeClasses(OUser.CLASS_NAME);
}
 
Example #12
Source File: UserOnlineModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
private void resetUsersOnline(ODatabaseDocument db) {
    String sql = String.format("update %s set %s = ?", OUser.CLASS_NAME, PROP_ONLINE);
    db.command(new OCommandSQL(sql)).execute(false);
}