Source Code Cross Referenced for AuthzSectionsImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » gradebook » facades » sections » 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 » ERP CRM Financial » sakai » org.sakaiproject.tool.gradebook.facades.sections 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         *
003:         * $Id: AuthzSectionsImpl.java 19624 2006-12-15 23:58:34Z ray@media.berkeley.edu $
004:         *
005:         ***********************************************************************************
006:         *
007:         * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008:         *
009:         * Licensed under the Educational Community License, Version 1.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *      http://www.opensource.org/licenses/ecl1.php
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         *
021:         **********************************************************************************/package org.sakaiproject.tool.gradebook.facades.sections;
022:
023:        import java.util.*;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:
028:        import org.sakaiproject.section.api.SectionAwareness;
029:        import org.sakaiproject.section.api.coursemanagement.CourseSection;
030:        import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
031:        import org.sakaiproject.section.api.facade.Role;
032:
033:        import org.sakaiproject.tool.gradebook.facades.Authn;
034:        import org.sakaiproject.tool.gradebook.facades.Authz;
035:
036:        /**
037:         * An implementation of Gradebook-specific authorization needs based
038:         * on the shared Section Awareness API.
039:         */
040:        public class AuthzSectionsImpl implements  Authz {
041:            private static final Log log = LogFactory
042:                    .getLog(AuthzSectionsImpl.class);
043:
044:            private Authn authn;
045:            private SectionAwareness sectionAwareness;
046:
047:            public boolean isUserAbleToGrade(String gradebookUid) {
048:                String userUid = authn.getUserUid();
049:                return (getSectionAwareness().isSiteMemberInRole(gradebookUid,
050:                        userUid, Role.INSTRUCTOR) || getSectionAwareness()
051:                        .isSiteMemberInRole(gradebookUid, userUid, Role.TA));
052:            }
053:
054:            public boolean isUserAbleToGradeAll(String gradebookUid) {
055:                String userUid = authn.getUserUid();
056:                return getSectionAwareness().isSiteMemberInRole(gradebookUid,
057:                        userUid, Role.INSTRUCTOR);
058:            }
059:
060:            public boolean isUserAbleToGradeSection(String sectionUid) {
061:                String userUid = authn.getUserUid();
062:                return getSectionAwareness().isSectionMemberInRole(sectionUid,
063:                        userUid, Role.TA);
064:            }
065:
066:            public boolean isUserAbleToEditAssessments(String gradebookUid) {
067:                String userUid = authn.getUserUid();
068:                return getSectionAwareness().isSiteMemberInRole(gradebookUid,
069:                        userUid, Role.INSTRUCTOR);
070:            }
071:
072:            public boolean isUserAbleToViewOwnGrades(String gradebookUid) {
073:                String userUid = authn.getUserUid();
074:                return getSectionAwareness().isSiteMemberInRole(gradebookUid,
075:                        userUid, Role.STUDENT);
076:            }
077:
078:            /**
079:             * Note that this is not a particularly efficient implementation.
080:             * If the method becomes more heavily used, it should be optimized.
081:             */
082:            public boolean isUserAbleToGradeStudent(String gradebookUid,
083:                    String studentUid) {
084:                if (isUserAbleToGradeAll(gradebookUid)) {
085:                    return true;
086:                }
087:
088:                List sections = getAvailableSections(gradebookUid);
089:                for (Iterator iter = sections.iterator(); iter.hasNext();) {
090:                    CourseSection section = (CourseSection) iter.next();
091:                    if (getSectionAwareness().isSectionMemberInRole(
092:                            section.getUuid(), studentUid, Role.STUDENT)) {
093:                        return true;
094:                    }
095:                }
096:
097:                return false;
098:            }
099:
100:            /**
101:             */
102:            public List getAvailableEnrollments(String gradebookUid) {
103:                List enrollments;
104:                if (isUserAbleToGradeAll(gradebookUid)) {
105:                    enrollments = getSectionAwareness().getSiteMembersInRole(
106:                            gradebookUid, Role.STUDENT);
107:                } else {
108:                    // We use a map because we may have duplicate students among the section
109:                    // participation records.
110:                    Map enrollmentMap = new HashMap();
111:                    List sections = getAvailableSections(gradebookUid);
112:                    for (Iterator iter = sections.iterator(); iter.hasNext();) {
113:                        CourseSection section = (CourseSection) iter.next();
114:                        List sectionEnrollments = getSectionEnrollmentsTrusted(section
115:                                .getUuid());
116:                        for (Iterator eIter = sectionEnrollments.iterator(); eIter
117:                                .hasNext();) {
118:                            EnrollmentRecord enr = (EnrollmentRecord) eIter
119:                                    .next();
120:                            enrollmentMap.put(enr.getUser().getUserUid(), enr);
121:                        }
122:                    }
123:                    enrollments = new ArrayList(enrollmentMap.values());
124:                }
125:                return enrollments;
126:            }
127:
128:            public List getAvailableSections(String gradebookUid) {
129:                SectionAwareness sectionAwareness = getSectionAwareness();
130:                List availableSections = new ArrayList();
131:                boolean userAbleToGradeAll = isUserAbleToGradeAll(gradebookUid);
132:
133:                // Get the list of sections. For now, just use whatever default
134:                // sorting we get from the Section Awareness component.
135:                List sections = sectionAwareness.getSections(gradebookUid);
136:                for (Iterator iter = sections.iterator(); iter.hasNext();) {
137:                    CourseSection section = (CourseSection) iter.next();
138:                    if (userAbleToGradeAll
139:                            || isUserAbleToGradeSection(section.getUuid())) {
140:                        availableSections.add(section);
141:                    }
142:                }
143:
144:                return availableSections;
145:            }
146:
147:            private List getSectionEnrollmentsTrusted(String sectionUid) {
148:                return getSectionAwareness().getSectionMembersInRole(
149:                        sectionUid, Role.STUDENT);
150:            }
151:
152:            public List getSectionEnrollments(String gradebookUid,
153:                    String sectionUid) {
154:                String userUid = authn.getUserUid();
155:                List enrollments;
156:                if (isUserAbleToGradeAll(gradebookUid)
157:                        || isUserAbleToGradeSection(sectionUid)) {
158:                    enrollments = getSectionEnrollmentsTrusted(sectionUid);
159:                } else {
160:                    enrollments = new ArrayList();
161:                    log.warn("getSectionEnrollments for sectionUid="
162:                            + sectionUid + " called by unauthorized userUid="
163:                            + userUid);
164:                }
165:                return enrollments;
166:            }
167:
168:            public List findMatchingEnrollments(String gradebookUid,
169:                    String searchString, String optionalSectionUid) {
170:                List enrollments;
171:                List allEnrollmentsFilteredBySearch = getSectionAwareness()
172:                        .findSiteMembersInRole(gradebookUid, Role.STUDENT,
173:                                searchString);
174:
175:                if (allEnrollmentsFilteredBySearch.isEmpty()
176:                        || ((optionalSectionUid == null) && isUserAbleToGradeAll(gradebookUid))) {
177:                    enrollments = allEnrollmentsFilteredBySearch;
178:                } else {
179:                    if (optionalSectionUid == null) {
180:                        enrollments = getAvailableEnrollments(gradebookUid);
181:                    } else {
182:                        // The user has selected a particular section.
183:                        enrollments = getSectionEnrollments(gradebookUid,
184:                                optionalSectionUid);
185:                    }
186:                    Set availableStudentUids = new HashSet();
187:                    for (Iterator iter = enrollments.iterator(); iter.hasNext();) {
188:                        EnrollmentRecord enr = (EnrollmentRecord) iter.next();
189:                        availableStudentUids.add(enr.getUser().getUserUid());
190:                    }
191:
192:                    enrollments = new ArrayList();
193:                    for (Iterator iter = allEnrollmentsFilteredBySearch
194:                            .iterator(); iter.hasNext();) {
195:                        EnrollmentRecord enr = (EnrollmentRecord) iter.next();
196:                        if (availableStudentUids.contains(enr.getUser()
197:                                .getUserUid())) {
198:                            enrollments.add(enr);
199:                        }
200:                    }
201:                }
202:
203:                return enrollments;
204:            }
205:
206:            public Authn getAuthn() {
207:                return authn;
208:            }
209:
210:            public void setAuthn(Authn authn) {
211:                this .authn = authn;
212:            }
213:
214:            public SectionAwareness getSectionAwareness() {
215:                return sectionAwareness;
216:            }
217:
218:            public void setSectionAwareness(SectionAwareness sectionAwareness) {
219:                this.sectionAwareness = sectionAwareness;
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.