Source Code Cross Referenced for ContextCache.java in  » Database-ORM » MMBase » org » mmbase » security » implementation » context » 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 » Database ORM » MMBase » org.mmbase.security.implementation.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.security.implementation.context;
011:
012:        import java.util.HashMap;
013:        import java.util.Map;
014:        import java.util.Set;
015:
016:        import org.mmbase.util.logging.Logger;
017:        import org.mmbase.util.logging.Logging;
018:
019:        /**
020:         * ContextCache class
021:         * @javadoc
022:         *
023:         * @author Eduard Witteveen
024:         * @version $Id: ContextCache.java,v 1.11 2007/02/11 19:45:04 nklasens Exp $
025:         */
026:        public class ContextCache {
027:            private static Logger log = Logging
028:                    .getLoggerInstance(ContextCache.class.getName());
029:
030:            private org.mmbase.cache.Cache<String, Map<String, Map<String, Boolean>>> globalRightCache = new org.mmbase.cache.Cache<String, Map<String, Map<String, Boolean>>>(
031:                    50) {
032:                public String getName() {
033:                    return "ContextRight";
034:                }
035:
036:                public String getDescription() {
037:                    return "Context Security Implementation Rights Cache";
038:                }
039:            };
040:
041:            private long rightTries = 0;
042:            private long rightSucces = 0;
043:            private long rightSize = 0;
044:
045:            public void rightAdd(String operation, String context, String user,
046:                    boolean value) {
047:                Map<String, Map<String, Boolean>> operationCache = globalRightCache
048:                        .get(operation);
049:                // when operation not known, create
050:                if (operationCache == null) {
051:                    operationCache = new HashMap<String, Map<String, Boolean>>();
052:                    globalRightCache.put(operation, operationCache);
053:                }
054:                Map<String, Boolean> contextCache = operationCache.get(context);
055:                // when context not known, create
056:                if (contextCache == null) {
057:                    contextCache = new HashMap<String, Boolean>();
058:                    operationCache.put(context, contextCache);
059:                }
060:                if (contextCache.containsKey(user)) {
061:                    log
062:                            .warn("rights context cache already contained this entry");
063:                }
064:                contextCache.put(user, Boolean.valueOf(value));
065:                log.debug("added to cache the operation: " + operation
066:                        + " for context: " + context + " with user: " + user
067:                        + " with value: " + value);
068:                rightSize++;
069:            }
070:
071:            public Boolean rightGet(String operation, String context,
072:                    String user) {
073:                Map<String, Map<String, Boolean>> operationCache = globalRightCache
074:                        .get(operation);
075:                rightTries++;
076:                if (operationCache == null) {
077:                    if (log.isDebugEnabled()) {
078:                        log.debug("operation not found in cache ("
079:                                + info(rightTries, rightSucces, rightSize)
080:                                + ")");
081:                    }
082:                    return null;
083:                }
084:
085:                Map<String, Boolean> contextCache = operationCache.get(context);
086:
087:                if (contextCache == null) {
088:                    if (log.isDebugEnabled()) {
089:                        log.debug("rights context not found in cache ("
090:                                + info(rightTries, rightSucces, rightSize)
091:                                + ")");
092:                    }
093:                    return null;
094:                }
095:
096:                if (contextCache.containsKey(user)) {
097:                    rightSucces++;
098:                    if (log.isDebugEnabled()) {
099:                        log.debug("user found in cache ("
100:                                + info(rightTries, rightSucces, rightSize)
101:                                + ")");
102:                        log
103:                                .debug("the operation: " + operation
104:                                        + " for context: " + context
105:                                        + " with user: " + user + " returned: "
106:                                        + contextCache.get(user));
107:                    }
108:                }
109:                return contextCache.get(user);
110:            }
111:
112:            private org.mmbase.cache.Cache<String, Set<String>> globalContextCache = new org.mmbase.cache.Cache<String, Set<String>>(
113:                    50) {
114:                public String getName() {
115:                    return "ContextContext";
116:                }
117:
118:                public String getDescription() {
119:                    return "Context Security Implementation Context Cache";
120:                }
121:            };
122:
123:            private long contextTries = 0;
124:            private long contextSucces = 0;
125:            private long contextSize = 0;
126:
127:            public void contextAdd(String context, Set<String> possible) {
128:                // when context was already known....
129:                if (globalContextCache.containsKey(context)) {
130:                    log.warn("context cache already contained this entry");
131:                }
132:                globalContextCache.put(context, possible);
133:                log.debug("added possible list to context with name : "
134:                        + context);
135:                contextSize++;
136:            }
137:
138:            public Set<String> contextGet(String context) {
139:                contextTries++;
140:
141:                if (globalContextCache.containsKey(context)) {
142:                    contextSucces++;
143:                    log.debug("context found in cache ("
144:                            + info(contextTries, contextSucces, contextSize)
145:                            + ")");
146:                }
147:                return globalContextCache.get(context);
148:            }
149:
150:            private String info(long tries, long succes, long size) {
151:                return "hit of #" + succes + " access of #" + tries + " ("
152:                        + succes / (tries / 100.0)
153:                        + " %) with a number of entries #" + size;
154:            }
155:
156:            ContextCache() {
157:                globalContextCache.putCache();
158:                globalRightCache.putCache();
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.