Source Code Cross Referenced for SubscriptionUserCleanup.java in  » Report » pentaho-report » org » pentaho » ui » servlet » 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 » Report » pentaho report » org.pentaho.ui.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Jan 10, 2006
014:         */
015:        package org.pentaho.ui.servlet;
016:
017:        import java.io.IOException;
018:        import java.io.Writer;
019:
020:        import javax.servlet.ServletConfig;
021:        import javax.servlet.ServletException;
022:        import javax.servlet.http.HttpServletRequest;
023:        import javax.servlet.http.HttpServletResponse;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.dom4j.Document;
028:        import org.dom4j.DocumentFactory;
029:        import org.dom4j.Element;
030:        import org.dom4j.Namespace;
031:        import org.dom4j.QName;
032:        import org.dom4j.io.OutputFormat;
033:        import org.dom4j.io.XMLWriter;
034:        import org.pentaho.core.session.IPentahoSession;
035:        import org.pentaho.core.system.PentahoSystem;
036:        import org.pentaho.messages.Messages;
037:        import org.pentaho.messages.util.LocaleHelper;
038:
039:        import com.pentaho.repository.subscribe.ISubscriptionRepository;
040:
041:        /**
042:         * Provides a web interface for the management of users. The service should be
043:         * called by external systems to notify Pentaho when a user has been remove,
044:         * allowing for proper clean-up of objects owned by the user.
045:         * <p>
046:         * <b>Parameters</b> <table cellspacing='5' cellpadding='3'>
047:         * <tr>
048:         * <td valign='top'>command</td>
049:         * <td valign='top'>the command to exeucte. The only valid value is <i>delete</i>.</td>
050:         * <td valign='top'>required</td>
051:         * </tr>
052:         * <tr>
053:         * <td valign='top'>user</td>
054:         * <td valign='top'>the user name of the user for whom the action is taken. For
055:         * example, this would be the user to delete.</td>
056:         * <td valign='top'>required</td>
057:         * </tr>
058:         * <tr>
059:         * <td valign='top'>password</td>
060:         * <td valign='top'>the password for authenticating the system invoking the
061:         * call. This password must match the value of the <i>parameter</i> optional
062:         * initialization parameter for the servlet and specified in the web.xml.</td>
063:         * <td valign='top'>optional</td>
064:         * </tr>
065:         * </table>
066:         * 
067:         * @author Anthony de Shazor
068:         * 
069:         */
070:        public class SubscriptionUserCleanup extends ServletBase {
071:
072:            private static final int SERVICE_SUCCESS = 0;
073:
074:            private static final int SERVICE_FAILURE = 1;
075:
076:            private static final int REQUEST_FAILURE = 2;
077:
078:            private static final long serialVersionUID = -3249803751706281261L;
079:
080:            private static final Log logger = LogFactory
081:                    .getLog(SubscriptionUserCleanup.class);
082:
083:            private String password;
084:
085:            /**
086:             * Constructs an instance.
087:             */
088:            public SubscriptionUserCleanup() {
089:                super ();
090:            }
091:
092:            /*
093:             * (non-Javadoc)
094:             * 
095:             * @see org.pentaho.core.ui.servlet.ServletBase#getLogger()
096:             */
097:            public Log getLogger() {
098:                return logger;
099:            }
100:
101:            /*
102:             * (non-Javadoc)
103:             * 
104:             * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
105:             */
106:            public void init(ServletConfig config) throws ServletException {
107:                super .init(config);
108:
109:                password = config.getInitParameter("password"); //$NON-NLS-1$
110:            }
111:
112:            /*
113:             * (non-Javadoc)
114:             * 
115:             * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
116:             *      javax.servlet.http.HttpServletResponse)
117:             */
118:            protected void doGet(HttpServletRequest request,
119:                    HttpServletResponse response) throws ServletException,
120:                    IOException {
121:
122:                PentahoSystem.systemEntryPoint();
123:
124:                try {
125:                    String userName;
126:                    String passwordParam;
127:                    String command;
128:                    Element soap;
129:
130:                    command = request.getParameter("command"); //$NON-NLS-1$
131:                    userName = request.getParameter("user"); //$NON-NLS-1$
132:                    passwordParam = request.getParameter("password"); //$NON-NLS-1$
133:
134:                    if (command == null) {
135:                        soap = generateSOAPMessage(
136:                                REQUEST_FAILURE,
137:                                Messages
138:                                        .getErrorString("ManageUsers.ERROR_0004_MISSING_COMMAND")); //$NON-NLS-1$                
139:                    } else if (userName == null) {
140:                        soap = generateSOAPMessage(
141:                                REQUEST_FAILURE,
142:                                Messages
143:                                        .getErrorString("ManageUsers.ERROR_0001_MISSING_USERNAME")); //$NON-NLS-1$
144:                    } else if ((password != null) && (password.length() > 0)
145:                            && !password.equals(passwordParam)) {
146:                        soap = generateSOAPMessage(
147:                                REQUEST_FAILURE,
148:                                Messages
149:                                        .getErrorString("ManageUsers.ERROR_0002_UNAUTHORIZED_ACCESS")); //$NON-NLS-1$
150:                    } else {
151:                        if ("delete".equals(command)) { //$NON-NLS-1$
152:                            soap = deleteUser(request, userName);
153:                        } else {
154:                            soap = generateSOAPMessage(
155:                                    REQUEST_FAILURE,
156:                                    Messages
157:                                            .getErrorString(
158:                                                    "ManageUsers.ERROR_0005_UNKNOWN_COMMAND", command)); //$NON-NLS-1$                                    
159:                        }
160:                    }
161:
162:                    generateResponse(response, soap);
163:                } finally {
164:                    PentahoSystem.systemExitPoint();
165:                }
166:            }
167:
168:            private void generateResponse(HttpServletResponse response,
169:                    Element soap) throws IOException {
170:                Writer output;
171:                XMLWriter xmlWriter;
172:                OutputFormat format;
173:
174:                response.setContentType("text/xml"); //$NON-NLS-1$
175:                response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
176:
177:                output = response.getWriter();
178:                format = OutputFormat.createCompactFormat();
179:                xmlWriter = new XMLWriter(output, format);
180:                xmlWriter.write(soap);
181:            }
182:
183:            private Element deleteUser(HttpServletRequest request, String user) {
184:                Element soap = null;
185:
186:                try {
187:                    ISubscriptionRepository repository;
188:                    IPentahoSession pentahoSession;
189:
190:                    pentahoSession = getPentahoSession(request);
191:                    repository = PentahoSystem
192:                            .getSubscriptionRepository(pentahoSession);
193:                    if (repository == null) {
194:                        soap = generateSOAPMessage(
195:                                SERVICE_FAILURE,
196:                                Messages
197:                                        .getErrorString("ManageUsers.ERROR_0006_REPOSITORY_ERROR")); //$NON-NLS-1$                
198:                    } else {
199:                        repository.deleteUserSubscriptions(user);
200:                        soap = generateSOAPMessage(SERVICE_SUCCESS, user);
201:                    }
202:                } catch (Exception ex) {
203:                    String message = ex.toString();
204:
205:                    soap = generateSOAPMessage(
206:                            SERVICE_FAILURE,
207:                            Messages
208:                                    .getErrorString(
209:                                            "ManageUsers.ERROR_0003_SUBSCRIPTION_DELETE_FAILURE_MESSAGE", user, message)); //$NON-NLS-1$                        
210:                }
211:
212:                return soap;
213:            }
214:
215:            private static Element generateSOAPMessage(int status,
216:                    String message) {
217:                DocumentFactory factory = DocumentFactory.getInstance();
218:                Document soap = factory.createDocument();
219:                Element envelope;
220:                Element body;
221:                QName qname;
222:                Namespace namespace;
223:
224:                namespace = new Namespace(
225:                        "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"); //$NON-NLS-1$ //$NON-NLS-2$        
226:                envelope = soap.addElement(new QName("Envelope", namespace)); //$NON-NLS-1$
227:                qname = new QName("encodingStyle", namespace); //$NON-NLS-1$
228:                envelope.addAttribute(qname,
229:                        "http://schemas.xmlsoap.org/soap/encoding/"); //$NON-NLS-1$
230:                body = envelope.addElement(new QName("Body", namespace)); //$NON-NLS-1$
231:
232:                if (status == SERVICE_SUCCESS) {
233:                    Element response = body.addElement("ManageUsers-response"); //$NON-NLS-1$
234:                    response.addCDATA(message);
235:                } else {
236:                    Element fault = body.addElement(new QName(
237:                            "Fault", namespace)); //$NON-NLS-1$
238:                    Element code = fault
239:                            .addElement(new QName("Code", namespace)); //$NON-NLS-1$
240:                    Element value = code.addElement(new QName(
241:                            "Value", namespace)); //$NON-NLS-1$
242:                    Element subcode;
243:                    Element reason;
244:                    Element text;
245:
246:                    if (status == REQUEST_FAILURE) {
247:                        value.setText("SOAP-ENV:Sender"); //$NON-NLS-1$
248:                    } else {
249:                        value.setText("SOAP-ENV:Reciever"); //$NON-NLS-1$
250:                    }
251:
252:                    subcode = code.addElement(new QName("Subcode", namespace)); //$NON-NLS-1$
253:                    value = subcode.addElement(new QName("Value", namespace)); //$NON-NLS-1$
254:                    value.addCDATA(message);
255:                    reason = fault.addElement(new QName("Reason", namespace)); //$NON-NLS-1$
256:                    text = reason.addElement(new QName("Text", namespace)); //$NON-NLS-1$
257:                    text.addAttribute(
258:                            "lang", LocaleHelper.getDefaultLocale().toString()); //$NON-NLS-1$
259:                    text.addCDATA(message);
260:
261:                    // Add empty Detail section
262:                    fault.addElement(new QName("Detail", namespace)); //$NON-NLS-1$
263:                }
264:
265:                return envelope;
266:            }
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.