Package org.apache.jetspeed.om.page

Examples of org.apache.jetspeed.om.page.PageSecurity


                }
            }

            // remove page security
            query = QueryFactory.newQuery(PageSecurityImpl.class, filter);
            PageSecurity document = (PageSecurity)getPersistenceBrokerTemplate().getObjectByQuery(query);
            if (document != null)
            {
                removePageSecurity(document);
            }
        }
View Full Code Here


                allConstraints.addAll(referencedConstraints);
            }
        }

        // add any global decurity constraints references
        PageSecurity pageSecurity = getSecurity(handlerFactory);
        if (pageSecurity != null)
        {
            List globalConstraintsRefs = pageSecurity.getGlobalSecurityConstraintsRefs();
            if ((globalConstraintsRefs != null) && !globalConstraintsRefs.isEmpty())
            {
                List referencedConstraints = dereferenceSecurityConstraintsRefs(globalConstraintsRefs, handlerFactory);
                if (referencedConstraints != null)
                {
View Full Code Here

        // constriants definitions
        List constraints = null;
        if (handlerFactory != null)
        {
            // security document
            PageSecurity pageSecurity = getSecurity(handlerFactory);
            if (pageSecurity != null)
            {  
                // dereference each security constraints definition
                Iterator constraintsRefsIter = constraintsRefs.iterator();
                while (constraintsRefsIter.hasNext())
                {
                    String constraintsRef = (String)constraintsRefsIter.next();
                    SecurityConstraintsDef securityConstraintsDef = pageSecurity.getSecurityConstraintsDef(constraintsRef);
                    if ((securityConstraintsDef != null) && (securityConstraintsDef.getSecurityConstraints() != null))
                    {
                        if (constraints == null)
                        {
                            constraints = new ArrayList(constraintsRefs.size());
View Full Code Here

        {
            checkAccess(SecuredResource.VIEW_ACTION);
        }

        // get pageSecurity
        PageSecurity pageSecurity = (PageSecurity) getAllNodes().subset(PageSecurity.DOCUMENT_TYPE).get(PageSecurity.DOCUMENT_TYPE);
        if (pageSecurity == null)
        {
            throw new DocumentNotFoundException("Jetspeed PSML page security not found: " + PageSecurity.DOCUMENT_TYPE);
        }
        return pageSecurity;
View Full Code Here

        assertNotNull(link.getParent());
        assertEquals(link.getParent().getId(), folder.getId());
        assertNotNull(folder.getLinks());
        assertEquals(1, folder.getLinks().size());

        PageSecurity pageSecurity = pageManager.newPageSecurity();
        List constraintsDefs = new ArrayList(2);
        SecurityConstraintsDef constraintsDef = pageManager.newSecurityConstraintsDef();
        constraintsDef.setName("public-view");
        List defConstraints = new ArrayList(1);
        SecurityConstraint defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setUsers(Shared.makeListFromCSV("*"));
        defConstraint.setPermissions(Shared.makeListFromCSV("view"));
        defConstraints.add(defConstraint);
        constraintsDef.setSecurityConstraints(defConstraints);
        constraintsDefs.add(constraintsDef);
        constraintsDef = pageSecurity.newSecurityConstraintsDef();
        constraintsDef.setName("admin-all");
        defConstraints = new ArrayList(2);
        defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setRoles(Shared.makeListFromCSV("admin"));
        defConstraint.setPermissions(Shared.makeListFromCSV("view,edit"));
        defConstraints.add(defConstraint);
        defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setRoles(Shared.makeListFromCSV("nobody"));
        defConstraints.add(defConstraint);
        constraintsDef.setSecurityConstraints(defConstraints);
        constraintsDefs.add(constraintsDef);
        pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
        List globalConstraintsRefs = new ArrayList(2);
        globalConstraintsRefs.add("admin-all");
        globalConstraintsRefs.add("public-view");
        pageSecurity.setGlobalSecurityConstraintsRefs(globalConstraintsRefs);

        pageManager.updatePageSecurity(pageSecurity);

        assertNotNull(pageSecurity.getParent());
        assertEquals(pageSecurity.getParent().getId(), folder.getId());
        assertNotNull(folder.getPageSecurity());

        // test duplicate creates
        try
        {
            Folder dupFolder = pageManager.newFolder("/");
            pageManager.updateFolder(dupFolder);
            assertTrue("Duplicate Folder / CREATED", false);
        }
        catch (FolderNotUpdatedException e)
        {
        }
        try
        {
            Page dupPage = pageManager.newPage("/default-page.psml");
            pageManager.updatePage(dupPage);
            assertTrue("Duplicate Page / CREATED", false);
        }
        catch (PageNotUpdatedException e)
        {
        }
        try
        {
            Link dupLink = pageManager.newLink("/default.link");
            pageManager.updateLink(dupLink);
            assertTrue("Duplicate Link / CREATED", false);
        }
        catch (FailedToUpdateDocumentException e)
        {
        }
        try
        {
            PageSecurity dupPageSecurity = pageManager.newPageSecurity();
            pageManager.updatePageSecurity(dupPageSecurity);
            assertTrue("Duplicate PageSecurity / CREATED", false);
        }
        catch (FailedToUpdateDocumentException e)
        {
View Full Code Here

        {
            checkAccess(SecuredResource.VIEW_ACTION);
        }

        // get pageSecurity
        PageSecurity pageSecurity = (PageSecurity) getAllNodes().subset(PageSecurity.DOCUMENT_TYPE).get(PageSecurity.DOCUMENT_TYPE);
        if (pageSecurity == null)
        {
            throw new DocumentNotFoundException("Jetspeed PSML page security not found: " + PageSecurity.DOCUMENT_TYPE);
        }
        return pageSecurity;
View Full Code Here

                        constraintsRefs.add("public-view");
                        constraints.setSecurityConstraintsRefs(constraintsRefs);
                        folder.setSecurityConstraints(constraints);
                        pageManager.updateFolder(folder);
                       
                        PageSecurity pageSecurity = pageManager.newPageSecurity();
                        List constraintsDefs = new ArrayList(2);
                        SecurityConstraintsDef constraintsDef = pageManager.newSecurityConstraintsDef();
                        constraintsDef.setName("public-view");
                        List defConstraints = new ArrayList(1);
                        SecurityConstraint defConstraint = pageManager.newPageSecuritySecurityConstraint();
                        defConstraint.setUsers(Shared.makeListFromCSV("*"));
                        defConstraint.setPermissions(Shared.makeListFromCSV("view"));
                        defConstraints.add(defConstraint);
                        constraintsDef.setSecurityConstraints(defConstraints);
                        constraintsDefs.add(constraintsDef);
                        constraintsDef = pageManager.newSecurityConstraintsDef();
                        constraintsDef.setName("admin-all");
                        defConstraints = new ArrayList(1);
                        defConstraint = pageManager.newPageSecuritySecurityConstraint();
                        defConstraint.setRoles(Shared.makeListFromCSV("admin"));
                        defConstraint.setPermissions(Shared.makeListFromCSV("view,edit"));
                        defConstraints.add(defConstraint);
                        constraintsDef.setSecurityConstraints(defConstraints);
                        constraintsDefs.add(constraintsDef);
                        pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
                        List globalConstraintsRefs = new ArrayList(1);
                        globalConstraintsRefs.add("admin-all");
                        pageSecurity.setGlobalSecurityConstraintsRefs(globalConstraintsRefs);
                        pageManager.updatePageSecurity(pageSecurity);
                       
                        Page page = pageManager.newPage("/default-page.psml");
                        constraints = pageManager.newSecurityConstraints();
                        constraints.setOwner("admin");
                        List inlineConstraints = new ArrayList(1);
                        SecurityConstraint constraint = pageManager.newPageSecurityConstraint();
                        constraint.setRoles(Shared.makeListFromCSV("manager"));
                        constraint.setPermissions(Shared.makeListFromCSV("edit"));
                        inlineConstraints.add(constraint);
                        constraints.setSecurityConstraints(inlineConstraints);
                        constraintsRefs = new ArrayList(1);
                        constraintsRefs.add("public-view");
                        constraints.setSecurityConstraintsRefs(constraintsRefs);
                        page.setSecurityConstraints(constraints);                       
                        Fragment root = page.getRootFragment();
                        root.setName("jetspeed-layouts::VelocityTwoColumns");
                        Fragment portlet = pageManager.newPortletFragment();
                        portlet.setName("security::LoginPortlet");
                        root.getFragments().add(portlet);
                        portlet = pageManager.newPortletFragment();
                        portlet.setName("some-app::SomePortlet");
                        SecurityConstraints fragmentConstraints = pageManager.newSecurityConstraints();
                        fragmentConstraints.setOwner("user");
                        portlet.setSecurityConstraints(fragmentConstraints);
                        root.getFragments().add(portlet);
                        pageManager.updatePage(page);
                        assertNotNull(page.getRootFragment());
                        assertNotNull(page.getRootFragment().getFragments());
                        assertEquals(2, page.getRootFragment().getFragments().size());
                        assertEquals("some-app::SomePortlet", ((Fragment)page.getRootFragment().getFragments().get(1)).getName());
                        assertFalse("0".equals(((Fragment)page.getRootFragment().getFragments().get(1)).getId()));
                        TestSecureDatabasePageManager.this.somePortletId = ((Fragment)page.getRootFragment().getFragments().get(1)).getId();
                       
                        page = pageManager.newPage("/user-page.psml");
                        constraints = pageManager.newSecurityConstraints();
                        inlineConstraints = new ArrayList(1);
                        constraint = pageManager.newPageSecurityConstraint();
                        constraint.setUsers(Shared.makeListFromCSV("user"));
                        constraint.setPermissions(Shared.makeListFromCSV("view,edit"));
                        inlineConstraints.add(constraint);
                        constraints.setSecurityConstraints(inlineConstraints);
                        page.setSecurityConstraints(constraints);
                        pageManager.updatePage(page);

                        Link link = pageManager.newLink("/default.link");
                        link.setUrl("http://www.default.org/");
                        constraints = pageManager.newSecurityConstraints();
                        constraints.setOwner("admin");
                        inlineConstraints = new ArrayList(1);
                        constraint = pageManager.newLinkSecurityConstraint();
                        constraint.setRoles(Shared.makeListFromCSV("manager"));
                        constraint.setPermissions(Shared.makeListFromCSV("edit"));
                        inlineConstraints.add(constraint);
                        constraints.setSecurityConstraints(inlineConstraints);
                        link.setSecurityConstraints(constraints);                       
                        pageManager.updateLink(link);

                        return null;
                    }
                    catch (Exception e)
                    {
                        return e;
                    }
                }
            }, null);
        if (setup != null)
        {
            throw setup;
        }

        // access test as admin user
        Exception adminAccess = (Exception)Subject.doAsPrivileged(adminSubject, new PrivilegedAction()
            {
                public Object run()
                {
                    try
                    {
                        // test view access
                        Folder folder = pageManager.getFolder("/");
                        assertNotNull(folder.getPageSecurity());
                        assertNotNull(folder.getPages());
                        assertEquals(2, folder.getPages().size());
                        PageSecurity pageSecurity = pageManager.getPageSecurity();
                        Page page0 = pageManager.getPage("/default-page.psml");
                        assertNotNull(page0.getRootFragment());
                        assertNotNull(page0.getRootFragment().getFragments());
                        assertEquals(2, page0.getRootFragment().getFragments().size());
                        assertNotNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
                        assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
                        assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
                        Page page1 = pageManager.getPage("/user-page.psml");
                        Link link = pageManager.getLink("/default.link");
                        // test edit access
                        pageManager.updateFolder(folder);
                        pageManager.updatePageSecurity(pageSecurity);
                        pageManager.updatePage(page0);
                        pageManager.updatePage(page1);
                        pageManager.updateLink(link);
                        return null;
                    }
                    catch (Exception e)
                    {
                        return e;
                    }
                }
            }, null);
        if (adminAccess != null)
        {
            throw adminAccess;
        }

        // access test as user user
        Exception userAccess = (Exception)Subject.doAsPrivileged(userSubject, new PrivilegedAction()
            {
                public Object run()
                {
                    try
                    {
                        // test view access
                        Folder folder = pageManager.getFolder("/");
                        assertNotNull(folder.getPageSecurity());
                        assertNotNull(folder.getPages());
                        assertEquals(2, folder.getPages().size());
                        PageSecurity pageSecurity = pageManager.getPageSecurity();
                        Page page0 = pageManager.getPage("/default-page.psml");
                        assertNotNull(page0.getRootFragment());
                        assertNotNull(page0.getRootFragment().getFragments());
                        assertEquals(2, page0.getRootFragment().getFragments().size());
                        assertNotNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
                        assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
                        assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
                        Page page1 = pageManager.getPage("/user-page.psml");
                        Link link = pageManager.getLink("/default.link");
                        // test edit access
                        try
                        {
                            pageManager.updateFolder(folder);
                            assertTrue("Folder / not editable for user", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        try
                        {
                            pageManager.updatePageSecurity(pageSecurity);
                            assertTrue("PageSecurity not editable for user", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        try
                        {
                            pageManager.updatePage(page0);
                            assertTrue("Page /default-page.psml not editable for user", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        pageManager.updatePage(page1);
                        try
                        {
                            pageManager.updateLink(link);
                            assertTrue("Page /default.link not editable for user", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        return null;
                    }
                    catch (Exception e)
                    {
                        return e;
                    }
                }
            }, null);
        if (userAccess != null)
        {
            throw userAccess;
        }

        // access test as manager user
        Exception managerAccess = (Exception)Subject.doAsPrivileged(managerSubject, new PrivilegedAction()
            {
                public Object run()
                {
                    try
                    {
                        // test view access
                        Folder folder = pageManager.getFolder("/");
                        assertNotNull(folder.getPageSecurity());
                        assertNotNull(folder.getPages());
                        assertEquals(1, folder.getPages().size());
                        PageSecurity pageSecurity = pageManager.getPageSecurity();
                        Page page0 = pageManager.getPage("/default-page.psml");
                        assertNotNull(page0.getRootFragment());
                        assertNotNull(page0.getRootFragment().getFragments());
                        assertEquals(1, page0.getRootFragment().getFragments().size());
                        assertNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
                        assertNull(page0.getFragmentsByName("some-app::SomePortlet"));
                        Link link = pageManager.getLink("/default.link");
                        try
                        {
                            Page page1 = pageManager.getPage("/user-page.psml");
                            assertTrue("Page /user-page.psml not viewable for manager", false);
                        }
                        catch (SecurityException se)
                        {
                        }                       
                        // test edit access
                        try
                        {
                            pageManager.updateFolder(folder);
                            assertTrue("Folder / not editable for manager", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        try
                        {
                            pageManager.updatePageSecurity(pageSecurity);
                            assertTrue("PageSecurity not editable for manager", false);
                        }
                        catch (SecurityException se)
                        {
                        }
                        pageManager.updatePage(page0);
                        pageManager.updateLink(link);
                        return null;
                    }
                    catch (Exception e)
                    {
                        return e;
                    }
                }
            }, null);
        if (managerAccess != null)
        {
            throw managerAccess;
        }

        // access test as guest user
        Exception guestAccess = (Exception)Subject.doAsPrivileged(guestSubject, new PrivilegedAction()
            {
                public Object run()
                {
                    try
                    {
                        // test view access
                        Folder folder = pageManager.getFolder("/");
                        assertNotNull(folder.getPageSecurity());
                        assertNotNull(folder.getPages());
                        assertEquals(1, folder.getPages().size());
                        PageSecurity pageSecurity = pageManager.getPageSecurity();
                        Page page0 = pageManager.getPage("/default-page.psml");
                        assertNotNull(page0.getRootFragment());
                        assertNotNull(page0.getRootFragment().getFragments());
                        assertEquals(1, page0.getRootFragment().getFragments().size());
                        assertNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
View Full Code Here

                allConstraints.addAll(referencedConstraints);
            }
        }

        // add any global decurity constraints references
        PageSecurity pageSecurity = getSecurity(handlerFactory);
        if (pageSecurity != null)
        {
            List globalConstraintsRefs = pageSecurity.getGlobalSecurityConstraintsRefs();
            if ((globalConstraintsRefs != null) && !globalConstraintsRefs.isEmpty())
            {
                List referencedConstraints = dereferenceSecurityConstraintsRefs(globalConstraintsRefs, handlerFactory);
                if (referencedConstraints != null)
                {
View Full Code Here

        // constriants definitions
        List constraints = null;
        if (handlerFactory != null)
        {
            // security document
            PageSecurity pageSecurity = getSecurity(handlerFactory);
            if (pageSecurity != null)
            {  
                // dereference each security constraints definition
                Iterator constraintsRefsIter = constraintsRefs.iterator();
                while (constraintsRefsIter.hasNext())
                {
                    String constraintsRef = (String)constraintsRefsIter.next();
                    SecurityConstraintsDef securityConstraintsDef = pageSecurity.getSecurityConstraintsDef(constraintsRef);
                    if ((securityConstraintsDef != null) && (securityConstraintsDef.getSecurityConstraints() != null))
                    {
                        if (constraints == null)
                        {
                            constraints = new ArrayList(constraintsRefs.size());
View Full Code Here

        Folder fsRoot = sourceManager.getFolder(rootFolder);               
        Folder root = importFolder(fsRoot);
       
       
        // create the root page security
        PageSecurity sourcePageSecurity = null;
        try
        {
            sourcePageSecurity = sourceManager.getPageSecurity();
        }
        catch (DocumentNotFoundException e)
        {
            // skip over it, not found
        }
       
        if (sourcePageSecurity != null)
        {
            PageSecurity rootSecurity = destManager.copyPageSecurity(sourcePageSecurity);       
            destManager.updatePageSecurity(rootSecurity);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.page.PageSecurity

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.