Source Code Cross Referenced for AnonymousUserUtil.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » 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 » Issue Tracking » scarab 0.21 » org.tigris.scarab.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 03.01.2005
003:         *
004:         * To change the template for this generated file go to
005:         * Window - Preferences - Java - Code Generation - Code and Comments
006:         */
007:        package org.tigris.scarab.util;
008:
009:        import org.apache.fulcrum.security.TurbineSecurity;
010:        import org.apache.fulcrum.security.entity.User;
011:        import org.apache.fulcrum.security.util.DataBackendException;
012:        import org.apache.fulcrum.security.util.UnknownEntityException;
013:        import org.apache.turbine.RunData;
014:        import org.apache.turbine.Turbine;
015:        import org.tigris.scarab.om.ScarabUser;
016:
017:        /**
018:         * @author hdab
019:         *
020:         * To change the template for this generated type comment go to
021:         * Window - Preferences - Java - Code Generation - Code and Comments
022:         */
023:        public class AnonymousUserUtil {
024:
025:            /**
026:             * Returns true if the user is the one set in scarab.anonymous.username, and
027:             * false otherwise.
028:             * Note: If anonymous access is denied per configuration, this method
029:             * always returns false!
030:             * @return
031:             */
032:            public static boolean isUserAnonymous(ScarabUser user) {
033:                boolean brdo = false;
034:                if (anonymousAccessAllowed()) {
035:                    String anonymous = getAnonymousUserId();
036:                    if (anonymous != null
037:                            && user.getUserName().equals(anonymous)) {
038:                        brdo = true;
039:                    }
040:                }
041:                return brdo;
042:            }
043:
044:            /**
045:             * Returns true, when anonymous user access is explicitly allowed,.
046:             * Otherwise returns false.
047:             * @return
048:             */
049:            public static boolean anonymousAccessAllowed() {
050:                boolean allowed = Turbine.getConfiguration().getBoolean(
051:                        "scarab.anonymous.enable", false);
052:                return allowed;
053:            }
054:
055:            /**
056:             * Returns the userid of the anonymous user
057:             * Note: This method returns the anonymous userid 
058:             * independent from wether anonymous access is allowed or not.
059:             * @return
060:             */
061:            public static String getAnonymousUserId() {
062:                String anonymous = Turbine.getConfiguration().getString(
063:                        "scarab.anonymous.username", null);
064:                return anonymous;
065:            }
066:
067:            /**
068:             * Returns the name of the anonymous rolename
069:             * Note: This method returns the anonymous userid 
070:             * independent from wether anonymous access is allowed or not.
071:             * @return
072:             */
073:            public static String getAnonymousRolename() {
074:                String anonymous = Turbine.getConfiguration().getString(
075:                        "scarab.anonymous.rolename", null);
076:                return anonymous;
077:            }
078:
079:            /**
080:             * Return an instanceof the Anonymous User.
081:             * If Anonymous user has been switched off, this method
082:             * returns a Turbine-anonymous user.
083:             * @return
084:             * @throws DataBackendException
085:             * @throws UnknownEntityException
086:             */
087:            public static User getAnonymousUser() throws DataBackendException,
088:                    UnknownEntityException {
089:                User user;
090:                if (anonymousAccessAllowed()) {
091:                    String userid = getAnonymousUserId();
092:                    try {
093:                        user = TurbineSecurity.getUser(userid);
094:                    } catch (UnknownEntityException uee) {
095:                        Log.get().error(
096:                                "anonymous user does not exist: [" + userid
097:                                        + "]");
098:                        Log.get().error(
099:                                "reported error was: [" + uee.getMessage()
100:                                        + "]");
101:                        Log.get().warn("anonymous login temporarily disabled.");
102:                        user = TurbineSecurity.getAnonymousUser();
103:                    }
104:                } else {
105:                    user = TurbineSecurity.getAnonymousUser();
106:                }
107:                return user;
108:            }
109:
110:            /**
111:             * Login the Anonymous user and prepare the run data
112:             * @param data
113:             */
114:            public static void anonymousLogin(RunData data) {
115:                try {
116:                    User user;
117:                    user = AnonymousUserUtil.getAnonymousUser();
118:                    userLogin(data, user);
119:                } catch (DataBackendException e) {
120:                    Log.get().error("anonymousLogin: " + e);
121:                } catch (UnknownEntityException e) {
122:                    Log.get().error("anonymousLogin: " + e);
123:                }
124:            }
125:
126:            /**
127:             * Login a given user into the session updating the rundata.
128:             * @param data
129:             * @param user
130:             */
131:            public static void userLogin(RunData data, User user) {
132:                data.setUser(user);
133:                if (null == user || user.getUserName() == null
134:                        || user.getUserName().equals("")) {
135:                    user.setHasLoggedIn(Boolean.FALSE);
136:                } else {
137:                    user.setHasLoggedIn(Boolean.TRUE);
138:                    try {
139:                        user.updateLastLogin();
140:                    } catch (Exception e) {
141:                        Log.get().error(
142:                                "userLogin: Error updating last login: " + e);
143:                    }
144:                }
145:                data.save();
146:
147:            }
148:
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.