Source Code Cross Referenced for SecurityTools.java in  » Forum » nemesis-forum » org » nemesis » forum » util » 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 » Forum » nemesis forum » org.nemesis.forum.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * NEMESIS-FORUM.
003:         * Copyright (C) 2002  David Laurent(lithium2@free.fr). All rights reserved.
004:         * 
005:         * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
006:         * 
007:         * Copyright (C) 2001 Yasna.com. All rights reserved.
008:         * 
009:         * Copyright (C) 2000 CoolServlets.com. All rights reserved.
010:         * 
011:         * NEMESIS-FORUM. is free software; you can redistribute it and/or
012:         * modify it under the terms of the Apache Software License, Version 1.1,
013:         * or (at your option) any later version.
014:         * 
015:         * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
016:         * application are parts of NEMESIS-FORUM and are distributed under
017:         * same terms of licence.
018:         * 
019:         * 
020:         * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
021:         * and software developed by CoolServlets.com (http://www.coolservlets.com).
022:         * and software developed by Yasna.com (http://www.yasna.com).
023:         * 
024:         */
025:
026:        package org.nemesis.forum.util;
027:
028:        import java.util.Iterator;
029:
030:        import org.nemesis.forum.Authorization;
031:        import org.nemesis.forum.Forum;
032:        import org.nemesis.forum.ForumFactory;
033:        import org.nemesis.forum.ForumPermissions;
034:        import org.nemesis.forum.Group;
035:        import org.nemesis.forum.ProfileManager;
036:        import org.nemesis.forum.config.Constants;
037:
038:        /**
039:         * @author dlaurent
040:         *
041:         */
042:        public class SecurityTools {
043:
044:            /**
045:             * Returns true if the user is a system administrator.
046:             *
047:             * @param authToken the authentication token of the user
048:             * @return true if the user is a system administrator, false otherwise.
049:             */
050:            public static boolean isSystemAdmin(Authorization authToken) {
051:                ForumFactory forumFactory = ForumFactory.getInstance(authToken);
052:                ForumPermissions permissions = forumFactory
053:                        .getPermissions(authToken);
054:                return permissions.get(Constants.SYSTEM_ADMIN);
055:            }
056:
057:            /**
058:             * Returns true if the user is a forum adminstrator of any forum in the
059:             * system. For example, if there are 3 forums in the system and the user
060:             * is an adminstrator of any one or more of them, this method will return
061:             * true.<p>
062:             *
063:             * Use the method <code>isForumAdmin( Authorization, Forum)</code> to
064:             * check an individual forum for administrator status.)
065:             *
066:             * @param authToken the authentication token of the user
067:             * @return true if the user is a forum administrator of any forum in the system.
068:             */
069:            public static boolean isForumAdmin(Authorization authToken) {
070:
071:                if (isSystemAdmin(authToken))
072:                    return true;
073:
074:                ForumFactory forumFactory = ForumFactory.getInstance(authToken);
075:
076:                Iterator forumIterator = forumFactory.forums();
077:                if (!forumIterator.hasNext()) {
078:                    return false;
079:                }
080:                while (forumIterator.hasNext()) {
081:                    Forum forum = (Forum) forumIterator.next();
082:                    if (forum.hasPermission(Constants.FORUM_ADMIN)) {
083:                        return true;
084:                    }
085:                }
086:                return false;
087:            }
088:
089:            /**
090:             * Returns true if the user is a forum moderator of any forum in the
091:             * system. For example, if there are 3 forums in the system and the user
092:             * is a moderator of any one or more of them, this method will return
093:             * true.<p>
094:             *
095:             * Use the method <code>isForumModerator( Authorization, Forum)</code> to
096:             * check an individual forum for moderator status.)
097:             *
098:             * @param authToken the authentication token of the user
099:             * @return true if the user is a forum moderator of any forum in the system.
100:             */
101:            public static boolean isForumModerator(Authorization authToken) {
102:
103:                if (isSystemAdmin(authToken))
104:                    return true;
105:
106:                ForumFactory forumFactory = ForumFactory.getInstance(authToken);
107:                Iterator forumIterator = forumFactory.forums();
108:                if (!forumIterator.hasNext()) {
109:                    return false;
110:                }
111:                while (forumIterator.hasNext()) {
112:                    Forum forum = (Forum) forumIterator.next();
113:                    if (forum.hasPermission(Constants.MODERATOR)) {
114:                        return true;
115:                    }
116:                }
117:                return false;
118:            }
119:
120:            /**
121:             * Returns true if the user is a forum adminstrator of the given forum.
122:             *
123:             * @param authToken the authentication token of the user
124:             * @param forum the forum to check administrator status on.
125:             * @return true if the user is a forum administrator of the given forum.
126:             */
127:            public static boolean isForumAdmin(Authorization authToken,
128:                    Forum forum) {
129:                if (isSystemAdmin(authToken))
130:                    return true;
131:
132:                return (forum.hasPermission(Constants.FORUM_ADMIN));
133:            }
134:
135:            /**
136:             * Returns true if the user is a forum moderator of the given forum.
137:             *
138:             * @param authToken the authentication token of the user
139:             * @param forum the forum to check moderator status on.
140:             * @return true if the user is a forum moderator of the given forum.
141:             */
142:            public static boolean isForumModerator(Authorization authToken,
143:                    Forum forum) {
144:                if (isSystemAdmin(authToken))
145:                    return true;
146:
147:                return (forum.hasPermission(Constants.MODERATOR));
148:            }
149:
150:            /**
151:             * Returns true if the user is a group administrator of any group in the
152:             * system. For example, if there are 3 groups in the system and the user
153:             * is an adminstrator of any one or more of them, this method will return
154:             * true.<p>
155:             *
156:             * Use the method <code>isGroupAdmin( Authorization, Group)</code> to check
157:             * an individual group for administrator status.)
158:             *
159:             */
160:            public static boolean isGroupAdmin(Authorization authToken) {
161:                if (isSystemAdmin(authToken))
162:                    return true;
163:
164:                ForumFactory forumFactory = ForumFactory.getInstance(authToken);
165:                ProfileManager manager = forumFactory.getProfileManager();
166:                Iterator groupIterator = manager.groups();
167:                if (!groupIterator.hasNext()) {
168:                    return false;
169:                }
170:                while (groupIterator.hasNext()) {
171:                    Group group = (Group) groupIterator.next();
172:                    if (group.hasPermission(Constants.GROUP_ADMIN)) {
173:                        return true;
174:                    }
175:                }
176:                return false;
177:            }
178:
179:            /**
180:             * Returns true if the user is a group administrator of the given group.
181:             *
182:             * @param authToken the authentication token of the user
183:             * @param group the group to check administrator status on.
184:             * @return true if the user is a group administrator of the given group.
185:             */
186:            public static boolean isGroupAdmin(Authorization authToken,
187:                    Group group) {
188:                if (isSystemAdmin(authToken))
189:                    return true;
190:
191:                return (group.hasPermission(Constants.GROUP_ADMIN));
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.