Package org.openrdf.store

Examples of org.openrdf.store.Session


      finally {
        tr.close();
      }

      // second test: evaluate the query as an unauthorized user
      Session session = SessionManager.getOrCreate();
      session.setUsername("no_access");
      tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // third test: evaluate the query as an authorized user
      session.setUsername("trezorix");
      tr = query.evaluate();
      try {
        assertTrue(
            "query result should not be empty: current user has viewing permission by inheritance",
            tr.hasNext());
View Full Code Here


    throws Exception
  {
    RepositoryConnection con = repository.getConnection();

    try {
      Session session = SessionManager.getOrCreate();
      session.setUsername("trezorix");

      String conceptQuery = "SELECT DISTINCT ?X WHERE {?X a <" + SKOS_NS + "Concept" + "> ; ?P ?Y . } ";
      TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, conceptQuery);

      TupleResult tr = query.evaluate();
View Full Code Here

      throw HTTPException.create(statusCode, body);
    }
  }

  private void setSessionCookie() {
    Session session = SessionManager.get();

    if (session == null) {
      // no session, no cookie
      return;
    }
View Full Code Here

  }

  private URI getCurrentUser()
    throws StoreException
  {
    Session session = SessionManager.get();
    if (session != null) {
      URI userId = session.getUserId();

      if (userId != null) {
        return userId;
      }

      String username = session.getUsername();

      if (username != null) {
        // backdoor for administrator user.
        if (username.equals("administrator")) {
          session.setUserId(ACL.ADMIN);
        }
        else {
          Literal usernameLiteral = this.getValueFactory().createLiteral(username, XMLSchema.STRING);
          Cursor<? extends Statement> statements = super.getStatements(null, ACL.USERNAME,
              usernameLiteral, true, ACL.CONTEXT);

          try {
            Statement st;
            if ((st = statements.next()) != null) {
              session.setUserId((URI)st.getSubject());
            }
          }
          finally {
            statements.close();
          }
        }
        return session.getUserId();
      }
    }
    return null;
  }
View Full Code Here

  {
    // Get userID from the client info
    // TODO: find out whether to use getUser() or getPrincipals()
    String userID = getUserID(getRequest().getClientInfo());

    final Session session;

    if (userID != null) {
      session = SessionManager.getOrCreate();
      session.setUsername(userID);

      if (SessionUtil.getSessionID(getRequest()) == null) {
        // Register a new session for this client
        SessionRegistry registry = SessionRegistry.getFromContext(getContext());
        String sessionID = registry.add(session);
        SessionUtil.setSessionID(getResponse(), sessionID);
      }
    }
    else {
      session = SessionManager.get();
    }

    if (session != null && session.getUsername() != null) {
      return new StringRepresentation("logged in as '" + session.getUsername() + "'");
    }
    else {
      return new StringRepresentation("not logged in");
    }
  }
View Full Code Here

      response.setStatus(Status.SUCCESS_OK);
      response.setEntity(new StringRepresentation("bla"));
      return Filter.SKIP;
    }

    Session session = SessionManager.get();
    if (session != null && session.getUsername() != null) {
      // Already authenticated
      return CONTINUE;
    }

    redirectToCAS(request, response);
View Full Code Here

  @Override
  protected int beforeHandle(Request request, Response response) {
    String sessionID = SessionUtil.getSessionID(request);
    if (sessionID != null) {
      SessionRegistry registry = SessionRegistry.getFromContext(getContext());
      Session session = registry.get(sessionID);
      if (session != null) {
        // restore the session for this request
        SessionManager.set(session);
      }
    }
View Full Code Here

TOP

Related Classes of org.openrdf.store.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.