Package net.sf.archimede.security

Examples of net.sf.archimede.security.SystemTransactionTemplate$SecurityDatabaseUtil


        synchronized (INSTANCE) {
            final Set foldersToUpdate = SynchronizedSet.decorate(new HashSet());
            final Set foldersToDelete = SynchronizedSet.decorate(new HashSet());
           
           
            SystemTransactionTemplate st = new SystemTransactionTemplate() {

                protected Object doInTransaction(Object trSession) throws Exception {
                    Session session = (Session) trSession;
                    while (events.hasNext()) {
                        Event e = events.nextEvent();
                        String path = e.getPath();
                        System.out.println(path);
                        if (e.getType() == Event.NODE_REMOVED) {
                            if (isFolderNode(path)) {
                                removeFolder(path);
                                foldersToDelete.remove(path);
                                continue;
                            }
                        }
                        if (e.getType() == Event.NODE_ADDED) {
                            Item item = session.getItem(path);
                            if (item.isNode()) {
                                Node node = (Node) item;
       
                                if (node.getPrimaryNodeType().getName().equals(NodesTypes.PREFIX + FolderDao.NAME)) {
                                    // Ajout l'index
                                    if (e.getType() == Event.NODE_ADDED) {
                                        indexFolder(node);
                                        continue;
                                    }
                                }
                            }
                        }
                       
                        if (isPathInFolder(path)) {
                            Node folderNode = (Node) session.getItem(getFolderPath(path));
                           
                            foldersToUpdate.add(folderNode);
                        }
                       
//                        if (e.getPath().indexOf(NodesTypes.PREFIX + CollectionDao.FOLDERS_NODE_NAME + "/") > - 1) {
//                            We presume that we only listen for changes in folder nodes
//                            Node folderNode = getFolderNode(item);
//                            this.foldersToUpdate.remove(folderNode);
//                            this.foldersToUpdate.add(folderNode);
//                        }
                    }
                   
                    for (Iterator it = foldersToUpdate.iterator(); it.hasNext(); ) {
                        Node folderNode = (Node) it.next();
                        String folderNodePath = folderNode.getPath();
                        if (!foldersToDelete.contains(folderNode.getPath())) {
                            //FIXME DECOMMENT
                            updateFolder(folderNode);
                        }
                    }
                    return null;
                }
            };
            try {
                st.execute();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
           
View Full Code Here


        if (this.managerThread != null) {
            throw new IllegalStateException("Observation manager thread is already started");
        }
        this.managerThread = new Thread() {
            public void run() {       
                SystemTransactionTemplate st = new SystemTransactionTemplate() {
       
                    protected Object doInTransaction(Object trSession) throws Exception {
                        Session session = (Session) trSession;
                        while (true) {
                           
                            if (stopRequested) {
                                break;
                            }
                           
                            synchronized (INSTANCE) {
                               
                                ListIterator li = JcrObservationManager.this.eventListeners.listIterator();
                                if (!li.hasNext()) {
                                    for (EventListenerIterator eli = session.getWorkspace().getObservationManager().getRegisteredEventListeners(); eli.hasNext();) {
                                        CustomEventListener cel = (CustomEventListener) eli.next();
                                        if (cel.isDone()) {
                                            session.getWorkspace().getObservationManager().removeEventListener(cel);
                                        }
                                    }
                                } else {
                                    System.out.println("Observation manager has " + JcrObservationManager.this.eventListeners.size() + " unregistered eventsListener(s)");
                                }
                                for (; li.hasNext(); li.remove()) {
                                    WrappedEventListener wel = (WrappedEventListener) li.next();
                                    session.getWorkspace().getObservationManager().addEventListener(wel.listener, wel.eventTypes, wel.absPath, wel.isDeep, wel.uuid, wel.nodeTypeName, wel.noLocal);
                                }
                            }
                                                                               
                            Thread.sleep(100);
                        }
                        return null;
                    }
                };
                st.execute();
            }
        };
        this.managerThread.start();
    }
View Full Code Here

        if (!username.equals("admin")) {
          //TODO log this unauthorized access
          return "home";
        }
       
        SystemTransactionTemplate st = new SystemTransactionTemplate() {
            protected Object doInTransaction(Object trSession) throws Exception {
            SessionImpl sessionImpl = (SessionImpl) trSession;
            Workspace w = sessionImpl.getWorkspace();  
                NamespaceRegistry nsRegistry = w.getNamespaceRegistry();
               
                nsRegistry.registerNamespace(getPrefix(), getNamespace());;
               
            NodeTypeManager ntMgr = w.getNodeTypeManager();
            NodeTypeRegistry ntReg  = ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
               
            ntReg.registerNodeType(getRootElementNodeTypeDef());
            ntReg.registerNodeType(getMetadataNodeTypeDef());
           
            sessionImpl.save();
               
                return null;
             }
        };
        st.execute();
   
        initElements();
       
    return "";
 
View Full Code Here

     * @param username
     * @return Will return null is no user is found
     */
    public User retrieve(final String username) {

        SystemTransactionTemplate st = new SystemTransactionTemplate() {

            protected Object doInTransaction(Object trSession) throws Exception {
                Session session = (Session) trSession;
                User user = retrieveWithinTransaction(session, username);               
                return user;
            }
        };
        User user = (User) st.execute();
       
        return user;
    }
View Full Code Here

    /**
     * @param username
     * @return Will return null is no user is found
     */
    public boolean exists(final String username, final String password) {
        SystemTransactionTemplate st = new SystemTransactionTemplate() {
           
            protected Object doInTransaction(Object trSession) throws Exception {
                Session session = (Session) trSession;
                Node usersNode = session.getRootNode().getNode(ROOT_USERS_NODE);
                if (!usersNode.hasNode(username)) {
                    return Boolean.FALSE;
                }
                Node userNode = usersNode.getNode(username);
                //FIXME Créer un noeud typé pour éviter ce check
                if (!userNode.isNodeType(NodesTypes.PREFIX + NAME)) {
                    throw new IllegalArgumentException("Node: " + userNode.getPath() + " is not of type: " + NodesTypes.PREFIX + NAME);
                }
               
                String userPassword = userNode.getProperty(NodesTypes.PREFIX + PASSWORD_PROPERTY_NAME).getString();
                if (password.equals(userPassword)) {
                    return Boolean.TRUE;
                }
                return Boolean.FALSE;
             }
        };
        Boolean value = (Boolean) st.execute();
       
        return value.booleanValue();
    }
View Full Code Here

        return value.booleanValue();
    }
   
    //FIXME Seulement utiliser le template de transaction pour cette méthode
    public void save(final User user) throws ObjectExistsException {
        SystemTransactionTemplate st = new SystemTransactionTemplate() {
           
            protected Object doInTransaction(Object trSession) throws Exception {
                Session session = (Session) trSession;
               
                Node usersNode = session.getRootNode().getNode(ROOT_USERS_NODE);
               
                if (usersNode.hasNode(user.getUsername())) {
                    throw new ObjectExistsException("Username : " + user.getUsername() + " is already saved.");
                }
                Node userNode = session.getRootNode().getNode(ROOT_USERS_NODE).addNode(user.getUsername(), NodesTypes.PREFIX + NAME);
                userNode.setProperty(NodesTypes.PREFIX + PASSWORD_PROPERTY_NAME, user.getPassword());
               
                session.save();
               
                return null;
             }
        };
        st.execute();
    }
View Full Code Here

       
        if (user.getUsername().equals("anonymous") || user.getUsername().equals("system")) {
            throw new IllegalArgumentException("Cannot update \"anonymous\" or \"system\" users");
        }
       
        SystemTransactionTemplate st = new SystemTransactionTemplate() {
           
            protected Object doInTransaction(Object trSession) throws Exception {
                Session session = (Session) trSession;
               
                Node userNode = session.getRootNode().getNode(ROOT_USERS_NODE).getNode(user.getUsername());
                userNode.setProperty(NodesTypes.PREFIX + PASSWORD_PROPERTY_NAME, user.getPassword());
               
                session.save();
               
                return null;
             }
        };
        st.execute();
    }
View Full Code Here

    }
   
    public List list() {
        final List results = new ArrayList();
       
        SystemTransactionTemplate st = new SystemTransactionTemplate() {
           
            protected Object doInTransaction(Object trSession) throws Exception {
                Session session = (Session) trSession;
                QueryManager queryManager = session.getWorkspace().getQueryManager();
                String queryString = "//element(*, "+ NodesTypes.PREFIX + NAME + ")";
                Query query = queryManager.createQuery(queryString, Query.XPATH);  
                QueryResult queryResult = query.execute();
                for (NodeIterator nit = queryResult.getNodes(); nit.hasNext(); ) {
                    Node currentNode = nit.nextNode();
                    //Don't forget, USERDAO takes a username!
                    User currentUser = retrieveWithinTransaction(session, currentNode.getName());
                    results.add(currentUser);
                }
                return null;
            }
        };
        st.execute();
        return results;
    }
View Full Code Here

                        Node currentNode = ni.nextNode();
                        if (currentNode.getPrimaryNodeType().getName().equals("nt:file")) {
                         
                          if (!currentNode.isNodeType("mix:referenceable")) {
                            final String nodePath = currentNode.getPath();
                            SystemTransactionTemplate st = new SystemTransactionTemplate() {
                                  protected Object doInTransaction(Object trSession) throws Exception {
                                  Session session = (Session) trSession;
                                      Node retrievedNode = (Node) session.getItem(nodePath);
                                      retrievedNode.addMixin("mix:referenceable");
                                      retrievedNode.save();
                                      return null;
                                   }
                              };
                              st.execute();
                          }
                           
                          //TODO Plus direct. Faire une m�thode publique, retrieve by node ?
                          StoredFile file = StoredFileDao.createInstance().retrieve(currentNode.getUUID());
                          files.add(file);
View Full Code Here

TOP

Related Classes of net.sf.archimede.security.SystemTransactionTemplate$SecurityDatabaseUtil

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.