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


001:        /* Copyright 2001 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.tools;
007:
008:        import java.sql.Connection;
009:        import java.sql.DatabaseMetaData;
010:        import java.sql.ResultSet;
011:        import java.sql.SQLException;
012:        import java.sql.Statement;
013:
014:        import org.jasig.portal.AuthorizationException;
015:        import org.jasig.portal.IUserIdentityStore;
016:        import org.jasig.portal.RDBMServices;
017:        import org.jasig.portal.RDBMUserIdentityStore;
018:        import org.jasig.portal.security.IPerson;
019:        import org.jasig.portal.security.PersonFactory;
020:        import org.springframework.dao.DataAccessException;
021:
022:        /**
023:         * Title:        Delete Portal User
024:         * Description:  Deletes all traces of a portal user from the database
025:         * Company:
026:         * @author  Atul Shenoy and Susan Bramhall (modify by Julien Marchal, University Nancy 2)
027:         * @version $Revision: 35664 $
028:         */
029:
030:        public class DeleteUser {
031:
032:            public static void main(String[] args) {
033:                RDBMServices.setGetDatasourceFromJndi(false); /*don't try jndi when not in web app */
034:
035:                if (args.length < 1) {
036:                    System.err.println("Usage \"DeleteUser <username>\"");
037:                    return;
038:                }
039:                int portalUID = -1;
040:                IPerson per = PersonFactory.createPerson();
041:                per.setAttribute(IPerson.USERNAME, args[0]);
042:
043:                IUserIdentityStore rdbmuser = new RDBMUserIdentityStore();
044:
045:                try {
046:                    portalUID = rdbmuser.getPortalUID(per, false);
047:                    System.out.println("DeleteUser.main(): Got portal UID for "
048:                            + args[0] + ": " + portalUID);
049:                } catch (AuthorizationException e) {
050:                    System.err
051:                            .println("DeleteUser.main(): Attempting to get portal UID for "
052:                                    + args[0]
053:                                    + " - Authorization exception: "
054:                                    + e.getMessage());
055:                    return;
056:                }
057:
058:                if (portalUID > -1) {
059:                    try {
060:                        rdbmuser.removePortalUID(portalUID);
061:                        System.out.println("DeleteUser.main(): Removed "
062:                                + portalUID + " from portal db.");
063:                    }
064:
065:                    catch (Exception e) {
066:                        System.err
067:                                .println("DeleteUser.main(): Attempting to delete user: "
068:                                        + "error removing user from user identity store.");
069:                        e.printStackTrace();
070:                        return;
071:                    }
072:                } else {
073:                    System.err.println("DeleteUser.removePortalUid(): "
074:                            + "Attempting to delete " + portalUID
075:                            + "; unable to find user.");
076:                    return;
077:                }
078:
079:                // Still left: bookmarks
080:                // No current way to notify channels
081:                // So directly access the database
082:                // This is the wrong way to do this
083:                // We need a way for channels to remove
084:                // data for a user when the user is deleted
085:
086:                try {
087:                    deleteBookmarks(portalUID);
088:                } catch (SQLException e) {
089:                    System.err
090:                            .println("DeleteUser.main(): Error deleting bookmarks: "
091:                                    + e.getMessage());
092:                }
093:                return;
094:            }
095:
096:            public static void deleteBookmarks(int uid) throws SQLException {
097:                DatabaseMetaData metadata = null;
098:                Connection con = null;
099:                try {
100:                    con = RDBMServices.getConnection();
101:
102:                    Statement stmt = null;
103:                    try {
104:                        metadata = con.getMetaData();
105:                        String[] names = { "TABLE" };
106:                        ResultSet tableNames = null;
107:                        try {
108:                            tableNames = metadata.getTables(null, "%",
109:                                    "UPC_BOOKMARKS", names);
110:
111:                            if (tableNames.next()) {
112:                                stmt = con.createStatement();
113:                                System.out
114:                                        .println("Deleting bookmarks from UPC_BOOKMARKS");
115:                                String bookmarksSql = "DELETE FROM UPC_BOOKMARKS WHERE PORTAL_USER_ID="
116:                                        + uid;
117:                                stmt.execute(bookmarksSql);
118:                            }
119:                        } finally {
120:                            try {
121:                                tableNames.close();
122:                            } catch (Exception e) {
123:                            }
124:                        }
125:                    } finally {
126:                        try {
127:                            stmt.close();
128:                        } catch (Exception e) {
129:                        }
130:                    }
131:                } catch (DataAccessException dae) {
132:                    // we know this was thrown by RDBMServices.getConnection().
133:                    throw new SQLException("DeleteUser.deleteBookmarks(): "
134:                            + "Unable to get a database connection.");
135:                } finally {
136:                    try {
137:                        RDBMServices.releaseConnection(con);
138:                    } catch (Exception e) {
139:                    }
140:                }
141:                return;
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.