public ODefaultServerSecurity(
      final OServer oServer, final OServerConfigurationManager serverCfg) {
    server = oServer;
    serverConfig = serverCfg;

    oServer.registerLifecycleListener(this);
    OSecurityManager.instance().setSecurityFactory(this);
  }
  @Test
  public void testHashMethod() throws UnsupportedEncodingException, NoSuchAlgorithmException {
    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select name, name.hash() as n256, name.hash('sha-512') as n512 from OUser"))
            .execute();

    Assert.assertFalse(result.isEmpty());
    for (ODocument d : result) {
      final String name = d.field("name");

      Assert.assertEquals(OSecurityManager.createHash(name, "SHA-256"), d.field("n256"));
      Assert.assertEquals(OSecurityManager.createHash(name, "SHA-512"), d.field("n512"));
    }
  }
  private void createSuperUser() {
    if (superUser == null)
      throw new OSecuritySystemException(
          "ODefaultServerSecurity.createSuperUser() SuperUser cannot be null");

    try {
      // Assign a temporary password so that we know if authentication requests coming from the
      // SuperUser are from us.
      superUserPassword =
          OSecurityManager.instance()
              .createSHA256(String.valueOf(new java.util.Random().nextLong()));

      superUserCfg = new OServerUserConfiguration(superUser, superUserPassword, "*");
    } catch (Exception ex) {
      OLogManager.instance().error(this, "createSuperUser() Exception: ", ex);
    }

    if (superUserPassword == null)
      throw new OSecuritySystemException("ODefaultServerSecurity Could not create SuperUser");
  }