Source Code Cross Referenced for CasSecurityContextMock.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » security » provider » cas » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.security.provider.cas 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2006 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.security.provider.cas;
007:
008:        import java.util.ArrayList;
009:        import java.util.Collections;
010:        import java.util.Enumeration;
011:        import java.util.HashMap;
012:        import java.util.List;
013:        import java.util.Map;
014:
015:        import org.jasig.portal.security.IAdditionalDescriptor;
016:        import org.jasig.portal.security.IOpaqueCredentials;
017:        import org.jasig.portal.security.IPrincipal;
018:        import org.jasig.portal.security.ISecurityContext;
019:        import org.jasig.portal.security.PortalSecurityException;
020:
021:        /**
022:         * A mock-object CAS security context.
023:         * This mock object can be configured to mock-out most CAS security context
024:         * behaviors and is useful for testing CasConnectionContext (and potentially
025:         * other components making use of ICasSecurityContexts).
026:         * 
027:         * This mock object is not threadsafe.
028:         */
029:        public class CasSecurityContextMock implements  ISecurityContext,
030:                ICasSecurityContext {
031:
032:            private static final long serialVersionUID = 1L;
033:
034:            private boolean authenticated = false;
035:
036:            /**
037:             * A List of String service tokens and/or CasProxyTicketAcquisitionExceptions
038:             * and/or RuntimeExceptions which programs the behavior of this object's
039:             * response to getCasServiceToken().  For any call of getCasServiceToken(),
040:             * this object will respond by returning the first object in this List if
041:             * it is a String or null, or throwing the first object in this list if 
042:             * it is a CasProxyTicketAcquisitionException or a RuntimeException.  
043:             * This object will then remove the first item in this list and append it to
044:             * vendedServiceTokens.  If this list is empty, this object will treat it
045:             * as if it had contained null.
046:             */
047:            private List serviceTokensToVend = new ArrayList();
048:
049:            /**
050:             * A List of responses from getCasServiceToken(), in the order given.
051:             */
052:            private final List vendedServiceTokens = new ArrayList();
053:
054:            /**
055:             * A List of the String targets for which service tokens were requested.
056:             */
057:            private final List serviceTokenTargets = new ArrayList();
058:
059:            /**
060:             * Map from subcontext name to ISecurityContext value.
061:             */
062:            private Map subcontexts = new HashMap();
063:
064:            public String getCasServiceToken(String target)
065:                    throws CasProxyTicketAcquisitionException {
066:
067:                // record the target
068:                this .serviceTokenTargets.add(target);
069:
070:                // return or throw the first item in serviceTokensToVend.
071:
072:                Object toVend = null;
073:
074:                if (!serviceTokensToVend.isEmpty()) {
075:                    toVend = this .serviceTokensToVend.get(0);
076:                    this .serviceTokensToVend.remove(0);
077:                }
078:
079:                // if the list was empty, toVend is still null, as desired.
080:
081:                // add the response to the end of the list
082:                this .vendedServiceTokens.add(toVend);
083:
084:                // return or throw the response
085:                if (toVend == null) {
086:                    return null;
087:                } else if (toVend instanceof  CasProxyTicketAcquisitionException) {
088:                    throw (CasProxyTicketAcquisitionException) toVend;
089:                } else if (toVend instanceof  RuntimeException) {
090:                    throw (RuntimeException) toVend;
091:                } else if (toVend instanceof  String) {
092:                    return (String) toVend;
093:                } else {
094:                    throw new IllegalStateException("Unexpected type: "
095:                            + toVend);
096:                }
097:
098:            }
099:
100:            public int getAuthType() {
101:                return ICasSecurityContext.CAS_AUTHTYPE;
102:            }
103:
104:            public IPrincipal getPrincipalInstance() {
105:                // TODO Auto-generated method stub
106:                return null;
107:            }
108:
109:            public IOpaqueCredentials getOpaqueCredentialsInstance() {
110:                // TODO Auto-generated method stub
111:                return null;
112:            }
113:
114:            public void authenticate() throws PortalSecurityException {
115:                // TODO Auto-generated method stub
116:
117:            }
118:
119:            public IPrincipal getPrincipal() {
120:                // TODO Auto-generated method stub
121:                return null;
122:            }
123:
124:            public IOpaqueCredentials getOpaqueCredentials() {
125:                // TODO Auto-generated method stub
126:                return null;
127:            }
128:
129:            public IAdditionalDescriptor getAdditionalDescriptor() {
130:                // TODO Auto-generated method stub
131:                return null;
132:            }
133:
134:            public boolean isAuthenticated() {
135:                return this .authenticated;
136:            }
137:
138:            public ISecurityContext getSubContext(String ctx)
139:                    throws PortalSecurityException {
140:                // TODO Auto-generated method stub
141:                return null;
142:            }
143:
144:            public Enumeration getSubContexts() {
145:                return Collections.enumeration(this .subcontexts.values());
146:            }
147:
148:            public Enumeration getSubContextNames() {
149:                return Collections.enumeration(this .subcontexts.keySet());
150:            }
151:
152:            public void addSubContext(String name, ISecurityContext ctx)
153:                    throws PortalSecurityException {
154:                this .subcontexts.put(name, ctx);
155:            }
156:
157:            public List getServiceTokensToVend() {
158:                return serviceTokensToVend;
159:            }
160:
161:            public void setServiceTokensToVend(List serviceTokensToVendArg) {
162:
163:                List defensiveCopy = new ArrayList();
164:                defensiveCopy.addAll(serviceTokensToVendArg);
165:
166:                this .serviceTokensToVend = defensiveCopy;
167:            }
168:
169:            public List getVendedServiceTokens() {
170:                return vendedServiceTokens;
171:            }
172:
173:            public void setAuthenticated(boolean authenticated) {
174:                this .authenticated = authenticated;
175:            }
176:
177:            public List getServiceTokenTargets() {
178:                return serviceTokenTargets;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.