View Javadoc

1   /*
2   jGuard is a security framework based on top of jaas (java authentication and authorization security).
3   it is written for web applications, to resolve simply, access control problems.
4   version $Name$
5   http://sourceforge.net/projects/jguard/
6   
7   Copyright (C) 2004  Charles GAY
8   
9   This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13  
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  Lesser General Public License for more details.
18  
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  
23  
24  jGuard project home page:
25  http://sourceforge.net/projects/jguard/
26  
27  */
28  package net.sf.jguard.ext.authorization.manager;
29  
30  import net.sf.jguard.core.authorization.manager.AuthorizationManager;
31  import java.security.Permission;
32  import java.security.Principal;
33  import java.sql.Connection;
34  import java.sql.PreparedStatement;
35  import java.sql.ResultSet;
36  import java.sql.SQLException;
37  import java.util.ArrayList;
38  import java.util.Arrays;
39  import java.util.HashMap;
40  import java.util.HashSet;
41  import java.util.Iterator;
42  import java.util.List;
43  import java.util.Map;
44  import java.util.Properties;
45  import java.util.Set;
46  import java.util.Stack;
47  
48  import javax.sql.DataSource;
49  
50  import net.sf.jguard.core.CoreConstants;
51  import net.sf.jguard.core.PolicyEnforcementPointOptions;
52  import net.sf.jguard.core.authorization.permissions.Domain;
53  import net.sf.jguard.core.authorization.permissions.JGPermissionCollection;
54  import net.sf.jguard.core.authorization.permissions.JGPositivePermissionCollection;
55  import net.sf.jguard.core.authorization.permissions.NoSuchPermissionException;
56  import net.sf.jguard.core.authorization.permissions.PermissionUtils;
57  import net.sf.jguard.core.principals.RolePrincipal;
58  import net.sf.jguard.ext.JdbcManager;
59  import net.sf.jguard.ext.JdbcManagerHelper;
60  import net.sf.jguard.ext.SecurityConstants;
61  import net.sf.jguard.core.authorization.AuthorizationException;
62  import net.sf.jguard.ext.database.ConnectionFactory;
63  import net.sf.jguard.ext.database.DatabaseUtils;
64  import org.slf4j.Logger;
65  import org.slf4j.LoggerFactory;
66  
67  /**
68   * jdbc-based AuthorizationManager class used for all database backend.
69   * @author <a href="mailto:diabolo512@users.sourceforge.net">Charles Gay</a>
70   * @author <a href="mailto:vinipitta@users.sourceforge.net">Vinicius Pitta Lima de Araujo</a>
71   * @author <a href="mailto:tandilero@users.sourceforge.net">Maximiliano Batelli</a>
72   */
73  public class JdbcAuthorizationManager extends AbstractAuthorizationManager implements AuthorizationManager,JdbcManager{
74  
75  	private static final Logger logger = LoggerFactory.getLogger(JdbcAuthorizationManager.class.getName());
76  
77  
78      protected static final String NAME = "name";
79      protected static final String DOMAIN_NAME= "domain_name";
80  
81      //domainIds is only dedicated to the jdbc subclasses
82      protected Map domainIds;
83  
84      //table and index names
85      protected static String jgDomainSeq ="jg_domain_seq";
86      protected static String jgPermissionSeq ="jg_permission_seq";
87      protected static String jgAppPrincipalSeq ="jg_app_principal_seq";
88      protected static String jgUrlQuerySeq ="jg_url_query_seq";
89      protected static String jgPrincipalDomain ="jg_principal_domain";
90      protected static String jgDomain ="jg_domain";
91      protected static String jgAppPrincipal ="jg_app_principal";
92      protected static String jgPrincipalPermission ="jg_principal_permission";
93      protected static String jgPermission= "jg_permission";
94      protected static String jgUrlQuery = "jg_urlquery";
95      protected static String jgPrincipalHierarchy = "jg_principal_principal";
96  
97      //SQL queries
98      protected String PRINCIPALS_HIERARCHY = "PRINCIPALS_HIERARCHY";
99      protected String CREATE_PRINCIPAL_INHERITANCE = "CREATE_PRINCIPAL_INHERITANCE";
100     protected String DELETE_PRINCIPAL_INHERITANCE = "DELETE_PRINCIPAL_INHERITANCE";
101 
102 
103     protected String PRINCIPALS="PRINCIPALS";
104     protected  String PERMISSIONS_FROM_PRINCIPAL="PERMISSIONS_FROM_PRINCIPAL";
105     protected  String PERMISSIONS_FROM_DOMAINS="PERMISSIONS_FROM_DOMAINS";
106     protected  String PERMISSIONS="PERMISSIONS";
107     protected  String CREATE_PERMISSION="CREATE_PERMISSION";
108     protected  String CREATE_DOMAIN="CREATE_DOMAIN";
109     protected  String CREATE_PRINCIPAL_PERMISSION="CREATE_PRINCIPAL_PERMISSION";
110     protected  String CREATE_PRINCIPAL_DOMAIN="CREATE_PRINCIPAL_DOMAIN";
111     protected  String DOMAINS="DOMAINS";
112     //delete a domain
113     protected  String DELETE_DOMAIN="DELETE_DOMAIN";
114     //delete all the association in jg_principal_domain for a specific principal
115     protected  String DELETE_PRINCIPAL_DOMAIN="DELETE_PRINCIPAL_DOMAIN";
116     //delete the associations in jg_principal_domain for a specific domain
117     protected  String DELETE_DOMAIN_PRINCIPAL="DELETE_DOMAIN_PRINCIPAL";
118 
119     protected String UPDATE_DOMAIN="UPDATE_DOMAIN";
120     protected  String UPDATE_PERMISSION="UPDATE_PERMISSION";
121     protected  String CHANGE_DOMAIN_PERMISSION="CHANGE_DOMAIN_PERMISSION";
122     protected  String DELETE_PRINCIPAL="DELETE_PRINCIPAL";
123     protected  String CREATE_PRINCIPAL="CREATE_PRINCIPAL";
124     protected  String UPDATE_PRINCIPAL="UPDATE_PRINCIPAL";
125     //delete a permission
126     protected  String DELETE_PERMISSION="DELETE_PERMISSION";
127     //delete all the association in jg_principal_domain for a specific principal
128     protected  String DELETE_PRINCIPAL_PERMISSION="DELETE_PRINCIPAL_PERMISSION";
129     //delete the associations in jg_principal_permission for a specific permission
130     protected  String DELETE_PERMISSION_PRINCIPAL="DELETE_PERMISSION_PRINCIPAL";
131     protected  String READ_PERMISSION_ID="READ_PERMISSION_ID";
132     protected  String READ_DOMAIN_ID ="READ_DOMAIN_ID";
133     protected  String READ_PRINCIPAL_ID ="READ_PRINCIPAL_ID";
134 
135     private Properties props;
136 
137     private ConnectionFactory connectionFactory = null;
138 
139     /**
140      * initialize this jdbc AuthorizationManager.
141      * @param options a Map which contains informations to configure the AuthorizationManager implementation.
142      */
143     public JdbcAuthorizationManager(Map options) {
144        
145     	super(options);
146 
147         //initialize database connection factory
148     	connectionFactory = new ConnectionFactory(options);
149         init(options,connectionFactory);
150 
151     }
152     
153      /**
154      * initialize this jdbc AuthorizationManager.
155      * this constructor can be useful if you use one Inversion of Control (IoC) container.
156      * this constructor can be used with Ioc type 3 (injection by constructor).
157      * @param dataSource datasource to use to grab JDBC connections.
158      * @param options a Map which contains informations to configure the AuthorizationManager implementation.
159      */
160     public JdbcAuthorizationManager(DataSource dataSource,Map options) {
161     	super(options);
162         //initialize database connection factory
163     	connectionFactory = new ConnectionFactory(dataSource);
164         init(options,connectionFactory);
165 
166     }
167 
168     private void init(Map options, ConnectionFactory connectionFactory){
169         super.options = options;
170         props = new Properties();
171         
172         domainIds = new HashMap();
173         
174         String applicationName= (String)options.get(PolicyEnforcementPointOptions.APPLICATION_NAME.getLabel());
175         this.setApplicationName(applicationName);
176         
177         Map jdbcMap = new HashMap();
178         
179         String dbPropertiesLocation = (String)options.get(CoreConstants.AUTHORIZATION_DATABASE_FILE_LOCATION);
180         jdbcMap.put(JdbcManagerHelper.DB_PROPERTIES_LOCATION,dbPropertiesLocation);
181         String createRequiredDatabaseEntities = (String)options.get(SecurityConstants.AUTHORIZATION_DATABASE_CREATE_REQUIRED_DATABASE_ENTITIES);
182         jdbcMap.put(JdbcManagerHelper.CREATE_REQUIRED_DATABASE_ENTITIES, createRequiredDatabaseEntities);
183         String importXmlDataKey = SecurityConstants.AUTHORIZATION_DATABASE_IMPORT_XML_DATA;
184         jdbcMap.put(JdbcManagerHelper.IMPORT_XML_DATA_KEY, importXmlDataKey);
185         String importXmlDataValue = (String)options.get(SecurityConstants.AUTHORIZATION_DATABASE_IMPORT_XML_DATA);
186         jdbcMap.put(JdbcManagerHelper.IMP0RT_XML_DATA_VALUE, importXmlDataValue);
187         jdbcMap.put(JdbcManagerHelper.XML_FILE_NAME, "jGuardPrincipalsPermissions.xml");
188     	JdbcManagerHelper.jdbcInit(this,connectionFactory,props,jdbcMap);
189         init();
190     }
191 
192 	
193     /**
194      * initialize Principals and permissions.
195      */
196     private void init() {
197 
198         urlp = initPermissions();
199         principalsSet = initPrincipals();
200         Iterator itPrincipalsSet = principalsSet.iterator();
201 
202         //populate the corresponding Map to the Set
203         while(itPrincipalsSet.hasNext()){
204             RolePrincipal tempPrincipal = (RolePrincipal)itPrincipalsSet.next();
205             principals.put(tempPrincipal.getLocalName(),tempPrincipal);
206         }
207     }
208 
209     /**
210      * return needed initialization parameters.
211      * @return initialization parameters' list
212      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#getInitParameters()
213      */
214     public List getInitParameters() {
215 
216         String[] authorizationParameters = {"authorizationUrl","authorizationLogin",
217                                             "authorizationPassword","authorizationDriver"};
218         return Arrays.asList(authorizationParameters);
219     }
220 
221 
222     /**
223      * initialize principals.
224      * regroup Principals in a Set.
225      * @return principals Set
226      */
227     private Set initPrincipals() {
228 
229         Set ppals = new HashSet();
230         Map principalsMap = new HashMap();
231         PreparedStatement pst;
232         PreparedStatement pst2;
233         PreparedStatement pst3;
234         ResultSet rs;
235         ResultSet rs2;
236         ResultSet rs3;
237        
238         Connection connection = null;
239        try {
240     	   	   connection = connectionFactory.getConnection();
241                pst= connection.prepareStatement(props.getProperty(PRINCIPALS));
242                rs = pst.executeQuery();
243 
244                while(rs.next()){
245                    RolePrincipal  tempJGuardPrincipal = new RolePrincipal();
246                    tempJGuardPrincipal.setName(this.applicationName+"#"+rs.getString(NAME));
247                    String name = rs.getString(NAME);
248 
249                    //domains names owned by this principal
250                    Set domainNames = new HashSet();
251 
252                    //add permissions from principal via domains
253                    pst3 = connection.prepareStatement(props.getProperty(PERMISSIONS_FROM_DOMAINS));
254                    pst3.setString(1,name);
255                    rs3 = pst3.executeQuery();
256 
257                    //fill principal object with the permissions bound to domains owned by the current principal
258                    while(rs3.next()){
259                     String domainName = rs3.getString(DOMAIN_NAME);
260 	                        if(!domainNames.contains(domainName)){
261 		                            domainNames.add(domainName);
262 	                            logger.debug(" add domain "+domainName+" to principal "+tempJGuardPrincipal.getLocalName());
263 		                            JGPermissionCollection domainTemp = (JGPermissionCollection)domains.get(domainName);
264 		                            tempJGuardPrincipal.addDomain(domainTemp);
265 		                        }
266 
267 	                    }
268 
269                    //add permissions not bound with a domain owned by this principal
270                    pst2 = connection.prepareStatement(props.getProperty(PERMISSIONS_FROM_PRINCIPAL));
271                    pst2.setString(1,name);
272                    rs2 = pst2.executeQuery();
273 
274                    //fill principal object with their permissions
275                    while(rs2.next()){
276                     String permissionName = rs2.getString(NAME);
277                     Permission perm;
278 						try {
279 							perm = (Permission)urlp.getPermission(permissionName);
280 	                    tempJGuardPrincipal.addPermission(perm);
281 						} catch (NoSuchPermissionException e) {
282 	                    	logger.warn(" permission "+permissionName+" is not present in the JGPermissionCollection ");
283 	                    }
284                    }
285 
286                    ppals.add(tempJGuardPrincipal);
287                    principalsMap.put(tempJGuardPrincipal.getLocalName(), tempJGuardPrincipal);
288                }
289 
290 
291 
292                rs.close();
293                pst.close();
294 
295                pst = connection.prepareStatement(props.getProperty(PRINCIPALS_HIERARCHY));
296                rs = pst.executeQuery();
297 
298                RolePrincipal ascendantPrincipal = null;
299 
300                while (rs.next()) {
301                    String principalAscendantName = rs.getString(1);
302                    String principalDescendantName = rs.getString(2);
303 
304                    if (ascendantPrincipal == null || !ascendantPrincipal.getLocalName().equals(principalAscendantName)) {
305                        ascendantPrincipal = (RolePrincipal) principalsMap.get(principalAscendantName);
306                    }
307                    
308                    RolePrincipal descendant = (RolePrincipal)principalsMap.get(principalDescendantName);
309                    ascendantPrincipal.getDescendants().add(descendant);
310 
311                    logger.info("Principal " + principalAscendantName + " inherites from principal " + principalDescendantName);
312                }
313 
314                rs.close();
315                pst.close();
316 
317        } catch (SQLException e) {
318 			if (logger.isDebugEnabled()) {
319 				logger.debug("initPrincipals in AuthorizationManager SQL ERROR "+ e.getMessage());
320 			}
321        }finally{
322            try {
323                connection.close();
324            } catch (SQLException e1) {
325 				logger.error( "listPrincipals()", e1);
326            }
327        }
328 
329         return ppals;
330     }
331 
332     /**
333      * initialize permissions.
334      * regroup permissions in a JGPermissionCollection.
335      * @return JGPermissionCollection
336      */
337     private JGPermissionCollection initPermissions() {
338 
339         JGPermissionCollection urlPc= new JGPositivePermissionCollection();
340         Permission  tempPermission = null;
341         String tempPermissionName="";
342         Connection connection2 = null;
343         try {
344                 //get the domains (although the empty domains)
345         		connection2 = connectionFactory.getConnection();
346                 PreparedStatement pst2 = connection2.prepareStatement(props.getProperty(DOMAINS));
347                 ResultSet rs2 = pst2.executeQuery();
348                 while(rs2.next()){
349                     String domainName = rs2.getString(NAME);
350                     Long domainId = new Long((rs2.getInt("id")));
351                     JGPermissionCollection domain = new Domain(domainName);
352                     domainsSet.add(domain);
353                     domains.put(domainName,domain);
354                     domainIds.put(domainName,domainId);
355                     Connection connection = null;
356                     try{
357 			                    connection = connectionFactory.getConnection();
358 			                    PreparedStatement pst = connection.prepareStatement(props.getProperty(PERMISSIONS));
359 			                    pst.setLong(1,domainId.longValue());
360 			                    ResultSet rs = pst.executeQuery();
361 			
362 			                   //get the corresponding permissions
363 			                    while(rs.next()){
364 			
365 			                        //new permission
366 			                        if(rs.getString(NAME).equals(tempPermissionName)==false){
367 			                            if(tempPermission!=null){
368 			                                urlPc.add(tempPermission);
369 			                            }
370 			                            String clazz = rs.getString(("class"));
371 			            		        String actions = rs.getString(("actions"));
372 			                            try {
373 											tempPermission = PermissionUtils.getPermission(clazz,rs.getString(NAME),actions);
374 										} catch (ClassNotFoundException e) {
375 											logger.warn(e.getMessage());
376 											continue;
377 										}
378 			                            permissions.put(tempPermission.getName(),tempPermission);
379 			                            permissionsSet.add(tempPermission);
380 			                            //add the Permission to the domain
381 			                            ((JGPermissionCollection)domains.get(domainName)).add(tempPermission);
382 			
383 			                        }
384 			                    }
385 			
386 			                    //add the last permission
387 			                    if(tempPermission!=null){
388 			                        urlPc.add(tempPermission);
389 			                    }
390                     }finally{
391                     	connection.close();
392                     }
393 
394                 }
395 
396 
397        } catch (SQLException e) {
398 
399 			if (logger.isDebugEnabled()) {
400 				logger.debug("listPermissions() - initializePermissions in AuthorizationManager SQL ERROR "+ e.getMessage());
401 			}
402 
403        }finally{
404     	   try {
405 			connection2.close();
406 		} catch (SQLException e) {
407 			throw new RuntimeException(e);
408 		}
409        }
410 
411         return urlPc;
412     }
413 
414     
415 
416 	public void createRequiredDatabaseEntities(Properties properties,ConnectionFactory connectionFactory) {
417 
418         //we create tables
419         List tablesNames = new ArrayList();
420         tablesNames.add("JG_DOMAIN");
421         tablesNames.add("JG_APP_PRINCIPAL");
422         tablesNames.add("JG_PERMISSION");
423         tablesNames.add("JG_PRINCIPAL_PERMISSION");
424         tablesNames.add("JG_PRINCIPAL_DOMAIN");
425         tablesNames.add("JG_PRINCIPAL_HIERARCHY");
426 
427         List sequencesNames = new ArrayList();
428         sequencesNames.add("JG_APP_PRINCIPAL_SEQ");
429         sequencesNames.add("JG_PERMISSION_SEQ");
430         sequencesNames.add("JG_DOMAIN_SEQ");
431 
432         List foreignkeysNames = new ArrayList();
433 		foreignkeysNames.add("FK_PERMISSION_PRINCIPAL");
434 		foreignkeysNames.add("FK_PRINCIPAL_PERMISSION");
435 		foreignkeysNames.add("FK_DOMAIN_PRINCIPAL");
436 		foreignkeysNames.add("FK_PRINCIPAL_DOMAIN");
437 		foreignkeysNames.add("FK_PERMISSION_DOMAIN");
438 		foreignkeysNames.add("FK_PRINCIPAL_HIERARCHY_PRINCIPAL");
439 		foreignkeysNames.add("FK_PRINCIPAL_HIERARCHY_PRINCIPAL2");
440 
441         //initialise database
442         DatabaseUtils.createRequiredDatabaseEntities(properties,connectionFactory,sequencesNames,tablesNames,foreignkeysNames);
443 
444 	}
445 
446 
447 
448 	/**
449      * create an URLPermission int the corresponding backend.
450      * @param permission URLPermission
451      * @param domainName the domain the permission belongs to
452      * @throws AuthorizationException
453      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#createPermission(java.security.Permission, java.lang.String)
454      */
455     public void createPermission(Permission permission,String domainName) throws AuthorizationException {
456 
457 
458     	Connection conn = null;
459         PreparedStatement pst = null;
460         //name,uri,description,scheme,domain_id
461         try {
462         	conn = connectionFactory.getConnection();
463             pst = conn.prepareStatement(props.getProperty(CREATE_PERMISSION));
464 
465             pst.setString(1,permission.getName());
466             pst.setString(2,permission.getActions());
467             pst.setString(3,permission.getClass().getName());
468             Long domainId =(Long)domainIds.get(domainName);
469             pst.setLong(4,domainId.longValue());
470             pst.executeUpdate();
471             
472             //add the permission to the permissionCollection
473             urlp.add(permission);
474 				if (logger.isDebugEnabled()) {
475 					logger.debug("createPermission() - " + permission
476 							+ " added!");
477 					logger.debug("createPermission() - permissions: " + urlp);
478 				}
479             //add the permission to its Domain
480             JGPermissionCollection domain = (JGPermissionCollection)domains.get(domainName);
481             domain.add(permission);
482             permissions.put(permission.getName(),permission);
483             permissionsSet.add(permission);
484 
485             /*
486              * udpate the permission list from all principals that have relationship with this
487              * domain. Is this is not done the change will not affect the users principals in this webapp
488              * while the application is not reloaded.
489              */
490             this.updatePrincipals(permission);
491 
492 
493         } catch (SQLException e) {
494 			logger.error( "createPermission(URLPermission, String)", e);
495         }finally{
496             try {
497             	pst.close();
498                 conn.close();
499             } catch (SQLException e1) {
500 				logger.error( "createPermission(URLPermission, String)", e1);
501             }
502         }
503 
504 
505     }
506 
507 
508 
509     /**
510      * update the URLPermission.
511      * @param oldPermissionName
512      * @param perm
513      * @param newDomainName
514      * @throws AuthorizationException
515      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#updatePermission(java.lang.String, java.security.Permission, java.lang.String)
516      */
517     public void updatePermission(String oldPermissionName, Permission perm, String newDomainName) throws AuthorizationException {
518 
519         
520         PreparedStatement pst;
521         Connection conn = null;
522 
523             try {
524             	conn = connectionFactory.getConnection();
525             	conn.setAutoCommit(false);
526 				pst = conn.prepareStatement(props.getProperty(UPDATE_PERMISSION));
527 
528 			// name
529             pst.setString(1,perm.getName());
530             //actions
531             pst.setString(2,perm.getActions());
532             //class
533             pst.setString(3,perm.getClass().getName());
534             //domainId
535             pst.setLong(4,((Long)domainIds.get(newDomainName)).longValue());
536             //old Permission Name
537             pst.setString(5,oldPermissionName);
538             pst.executeUpdate();
539 
540             JGPermissionCollection newDomain = (JGPermissionCollection)domains.get(newDomainName);
541 
542 	            // we are looking for the old domain which contains the updated permission
543             Iterator itDomains = domainsSet.iterator();
544             Permission oldPermission = (Permission) permissions.get(oldPermissionName);
545             while(itDomains.hasNext()){
546                 JGPermissionCollection domain = (JGPermissionCollection)itDomains.next();
547 
548                 if(domain.containsPermission(oldPermission)){
549                     domain.removePermission(oldPermission);
550                     //only one domain can contain a permission
551                     //so, when we found the 'old' domain which contain the searched permission
552                     //we break the loop
553                     break;
554                 }
555             }
556 
557             //update the "in memory" permission
558 			urlp.removePermission(oldPermission);
559             urlp.add(perm);
560             permissions.remove(oldPermissionName);
561             permissions.put(perm.getName(),perm);
562             Iterator itPermissionsSet = permissionsSet.iterator();
563             while(itPermissionsSet.hasNext()){
564             	Permission tempPerm = (Permission)itPermissionsSet.next();
565             	if(tempPerm.getName().equals(oldPermissionName)){
566             		permissionsSet.remove(tempPerm);
567             		break;
568             	}
569             }
570             permissionsSet.add(perm);
571             //add the updated permission to the new domain
572             newDomain.add(perm);
573 
574             //update principals
575             this.updatePrincipals(perm);
576 	            //we only commit SQL changes if SQL and memory changes are synchronized:
577 	            //i.e no exception has been raised on the memory scope
578 	            conn.commit();
579             } catch (SQLException e) {
580                 throw new AuthorizationException(e);
581             }finally{
582                 try {
583                     conn.close();
584                 } catch (SQLException e1) {
585     				logger.error( "updatePermission(String, URLPermission, String)",	e1);
586                 }
587             }
588     }
589 
590 
591 
592     /**
593      * delete the permission.
594      * @param permissionName
595      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#deletePermission(java.lang.String)
596      */
597     public void deletePermission(String permissionName) throws AuthorizationException {
598 
599        
600         PreparedStatement pst;
601         PreparedStatement pst2;
602         Connection conn = null;
603         try {
604         	conn = connectionFactory.getConnection();
605         	conn.setAutoCommit(false);
606             //delete associations in jg_principal_permisison
607             //before suppress the corresponding permission
608             pst = conn.prepareStatement(props.getProperty(DELETE_PERMISSION_PRINCIPAL));
609             pst.setString(1,permissionName);
610             logger.debug(props.getProperty(DELETE_PERMISSION_PRINCIPAL));
611             logger.debug("permissionName="+permissionName);
612             pst.executeUpdate();
613             pst.close();
614 
615             pst2 = conn.prepareStatement(props.getProperty(DELETE_PERMISSION));
616             pst2.setString(1,permissionName);
617             pst2.executeUpdate();
618 
619             this.removePermissionFromPrincipals(permissionName);
620             Permission permission = null;
621 			try {
622 				permission = (Permission)urlp.getPermission(permissionName);
623 			} catch (NoSuchPermissionException e) {
624 				throw new AuthorizationException(e);
625 			}
626             Domain domain = getDomain(permission);
627             domain.removePermission(permission);
628             permissions.remove(permission.getName());
629             permissionsSet.remove(permission);
630             urlp.removePermission(permission);
631             //update the principals that have this permission by the domain that own this permission
632             this.updatePrincipals(domain);
633 
634             Iterator urlpIt = urlp.getPermissions().iterator();
635             while(urlpIt.hasNext()){
636                 Permission tempPermission = (Permission)urlpIt.next();
637                 if(tempPermission.getName().equals(permissionName)){
638                     //remove the permission in the Set
639                     getDomain(tempPermission).removePermission(tempPermission);
640                     //remove the permission in the permissionCollection
641                     urlpIt.remove();
642                     break;
643                 }
644 
645             }
646             conn.commit();
647         } catch (SQLException e) {
648 			logger.error( "deletePermission(String)", e);
649         }finally{
650             try {
651                 conn.close();
652             } catch (SQLException e1) {
653 				logger.error( "deletePermission(String)", e1);
654             }
655         }
656 
657     }
658 
659 
660     /**
661      * create a new domain.
662      * @param domainName
663      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#createDomain(java.lang.String)
664      */
665     public void createDomain(String  domainName) throws AuthorizationException {
666         
667         PreparedStatement pst;
668         PreparedStatement pst2;
669         ResultSet rs2;
670         Connection conn = null;
671         try {
672         	conn = connectionFactory.getConnection();
673             pst = conn.prepareStatement(props.getProperty(CREATE_DOMAIN));
674             pst.setString(1,domainName);
675             pst.executeUpdate();
676             JGPermissionCollection newDomain = new Domain(domainName);
677             pst2 = conn.prepareStatement(props.getProperty(READ_DOMAIN_ID));
678             pst2.setString(1,domainName);
679             rs2 = pst2.executeQuery();
680             conn.commit();
681             //there must be only one result
682             rs2.next();
683             domains.put(domainName,newDomain);
684             domainsSet.add(newDomain);
685             domainIds.put(domainName,new Long(rs2.getLong("id")));
686 
687         } catch (SQLException e) {
688 			logger.error( "createDomain(String)", e);
689         }finally{
690             try {
691                 conn.close();
692             } catch (SQLException e1) {
693 				logger.error( "createDomain(String)", e1);
694             }
695         }
696 
697     }
698 
699     /**
700      * change the domain name.
701      * @param newDomainName
702      * @param oldDomainName
703      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#updateDomain(java.lang.String, java.lang.String)
704      */
705     public void updateDomain(String newDomainName,String oldDomainName) throws AuthorizationException {
706         
707         PreparedStatement pst;
708         PreparedStatement pst2;
709         ResultSet rs2;
710         Connection conn = null;
711         try {
712         	conn = connectionFactory.getConnection();
713             pst = conn.prepareStatement(props.getProperty(UPDATE_DOMAIN));
714             pst.setString(1,newDomainName);
715             pst.setString(2,oldDomainName);
716             pst.executeUpdate();
717             //if the database update is right, we can update the in memory reference
718             Domain updatedDomain = ((Domain)domains.get(oldDomainName));
719             /*
720              * 2005-05-18 Vinícius: Order of methods call changed to fix the
721              * bug 1205011
722              *
723              * before update the domain name we must remove the domain from
724              * domainsSet set because this operations depends of equals method
725              * from Domain that compare the domains names, otherwise the
726              * remove method from the Set final type will not be able to find
727              * the right instance with the equals method and will not remove
728              * the Domain from domainsSet. The wrong call sequence cause the
729              * domain to be duplicated in the set (in memory domain list).
730              *
731              * I am note sure about "why" the old domain instance on the
732              * domainsSet still with the old name because the domainsSet and
733              * domains map are supposed to share the same instance of Domain.
734              * So the change on domain instance from the domains map must to
735              * means one change on domain instance from domainsSet that share the
736              * same instance!
737              *
738              * I conclude that in some place of the code that load domains
739              * and permissions, more than one Domain instance are created
740              * to represents the same domain.
741              */
742             domainsSet.remove(domains.get(oldDomainName));
743             //now we can safe update the domain name
744             updatedDomain.setName(newDomainName);
745 
746             domains.remove(oldDomainName);
747             //I think that this call was forgotten
748             domainIds.remove(oldDomainName);
749 
750             domains.put(newDomainName,updatedDomain);
751 
752             pst2 = conn.prepareStatement(props.getProperty(READ_DOMAIN_ID));
753             pst2.setString(1,newDomainName);
754             rs2 = pst2.executeQuery();
755             //there must be only one result
756             rs2.next();
757             domainIds.put(newDomainName,new Long(rs2.getLong("id")));
758             domainsSet.add(domains.get(updatedDomain.getName()));
759 
760             //update principals relationship with this domain
761             this.updatePrincipals(updatedDomain, oldDomainName);
762         } catch (SQLException e) {
763 			logger.error( "updateDomain(String, String)", e);
764         }finally{
765             try {
766                 conn.close();
767             } catch (SQLException e1) {
768 				logger.error( "updateDomain(String, String)", e1);
769             }
770         }
771 
772     }
773 
774 
775     /**
776      * delete a domain.
777      * a domain can be deleted only if no permissions are bound to it.
778      * @param domainName
779      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#deleteDomain(java.lang.String)
780      */
781     public void deleteDomain(String domainName) throws AuthorizationException {
782         if(domains.get(domainName)== null){
783             throw new AuthorizationException(" this domain does not exists ");
784         }else if(((JGPermissionCollection)domains.get(domainName)).getPermissions().isEmpty()==false){
785             throw new AuthorizationException(" there are "+
786                     ((JGPermissionCollection)domains.get(domainName)).getPermissions().size()+" permissions bound to this domain ");
787         }else{
788 
789             
790             PreparedStatement pst;
791             PreparedStatement pst2;
792             Connection conn = null;
793             try {
794             	conn = connectionFactory.getConnection();
795                 //delete associations between principals and this domain
796                 pst2 = conn.prepareStatement(props.getProperty(DELETE_DOMAIN_PRINCIPAL));
797                 pst2.setString(1,domainName);
798                 pst2.executeUpdate();
799 
800                 pst = conn.prepareStatement(props.getProperty(DELETE_DOMAIN));
801                 pst.setString(1,domainName);
802                 pst.executeUpdate();
803                 domainIds.remove(((Domain)domains.get(domainName)).getName());
804                 domainsSet.remove(domains.get(domainName));
805                 //if the database remove is right, we can remove the in memory reference
806                 domains.remove(domainName);
807 
808                 //update principals that have relationship with this domain
809                 super.removeDomainFromPrincipals(domainName);
810             } catch (SQLException e) {
811 				logger.error( "deleteDomain(String)", e);
812             }finally{
813                 try {
814                     conn.close();
815                 } catch (SQLException e1) {
816 					logger.error( "deleteDomain(String)", e1);
817                 }
818             }
819         }
820     }
821 
822 
823     /**
824      * update the application Principal (role).
825      * @param oldPrincipalName name of the principal to be replaced
826      * @param principal the new principal updated
827      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#updatePrincipal(net.sf.jguard.core.principals.RolePrincipal)
828      * @throws AuthorizationException
829      */
830     public void updatePrincipal(String oldPrincipalName, Principal principal) throws AuthorizationException {
831         
832         PreparedStatement pst;
833         PreparedStatement pst2;
834         PreparedStatement pst3;
835         Connection conn = null;
836 
837         try {
838         	conn = connectionFactory.getConnection();
839             //delete old assocations between principal and permissions
840             pst2 = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL_PERMISSION));
841             pst2.setString(1,oldPrincipalName);
842             logger.debug(props.getProperty(DELETE_PRINCIPAL_PERMISSION));
843             logger.debug(oldPrincipalName);
844             pst2.executeUpdate();
845 
846             //delete old assocations between principal and domains
847             pst3 = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL_DOMAIN));
848             pst3.setString(1,oldPrincipalName);
849             pst3.executeUpdate();
850 
851             //update the principal name
852             pst = conn.prepareStatement(props.getProperty(UPDATE_PRINCIPAL));
853             pst.setString(1,getLocalName(principal));
854             pst.setString(2,oldPrincipalName);
855             pst.executeUpdate();
856         } catch (SQLException e) {
857 			logger.error( "updatePrincipal(String, RolePrincipal)", e);
858             throw new AuthorizationException(e);
859         }finally{
860             try {
861                 conn.close();
862             } catch (SQLException e1) {
863                throw new AuthorizationException(" connection cannot be closed ",e1);
864             }
865         }
866             if(principal.getClass().equals(RolePrincipal.class)){
867              
868              boolean result= addDomainsAndPermissions((RolePrincipal)principal);
869              if(!result){
870                  //we dont update in memory principal because update fails
871                  return;
872              }
873             }
874             //if the database update is right, we can update the in memory reference
875             Principal oldPal = (Principal)principals.remove(oldPrincipalName);
876             principalsSet.remove(oldPal);
877             principals.put(getLocalName(principal),principal);
878             principalsSet.add(principal);
879 
880 
881     }
882 
883     /**
884      * @param principal
885      * @return boolean true if update has been done and false otherwise.
886      * @throws AuthorizationException
887      */
888     private boolean addDomainsAndPermissions(RolePrincipal principal) throws AuthorizationException {
889 
890         
891         PreparedStatement pst4;
892         PreparedStatement pst5;
893         PreparedStatement pst6;
894         PreparedStatement pst7;
895         PreparedStatement pst8;
896         ResultSet rs5;
897         ResultSet rs6;
898         ResultSet rs7;
899         Connection conn = null;
900         try {
901         	conn = connectionFactory.getConnection();
902             //retrieve the principal id
903             pst6 = conn.prepareStatement(props.getProperty(READ_PRINCIPAL_ID));
904 
905         pst6.setString(1,getLocalName(principal));
906         rs6 = pst6.executeQuery();
907         long idPrincipal;
908         if(rs6.next()){
909          idPrincipal = rs6.getLong(1);
910         }else{
911             //throw new AuthorizationException(" the principal "+principal.getLocalName()+" is not present in the database : it hasn't got any id ");
912             return false;
913         }
914         //add new assocations between  principal and permissions
915         Set orphanedPermissions  = principal.getOrphanedPermissions();
916         Iterator itOrphanedPermissions = orphanedPermissions.iterator();
917         long idPermission;
918 
919         while(itOrphanedPermissions.hasNext()){
920          Permission perm = (Permission)itOrphanedPermissions.next();
921          pst5 = conn.prepareStatement(props.getProperty(READ_PERMISSION_ID));
922          pst5.setString(1,perm.getName());
923          rs5 = pst5.executeQuery();
924          rs5.next();
925          idPermission = rs5.getLong(1);
926 
927          pst8 = conn.prepareStatement(props.getProperty(CREATE_PRINCIPAL_PERMISSION));
928          pst8.setLong(1,idPrincipal);
929          pst8.setLong(2,idPermission);
930          pst8.executeUpdate();
931         }
932 
933         //add new assocations between  principal and domains
934         Set  doms  = principal.getDomains();
935         Iterator itDomains = doms.iterator();
936         long idDomain;
937         while(itDomains.hasNext()){
938             Domain dom = (Domain)itDomains.next();
939             pst7 = conn.prepareStatement(props.getProperty(READ_DOMAIN_ID));
940             pst7.setString(1,dom.getName());
941             rs7 = pst7.executeQuery();
942             rs7.next();
943             idDomain = rs7.getLong(1);
944 
945             pst4 = conn.prepareStatement(props.getProperty(CREATE_PRINCIPAL_DOMAIN));
946             pst4.setLong(1,idPrincipal);
947             pst4.setLong(2,idDomain);
948             pst4.executeUpdate();
949         }
950           return true;
951         } catch (SQLException e) {
952             throw new AuthorizationException(" an SQLException  has been raised in the addDomainsAndPermissions method ",e);
953         }finally{
954             try {
955                 conn.close();
956             } catch (SQLException e1) {
957                throw new AuthorizationException(" connection cannot be closed ",e1);
958             }
959         }
960     }
961 
962     /**
963      * delete principal.
964      * @param principal
965      * @see net.sf.jguard.ext.authorization.manager.AuthorizationManager#deletePrincipal(java.security.Principal)
966      */
967     public void deletePrincipal(Principal principal) throws AuthorizationException {
968         
969         PreparedStatement pst;
970         PreparedStatement pst2;
971         PreparedStatement pst3;
972         Connection conn = null;
973         try {
974             conn = connectionFactory.getConnection();
975             pst = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL_PERMISSION));
976             pst.setString(1,getLocalName(principal));
977             pst.executeUpdate();
978 
979             pst3 = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL_DOMAIN));
980             pst3.setString(1,getLocalName(principal));
981             pst3.executeUpdate();
982 
983             pst2 = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL));
984             pst2.setString(1,getLocalName(principal));
985             pst2.executeUpdate();
986             principals.remove(getLocalName(principal));
987             RolePrincipal ppal = new RolePrincipal();
988             ppal.setLocalName(getLocalName(principal));
989             ppal.setApplicationName(applicationName);
990             principalsSet.remove(ppal);
991 
992         } catch (SQLException e) {
993 			logger.error( "deletePrincipal(String)", e);
994         }finally{
995             try {
996                 conn.close();
997             } catch (SQLException e1) {
998 				logger.error( "deletePrincipal(String)", e1);
999             }
1000         }
1001 
1002     }
1003 
1004 
1005     /**
1006      * update the permission to bound it to another Domain.
1007      * @param permissionName name of the permission to update
1008      * @param newDomainName name of the Domain to bound this permission
1009      * @throws AuthorizationException
1010      */
1011     public void changeDomainPermission(String permissionName, String newDomainName) throws AuthorizationException{
1012        
1013         PreparedStatement pst;
1014         Connection conn = null;
1015         try {
1016         	conn = connectionFactory.getConnection();
1017         	conn.setAutoCommit(false);
1018             pst = conn.prepareStatement(props.getProperty(CHANGE_DOMAIN_PERMISSION));
1019             pst.setString(1,newDomainName);
1020             pst.setString(2,permissionName);
1021             pst.executeUpdate();
1022             Permission perm;
1023 			try {
1024 				perm = (Permission)urlp.getPermission(permissionName);
1025 			} catch (NoSuchPermissionException e) {
1026 				throw new AuthorizationException(e);
1027 			}
1028             JGPermissionCollection oldDomain =getDomain(perm);
1029             oldDomain.removePermission(perm);
1030             JGPermissionCollection newDomain =(JGPermissionCollection)domains.get(newDomainName);
1031             newDomain.add(perm);
1032             conn.commit();
1033         } catch (SQLException e) {
1034 			logger.error( "changeDomainPermission(String, String)", e);
1035         }finally{
1036             try {
1037                 conn.close();
1038             } catch (SQLException e1) {
1039 				logger.error( "changeDomainPermission(String, String)", e1);
1040             }
1041         }
1042 
1043     }
1044 
1045     public void createPrincipal(Principal principal) throws AuthorizationException{
1046         
1047         PreparedStatement pst;
1048         Connection conn = null;
1049         //create the principal
1050         try {
1051         	conn = connectionFactory.getConnection();
1052             pst = conn.prepareStatement(props.getProperty(CREATE_PRINCIPAL));
1053 			pst.setString(1,getLocalName(principal));
1054             int result = pst.executeUpdate();
1055             if(result==0){
1056             	throw new AuthorizationException("principal "+getLocalName(principal)+" has not been created");
1057             }
1058         } catch (SQLException e) {
1059 			logger.error( "createPrincipal(RolePrincipal)", e);
1060             throw new AuthorizationException(e);
1061         }finally{
1062             try {
1063                 conn.close();
1064             } catch (SQLException e1) {
1065 				logger.error( "createPrincipal(RolePrincipal)", e1);
1066                 throw new AuthorizationException(e1);
1067             }
1068         }
1069         if(principal.getClass().equals(RolePrincipal.class)){
1070             addDomainsAndPermissions((RolePrincipal)principal);
1071         }
1072 			principals.put(getLocalName(principal),principal);	
1073         
1074         principalsSet.add(principal);
1075 
1076     }
1077 
1078     /**
1079      * This commands establishes a new immediate inheritance relationship
1080      * between the existing principals principalAsc and the principalDesc.
1081      * The command is valid if and only if the principal principalAsc is not an immediate
1082      * ascendant of principalDesc, and descendant does
1083      * not properly inherit principalAsc principal(in order to avoid cycle creation).
1084      *
1085      * @param principalAscName  the principal that will inherite.
1086      * @param principalDescName the principal that will be inherited.
1087      * @throws AuthorizationException if the inheritance already exists or create a cycle.
1088      */
1089     public void addInheritance(String principalAscName, String principalDescName) throws AuthorizationException {
1090         //getting the principals
1091         RolePrincipal principalAsc = (RolePrincipal) principals.get(principalAscName);
1092         RolePrincipal principalDesc = (RolePrincipal) principals.get(principalDescName);
1093 
1094         if (principalAsc == null) {
1095             logger.error("Principal " + principalAscName + " not found!");
1096             throw new AuthorizationException("Principal " + principalAscName + " not found!");
1097         }
1098 
1099         if (principalDesc == null) {
1100             logger.error("Principal " + principalDescName + " not found!");
1101             throw new AuthorizationException("Principal " + principalDescName + " not found!");
1102         }
1103 
1104         //check if the principalAsc is immediate ascendant of principalDesc
1105         for (Iterator it = principalAsc.getDescendants().iterator(); it.hasNext(); ) {
1106             if (principalDesc.equals(it.next())) {
1107                 logger.warn("Principal " + principalAscName + " is immediate ascendant of Principal " + principalDescName + "!");
1108             }
1109         }
1110 
1111         //check if principalDesc inherit principalAsc
1112         //use a stack instead of a recursive method
1113         Stack principalsToCheck = new Stack();
1114         //used to check first all principals from one level before check the next level
1115         Stack principalsFromNextLevel = new Stack();
1116         principalsToCheck.addAll(principalDesc.getDescendants());
1117 
1118         while (!principalsToCheck.isEmpty()) {
1119             RolePrincipal principal = (RolePrincipal) principalsToCheck.pop();
1120             if (principalAsc.equals(principal)) {
1121                 logger.error("Principal " + principalAscName + " cannot inherit Principal "
1122                         + principalDescName + " because " + principalDescName + " inherit "
1123                         + principalAscName);
1124                 throw new AuthorizationException("Principal " + principalAscName + " cannot inherit Principal "
1125                         + principalDescName + " because " + principalDescName + " inherit "
1126                         + principalAscName);
1127             }
1128 
1129             principalsFromNextLevel.addAll(principal.getDescendants());
1130 
1131             //is time to go to next level
1132             if (principalsToCheck.isEmpty()) {
1133                 principalsToCheck.addAll(principalsFromNextLevel);
1134 
1135                 //clear the second level stack
1136                 principalsFromNextLevel.clear();
1137             }
1138         }
1139 
1140         
1141         PreparedStatement pst;
1142         Connection conn = null;
1143         try {
1144         	conn = connectionFactory.getConnection();
1145             //get principalAsc id
1146             pst = conn.prepareStatement(props.getProperty(READ_PRINCIPAL_ID));
1147             pst.setString(1, principalAscName);
1148             ResultSet rs = pst.executeQuery();
1149             rs.next();
1150             int principalAscId = rs.getInt(1);
1151             rs.close();
1152 
1153             //get principalDesc id
1154             pst.setString(1, principalDescName);
1155             rs = pst.executeQuery();
1156             rs.next();
1157             int principalDescId = rs.getInt(1);
1158             rs.close();
1159             pst.close();
1160 
1161             //update the backend
1162             pst = conn.prepareStatement(props.getProperty(CREATE_PRINCIPAL_INHERITANCE));
1163             pst.setInt(1, principalAscId);
1164             pst.setInt(2, principalDescId);
1165             pst.executeUpdate();
1166             pst.close();
1167 
1168             //update in-memory principal
1169             principalAsc.getDescendants().add(principalDesc);
1170 
1171         } catch (SQLException e) {
1172             logger.error( "addInheritance(principalAscName, principalDescName)", e);
1173         } finally {
1174             try {
1175                 conn.close();
1176             } catch (SQLException e1) {
1177                 logger.error( "addInheritance(principalAscName, principalDescName)", e1);
1178             }
1179         }
1180 
1181 
1182     }
1183 
1184     /**
1185      * Delete the inheritance beteween two existings principals.
1186      * @param principalAscName
1187      * @param principalDescName
1188      */
1189     public void deleteInheritance(String principalAscName, String principalDescName) throws AuthorizationException {
1190         
1191         PreparedStatement pst;
1192         Connection conn = null;
1193         try {
1194         	conn = connectionFactory.getConnection();
1195             //get principalAsc id
1196             pst = conn.prepareStatement(props.getProperty(READ_PRINCIPAL_ID));
1197             pst.setString(1, principalAscName);
1198             ResultSet rs = pst.executeQuery();
1199             rs.next();
1200             int principalAscId = rs.getInt(1);
1201             rs.close();
1202 
1203             //get principalDesc id
1204             pst.setString(1, principalDescName);
1205             rs = pst.executeQuery();
1206             rs.next();
1207             int principalDescId = rs.getInt(1);
1208             rs.close();
1209             pst.close();
1210 
1211             //delete the principal inheritance
1212             pst = conn.prepareStatement(props.getProperty(DELETE_PRINCIPAL_INHERITANCE));
1213             pst.setInt(1, principalAscId);
1214             pst.setInt(2, principalDescId);
1215             pst.executeUpdate();
1216 
1217             pst.close();
1218 
1219             RolePrincipal principalAsc = (RolePrincipal) principals.get(principalAscName);
1220             principalAsc.getDescendants().remove(principals.get(principalDescName));
1221 
1222             logger.info("Inheritance beteween principal " + principalAscName + " and " + principalDescName + " was been deleted.");
1223         } catch (SQLException e) {
1224             logger.error( "assemblyPrincipalHierarchy(RolePrincipal)", e);
1225         }finally{
1226             try {
1227                 conn.close();
1228             } catch (SQLException e1) {
1229                 logger.error( "assemblyPrincipalHierarchy(RolePrincipal)", e1);
1230             }
1231         }
1232     }
1233 
1234 
1235     /**
1236      * import required datas from XML datastore.
1237      */
1238     public void insertRequiredData(String xmlFileLocation){
1239     	
1240     	Map options = new HashMap();
1241         options.put(CoreConstants.AUTHORIZATION_XML_FILE_LOCATION,xmlFileLocation);
1242         options.put(PolicyEnforcementPointOptions.APPLICATION_NAME.getLabel(),this.applicationName);
1243     	
1244 
1245     	try {
1246                 AuthorizationManager authManager = new XmlAuthorizationManager(options);
1247                 importAuthorizationManager(authManager);
1248 	} catch (AuthorizationException e) {
1249 		logger.error(" error importing AuthorizationManager with options "+options);
1250                 logger.warn(e.getMessage());
1251 	}
1252 
1253     }
1254 
1255 	public boolean isEmpty() {
1256         List selectQueries = new ArrayList();
1257         selectQueries.add("PRINCIPALS");
1258         selectQueries.add("ALL_PERMISSIONS");
1259         selectQueries.add("DOMAINS");
1260         return DatabaseUtils.isEmpty(this.props,connectionFactory,selectQueries);
1261 
1262 	}
1263 
1264     public void refresh() {
1265         init();
1266     }
1267 
1268 
1269 }