- 1.7.6 초기 코드
[Tadpole.git] / com.hangum.tadpole.commons.sql / src / com / hangum / tadpole / engine / query / sql / TadpoleSystem_AccessControl.java
blob7fee266a4658071bda091c2896614cb43ad772c0
1 /*******************************************************************************
2 * Copyright (c) 2012 - 2015 hangum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser Public License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
7 *
8 * Contributors:
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com.hangum.tadpole.engine.query.sql;
13 import java.sql.SQLException;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
19 import com.hangum.tadpole.commons.exception.TadpoleSQLManagerException;
20 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine;
21 import com.hangum.tadpole.engine.initialize.TadpoleEngineUserDB;
22 import com.hangum.tadpole.engine.manager.TadpoleSQLManager;
23 import com.hangum.tadpole.engine.query.dao.system.TadpoleUserDbRoleDAO;
24 import com.hangum.tadpole.engine.query.dao.system.accesscontrol.AccessCtlObjectDAO;
25 import com.hangum.tadpole.engine.query.dao.system.accesscontrol.DBAccessControlDAO;
26 import com.ibatis.sqlmap.client.SqlMapClient;
28 /**
29 * db access control
31 * @author hangum
32 * @version 1.6.1
33 * @since 2015. 4. 27.
36 public class TadpoleSystem_AccessControl {
38 /**
39 * To save default access control data.
42 public static DBAccessControlDAO saveDBAccessControl(TadpoleUserDbRoleDAO roleDao) throws TadpoleSQLManagerException, SQLException {
43 DBAccessControlDAO dao = new DBAccessControlDAO();
44 dao.setDb_role_seq(roleDao.getSeq());
46 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
47 dao = (DBAccessControlDAO)sqlClient.insert("saveAccessControl", dao);
49 return dao;
52 /**
53 * Get user db access contorl data.
55 * @param roleDao
56 * @throws TadpoleSQLManagerException, SQLException
58 public static DBAccessControlDAO getDBAccessControl(TadpoleUserDbRoleDAO roleDao) throws TadpoleSQLManagerException, SQLException {
59 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
60 DBAccessControlDAO _accessCtlDao = (DBAccessControlDAO)sqlClient.queryForObject("getAccessControl", roleDao);
62 if(_accessCtlDao.getIntDetailCnt() == 0) {
63 _accessCtlDao.setAllAccessCtl(new ArrayList<AccessCtlObjectDAO>());
64 } else {
65 // select 항목이 있다면..
66 List<AccessCtlObjectDAO> listAccessDetail = sqlClient.queryForList("getAccessCtlDetail", _accessCtlDao.getSeq());
67 _accessCtlDao.setAllAccessCtl(listAccessDetail);
69 Map<String, AccessCtlObjectDAO> mapSelectTableAccessCtl = new HashMap<String, AccessCtlObjectDAO>();
70 Map<String, AccessCtlObjectDAO> mapSelectFunctionAccessCtl = new HashMap<String, AccessCtlObjectDAO>();
71 Map<String, AccessCtlObjectDAO> mapSelectProcedureAccessCtl = new HashMap<String, AccessCtlObjectDAO>();
72 for (AccessCtlObjectDAO accCtlObj : listAccessDetail) {
73 if(PublicTadpoleDefine.ACCEAS_CTL_DDL_TYPE.TABLEoVIEW.name().equals(accCtlObj.getType())) {
74 mapSelectTableAccessCtl.put(String.format("%s.%s", accCtlObj.getObj_schema(), accCtlObj.getObj_name()), accCtlObj);
75 } else if(PublicTadpoleDefine.ACCEAS_CTL_DDL_TYPE.FUNCTION.name().equals(accCtlObj.getType())) {
76 mapSelectFunctionAccessCtl.put(String.format("%s.%s", accCtlObj.getObj_schema(), accCtlObj.getObj_name()), accCtlObj);
77 } else if(PublicTadpoleDefine.ACCEAS_CTL_DDL_TYPE.PROCEDURE.name().equals(accCtlObj.getType())) {
78 mapSelectProcedureAccessCtl.put(String.format("%s.%s", accCtlObj.getObj_schema(), accCtlObj.getObj_name()), accCtlObj);
81 _accessCtlDao.setMapSelectTableAccessCtl(mapSelectTableAccessCtl);
82 _accessCtlDao.setMapSelectFunctionAccessCtl(mapSelectFunctionAccessCtl);
83 _accessCtlDao.setMapSelectProcedureAccessCtl(mapSelectProcedureAccessCtl);
86 return _accessCtlDao;
89 /**
90 * Get user db access contorl data.
92 * @param intRoleSeq
93 * @throws TadpoleSQLManagerException, SQLException
95 public static DBAccessControlDAO getDBAccessControl(int intRoleSeq) throws TadpoleSQLManagerException, SQLException {
96 TadpoleUserDbRoleDAO roleDao = new TadpoleUserDbRoleDAO();
97 roleDao.setSeq(intRoleSeq);
99 return getDBAccessControl(roleDao);
103 * update db access control
105 * @param dao
106 * @throws TadpoleSQLManagerException, SQLException
108 public static void updateDBAccessControl(DBAccessControlDAO dao) throws TadpoleSQLManagerException, SQLException {
109 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
110 sqlClient.update("updateAccessControl", dao);
112 // already data remove and add data
113 sqlClient.update("removeAccessControlDetail", dao);
115 for(AccessCtlObjectDAO objecDao : dao.getAllAccessCtl()) {
116 sqlClient.insert("insertAccessControlDetail", objecDao);