Search in sources :

Example 6 with OToken

use of com.orientechnologies.orient.core.metadata.security.OToken in project orientdb by orientechnologies.

the class OTokenHandlerImplTest method testWebTokenCreationValidation.

@Test
@Ignore
public void testWebTokenCreationValidation() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
    db.create();
    try {
        OSecurityUser original = db.getUser();
        OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
        byte[] token = handler.getSignedWebToken(db, original);
        try {
            // Make this thread wait at least 10 milliseconds before check the validity
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        OToken tok = handler.parseWebToken(token);
        assertNotNull(tok);
        assertTrue(tok.getIsVerified());
        OUser user = tok.getUser(db);
        assertEquals(user.getName(), original.getName());
        boolean boole = handler.validateToken(tok, "open", db.getName());
        assertTrue(boole);
        assertTrue(tok.getIsValid());
    } finally {
        db.drop();
    }
}
Also used : OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with OToken

use of com.orientechnologies.orient.core.metadata.security.OToken in project orientdb by orientechnologies.

the class OTokenHandlerImplTest method testTokenNotRenew.

@Test
public void testTokenNotRenew() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
    db.create();
    try {
        OSecurityUser original = db.getUser();
        OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
        ONetworkProtocolData data = new ONetworkProtocolData();
        data.driverName = "aa";
        data.driverVersion = "aa";
        data.serializationImpl = "a";
        data.protocolVersion = 2;
        byte[] token = handler.getSignedBinaryToken(db, original, data);
        OToken tok = handler.parseBinaryToken(token);
        token = handler.renewIfNeeded(tok);
        assertEquals(0, token.length);
    } finally {
        db.drop();
    }
}
Also used : ONetworkProtocolData(com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData) OToken(com.orientechnologies.orient.core.metadata.security.OToken) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OSecurityUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser) Test(org.junit.Test)

Aggregations

OToken (com.orientechnologies.orient.core.metadata.security.OToken)7 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)5 OSecurityUser (com.orientechnologies.orient.core.metadata.security.OSecurityUser)5 Test (org.junit.Test)5 ONetworkProtocolData (com.orientechnologies.orient.server.network.protocol.ONetworkProtocolData)3 OException (com.orientechnologies.common.exception.OException)2 OUser (com.orientechnologies.orient.core.metadata.security.OUser)2 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)2 IOException (java.io.IOException)2 OSystemException (com.orientechnologies.common.exception.OSystemException)1 Ignore (org.junit.Ignore)1