📄 rdbmuseridentitystore.java
字号:
/** * Copyright � 2001 The JA-SIG Collaborative. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the JA-SIG Collaborative * (http://www.jasig.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */package org.jasig.portal;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Iterator;import org.jasig.portal.groups.IEntityGroup;import org.jasig.portal.groups.IGroupMember;import org.jasig.portal.properties.PropertiesManager;import org.jasig.portal.security.IPerson;import org.jasig.portal.services.GroupService;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.jasig.portal.utils.CounterStoreFactory;/** * SQL implementation for managing creation and removal of User Portal Data * @author Susan Bramhall, Yale University (modify by Julien Marchal, University Nancy 2; Eric Dalquist - edalquist@unicon.net) */public class RDBMUserIdentityStore implements IUserIdentityStore { private static final Log log = LogFactory.getLog(RDBMUserIdentityStore.class); //********************************************************************* // Constants private static final String defaultTemplateUserName = PropertiesManager.getProperty("org.jasig.portal.services.Authentication.defaultTemplateUserName"); private static final String templateAttrName = "uPortalTemplateUserName"; private static final int guestUID = 1; static int DEBUG = 0; /** * getuPortalUID - return a unique uPortal key for a user. * calls alternate signature with createPortalData set to false. * @param person the person object * @return uPortalUID number * @throws Exception if no user is found. */ public int getPortalUID (IPerson person) throws Exception { int uPortalUID=-1; uPortalUID=this.getPortalUID(person, false); return uPortalUID; } /** * * removeuPortalUID * @param uPortalUID integer key to uPortal data for a user * @throws SQLException exception if a sql error is encountered */ public void removePortalUID(int uPortalUID) throws Exception { Connection con = RDBMServices.getConnection(); java.sql.PreparedStatement ps = null; Statement stmt = null; ResultSet rs = null; try { stmt = con.createStatement(); if (RDBMServices.supportsTransactions) con.setAutoCommit(false); // START of Addition after bug declaration (bug id 1516) // Permissions delete // must be made before delete user in UP_USER rs = stmt.executeQuery("SELECT USER_NAME FROM UP_USER WHERE USER_ID="+uPortalUID); String name = ""; if ( rs.next() ) name = rs.getString(1); rs.close(); rs = stmt.executeQuery("SELECT ENTITY_TYPE_ID FROM UP_ENTITY_TYPE WHERE ENTITY_TYPE_NAME = 'org.jasig.portal.security.IPerson'"); int type = -1; if ( rs.next() ) type = rs.getInt(1); rs.close(); rs = null; String SQLDelete = "DELETE FROM UP_PERMISSION WHERE PRINCIPAL_KEY='"+name+"' AND PRINCIPAL_TYPE="+type; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); rs = stmt.executeQuery("SELECT M.GROUP_ID " + "FROM UP_GROUP_MEMBERSHIP M, UP_GROUP G, UP_ENTITY_TYPE E " + "WHERE M.GROUP_ID = G.GROUP_ID " + " AND G.ENTITY_TYPE_ID = E.ENTITY_TYPE_ID " + " AND E.ENTITY_TYPE_NAME = 'org.jasig.portal.security.IPerson'" + " AND M.MEMBER_KEY ='"+name+"' AND M.MEMBER_IS_GROUP = 'F'"); java.util.Vector groups = new java.util.Vector(); while ( rs.next() ) groups.add(rs.getString(1)); rs.close(); rs = null; // Remove from local group // Delete from DeleteUser.java and place here // must be made before delete user in UP_USER ps = con.prepareStatement("DELETE FROM UP_GROUP_MEMBERSHIP WHERE MEMBER_KEY='"+name+"' AND GROUP_ID=?"); for ( int i = 0; i < groups.size(); i++ ) { String group = (String) groups.get(i); ps.setString(1,group); ps.executeUpdate(); } if ( ps != null ) ps.close(); // END of Addition after bug declaration (bug id 1516) SQLDelete = "DELETE FROM UP_USER WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_LAYOUT WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_PARAM WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_PROFILE WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_LAYOUT WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_SS_USER_ATTS WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_SS_USER_PARM WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_LAYOUT_PARAM WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_UA_MAP WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_LAYOUT_STRUCT WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); // START of Addition after bug declaration (bug id 1516) SQLDelete = "DELETE FROM UP_USER_LOCALE WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_PROFILE_MDATA WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_PROFILE_LOCALE WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_LAYOUT_AGGR WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_USER_LAYOUT_MDATA WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_LAYOUT_STRUCT_AGGR WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_LAYOUT_STRUCT_MDATA WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); SQLDelete = "DELETE FROM UP_LAYOUT_RESTRICTIONS WHERE USER_ID = " + uPortalUID; log.debug("RDBMUserIdentityStore::removePortalUID(): " + SQLDelete); stmt.executeUpdate(SQLDelete); // END of Addition after bug declaration (bug id 1516) if (RDBMServices.supportsTransactions) con.commit(); try { IPortletPreferencesStore portletPrefStore = PortletPreferencesStoreFactory.getPortletPreferencesStoreImpl(); portletPrefStore.deletePortletPreferencesByUser(uPortalUID); } catch (Exception e) { } } catch (SQLException se) { try { log.error( "RDBMUserIdentityStore::removePortalUID(): " + se); if (RDBMServices.supportsTransactions) con.rollback(); } catch (SQLException e) { log.error( "RDBMUserIdentityStore::removePortalUID(): " + e); } if (DEBUG>0) { System.err.println("SQLException: " + se.getMessage()); System.err.println("SQLState: " + se.getSQLState()); System.err.println("Message: " + se.getMessage()); System.err.println("Vendor: " + se.getErrorCode()); } throw se; } finally { RDBMServices.closeResultSet(rs); RDBMServices.closeStatement(stmt); RDBMServices.closePreparedStatement(ps); RDBMServices.releaseConnection(con); } } /** * Get the portal user ID for this person object. * @param person * @param createPortalData indicating whether to try to create all uPortal data for this user from template prototype * @return uPortalUID number or -1 if unable to create user. * @throws AuthorizationException if createPortalData is false and no user is found * or if a sql error is encountered */ public synchronized int getPortalUID (IPerson person, boolean createPortalData) throws AuthorizationException { PortalUser portalUser = null; try { String userName = (String)person.getAttribute(IPerson.USERNAME); String templateName = getTemplateName(person); portalUser = getPortalUser(userName); if (createPortalData) { //If we are allowed to modify the database if (portalUser != null) { //If the user has logged in we may have to update their template user information boolean hasSavedLayout = userHasSavedLayout(portalUser.getUserId()); if (!hasSavedLayout) { TemplateUser templateUser = getTemplateUser(templateName); if (portalUser.getDefaultUserId() != templateUser.getUserId()) { //Update user data with new template user's data updateUser(portalUser.getUserId(), person, templateUser); } } } else { //User hasn't logged in before, some data needs to be created for them based on their template user // Retrieve the information for the template user TemplateUser templateUser = getTemplateUser(templateName); if (templateUser == null) { throw new AuthorizationException("No information found for template user = " + templateName + ". Cannot create new account for " + userName); } // Get a new user ID for this user
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -