Source Code Cross Referenced for RoleCondition.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » workflow » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.lenya.cms.workflow 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        /* $Id: RoleCondition.java 473861 2006-11-12 03:51:14Z gregor $  */
020:
021:        package org.apache.lenya.cms.workflow;
022:
023:        import java.util.HashSet;
024:        import java.util.Iterator;
025:        import java.util.Set;
026:
027:        import org.apache.avalon.framework.service.ServiceManager;
028:        import org.apache.avalon.framework.service.ServiceSelector;
029:        import org.apache.lenya.ac.AccessController;
030:        import org.apache.lenya.ac.AccessControllerResolver;
031:        import org.apache.lenya.ac.AccreditableManager;
032:        import org.apache.lenya.ac.Identity;
033:        import org.apache.lenya.ac.Policy;
034:        import org.apache.lenya.ac.PolicyManager;
035:        import org.apache.lenya.ac.Role;
036:        import org.apache.lenya.ac.RoleManager;
037:        import org.apache.lenya.workflow.Condition;
038:        import org.apache.lenya.workflow.Workflow;
039:        import org.apache.lenya.workflow.WorkflowException;
040:        import org.apache.lenya.workflow.Workflowable;
041:
042:        /**
043:         * Role condition
044:         */
045:        public class RoleCondition implements  Condition {
046:
047:            private Set roleIds = new HashSet();
048:
049:            protected static final String SEPARATOR = ",";
050:
051:            /**
052:             * @see org.apache.lenya.workflow.Condition#setExpression(java.lang.String)
053:             */
054:            public void setExpression(String expression)
055:                    throws WorkflowException {
056:                this .expression = expression;
057:
058:                String[] roles = expression.split(SEPARATOR);
059:                for (int i = 0; i < roles.length; i++) {
060:                    this .roleIds.add(roles[i].trim());
061:                }
062:            }
063:
064:            /**
065:             * Returns if the condition is complied in a certain situation. The
066:             * condition is complied when the current user has the role that is required
067:             * by the RoleCondition.
068:             * 
069:             * @see org.apache.lenya.workflow.impl.AbstractCondition#isComplied(Workflow,
070:             *      Workflowable)
071:             */
072:            public boolean isComplied(Workflow workflow, Workflowable instance) {
073:
074:                DocumentWorkflowable workflowable = (DocumentWorkflowable) instance;
075:                ServiceManager manager = workflowable.getServiceManager();
076:                String url = workflowable.getDocument().getCanonicalWebappURL();
077:
078:                ServiceSelector selector = null;
079:                AccessControllerResolver acResolver = null;
080:                AccessController accessController = null;
081:                try {
082:
083:                    selector = (ServiceSelector) manager
084:                            .lookup(AccessControllerResolver.ROLE + "Selector");
085:                    acResolver = (AccessControllerResolver) selector
086:                            .select(AccessControllerResolver.DEFAULT_RESOLVER);
087:                    accessController = acResolver.resolveAccessController(url);
088:
089:                    PolicyManager policyManager = accessController
090:                            .getPolicyManager();
091:                    Identity identity = workflowable.getSession().getIdentity();
092:                    AccreditableManager accreditableMgr = accessController
093:                            .getAccreditableManager();
094:                    Policy policy = policyManager.getPolicy(accreditableMgr,
095:                            url);
096:                    RoleManager roleManager = accreditableMgr.getRoleManager();
097:
098:                    boolean complied = false;
099:
100:                    for (Iterator i = this .roleIds.iterator(); i.hasNext();) {
101:                        String roleId = (String) i.next();
102:                        Role role = roleManager.getRole(roleId);
103:                        if (policy.check(identity, role) == Policy.RESULT_GRANTED) {
104:                            complied = true;
105:                        }
106:                    }
107:
108:                    return complied;
109:
110:                } catch (final Exception e) {
111:                    throw new RuntimeException(e);
112:                } finally {
113:                    if (selector != null) {
114:                        if (acResolver != null) {
115:                            if (accessController != null) {
116:                                acResolver.release(accessController);
117:                            }
118:                            selector.release(acResolver);
119:                        }
120:                        manager.release(selector);
121:                    }
122:                }
123:
124:            }
125:
126:            private String expression;
127:
128:            /**
129:             * Returns the expression of this condition.
130:             * 
131:             * @return A string.
132:             */
133:            public String getExpression() {
134:                return this .expression;
135:            }
136:
137:            /**
138:             * @see java.lang.Object#toString()
139:             */
140:            public String toString() {
141:                return getExpression();
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.