⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localuserdatasourcesessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            	}else{            		BaseUserDataSource userdatasource = next.getUserDataSource();            		if(userdatasource.getApplicableCAs().contains(new Integer(BaseUserDataSource.ANYCA))){            			if(includeAnyCA){            				returnval.add(next.getId());            			}            		}else{            			if(authorizedcas.containsAll(userdatasource.getApplicableCAs())){            				returnval.add(next.getId());            			}            		}            	}            }        }  catch (FinderException fe) {			String msg = intres.getLocalizedMessage("userdatasource.errorfindingall");            	        	log.error(msg, fe);        }        return returnval;    } // getAuthorizedUserDataSourceIds    /**     * Method creating a hashmap mapping user data source id (Integer) to user data source name (String).     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public HashMap getUserDataSourceIdToNameMap(Admin admin) {        HashMap returnval = new HashMap();        Collection result = null;        try {            result = userdatasourcehome.findAll();            Iterator i = result.iterator();            while (i.hasNext()) {            	UserDataSourceDataLocal next = (UserDataSourceDataLocal) i.next();                returnval.put(next.getId(), next.getName());            }        } catch (FinderException e) {        }        return returnval;    } // getUserDataSourceIdToNameMap    /**     * Retrives a named user data source.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public BaseUserDataSource getUserDataSource(Admin admin, String name) {        BaseUserDataSource returnval = null;        try {        	BaseUserDataSource result = (userdatasourcehome.findByName(name)).getUserDataSource();            if(isAuthorizedToEditUserDataSource(admin,result)){            	returnval = result;            }else{    			String msg = intres.getLocalizedMessage("userdatasource.errornotauth", name);            	        		getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_RA,new Date(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,msg);            }        } catch (FinderException e) {            // return null if we cant find it        }        return returnval;    } //  getUserDataSource    /**     * Finds a user data source by id.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public BaseUserDataSource getUserDataSource(Admin admin, int id) {        BaseUserDataSource returnval = null;        try {                    	BaseUserDataSource result = (userdatasourcehome.findByPrimaryKey(new Integer(id))).getUserDataSource();            if(isAuthorizedToEditUserDataSource(admin,result)){            	returnval = result;            }else{    			String msg = intres.getLocalizedMessage("userdatasource.errornotauth", new Integer(id));            	        		getLogSession().log(admin, admin.getCaId(),LogEntry.MODULE_RA,new Date(),null,null,LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,msg);            }        } catch (FinderException e) {            // return null if we cant find it        }        return returnval;    } // getUserDataSource    /**     * Help method used by user data source proxys to indicate if it is time to     * update it's data.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public int getUserDataSourceUpdateCount(Admin admin, int userdatasourceid) {        int returnval = 0;        try {            returnval = (userdatasourcehome.findByPrimaryKey(new Integer(userdatasourceid))).getUpdateCounter();        } catch (FinderException e) {        }        return returnval;    }    /**     * Returns a user data source id, given it's user data source name     *     * @return the id or 0 if the user data source cannot be found.     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public int getUserDataSourceId(Admin admin, String name) {        int returnval = 0;        try {            Integer id = (userdatasourcehome.findByName(name)).getId();            returnval = id.intValue();        } catch (FinderException e) {        }        return returnval;    } // getUserDataSourceId    /**     * Returns a user data source name given its id.     *     * @return the name or null if id doesnt exists     * @throws EJBException if a communication or other error occurs.     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public String getUserDataSourceName(Admin admin, int id) {        debug(">getUserDataSourceName(id: " + id + ")");        String returnval = null;        UserDataSourceDataLocal htp = null;        try {            htp = userdatasourcehome.findByPrimaryKey(new Integer(id));            if (htp != null) {                returnval = htp.getName();            }        } catch (FinderException e) {        }        debug("<getUserDataSourceName()");        return returnval;    } // getUserDataSourceName        /**     * Method to check if an admin is authorized to fetch user data from userdata source     * The following checks are performed.     *      * 1. If the admin is an administrator     * 2. If the admin is authorized to all cas applicable to userdata source.     *    or     *    If the userdatasource have "ANYCA" set.     * @return true if the administrator is authorized     */    private boolean isAuthorizedToUserDataSource(Admin admin, BaseUserDataSource userdatasource) {    	try {    		if(getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.ROLE_SUPERADMINISTRATOR)){    			return true;    		}    		    	} catch (AuthorizationDeniedException e) {}    	try {    		if(getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.ROLE_ADMINISTRATOR)){    			if(userdatasource.getApplicableCAs().contains(new Integer(BaseUserDataSource.ANYCA))){    				return true;    			}    			Collection authorizedcas = getAuthorizationSession().getAuthorizedCAIds(admin);    			if(authorizedcas.containsAll(userdatasource.getApplicableCAs())){    				return true;    			}    		}    	} catch (AuthorizationDeniedException e) {}    			return false;	}        /**     * Method to check if an admin is authorized to edit an user data source     * The following checks are performed.     *      * 1. If the admin is an administrator     * 2. If tha admin is authorized AvailableAccessRules.REGULAR_EDITUSERDATASOURCES     * 3. Only the superadmin should have edit access to user data sources with 'ANYCA' set     * 4. Administrators should be authorized to all the user data source applicable cas.     *      * @return true if the administrator is authorized     */    private boolean isAuthorizedToEditUserDataSource(Admin admin, BaseUserDataSource userdatasource) {    	try {    		if(getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.ROLE_SUPERADMINISTRATOR)){    			return true;    		}    	} catch (AuthorizationDeniedException e) {}    	try {    		if(getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.ROLE_ADMINISTRATOR) &&    				getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.REGULAR_EDITUSERDATASOURCES)){    			if(userdatasource.getApplicableCAs().contains(new Integer(BaseUserDataSource.ANYCA))){    				return false;    			}    			Collection authorizedcas = getAuthorizationSession().getAuthorizedCAIds(admin);    			if(authorizedcas.containsAll(userdatasource.getApplicableCAs())){    				return true;    			}    		}		} catch (AuthorizationDeniedException e) {}    			return false;	}    private Integer findFreeUserDataSourceId() {        Random ran = (new Random((new Date()).getTime()));        int id = ran.nextInt();        boolean foundfree = false;        while (!foundfree) {            try {                if (id > 1)                   userdatasourcehome.findByPrimaryKey(new Integer(id));                id = ran.nextInt();            } catch (FinderException e) {                foundfree = true;            }        }        return new Integer(id);    } // findFreeUserDataSourceId} // LocalUserDataSourceSessionBean

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -