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

📄 localpublishersessionbean.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Adds a publisher to the database.     *     * @throws PublisherExistsException if hard token already exists.     * @throws EJBException             if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void addPublisher(Admin admin, String name, BasePublisher publisher) throws PublisherExistsException {        debug(">addPublisher(name: " + name + ")");        addPublisher(admin,findFreePublisherId().intValue(),name,publisher);        debug("<addPublisher()");    } // addPublisher    /**     * Adds a publisher to the database.     * Used for importing and exporting profiles from xml-files.     *     * @throws PublisherExistsException if hard token already exists.     * @throws EJBException             if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void addPublisher(Admin admin, int id, String name, BasePublisher publisher) throws PublisherExistsException {        debug(">addPublisher(name: " + name + ", id: " + id + ")");        boolean success = false;        try {            publisherhome.findByName(name);        } catch (FinderException e) {            try {                publisherhome.findByPrimaryKey(new Integer(id));            } catch (FinderException f) {                try {                    publisherhome.create(new Integer(id), name, publisher);                    success = true;                } catch (CreateException g) {                    error("Unexpected error creating new publisher: ", g);                }            }        }        if (success)            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "Publisher " + name + " added.");        else            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Error adding publisher " + name);        if (!success)            throw new PublisherExistsException();        debug("<addPublisher()");    } // addPublisher    /**     * Updates publisher data     *     * @throws EJBException if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void changePublisher(Admin admin, String name, BasePublisher publisher) {        debug(">changePublisher(name: " + name + ")");        boolean success = false;        try {            PublisherDataLocal htp = publisherhome.findByName(name);            htp.setPublisher(publisher);            success = true;        } catch (FinderException e) {        }        if (success)            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "Publisher " + name + " edited.");        else            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Error editing publisher " + name + ".");        debug("<changePublisher()");    } // changePublisher    /**     * Adds a publisher with the same content as the original.     *     * @throws PublisherExistsException if publisher already exists.     * @throws EJBException             if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void clonePublisher(Admin admin, String oldname, String newname) {        debug(">clonePublisher(name: " + oldname + ")");        BasePublisher publisherdata = null;        try {            PublisherDataLocal htp = publisherhome.findByName(oldname);            publisherdata = (BasePublisher) htp.getPublisher().clone();            try {                addPublisher(admin, newname, publisherdata);                getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "New publisher " + newname + ", used publisher " + oldname + " as template.");            } catch (PublisherExistsException f) {                getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Error adding publisher " + newname + " using publisher " + oldname + " as template.");                throw f;            }        } catch (Exception e) {            error("Error cloning publisher: ", e);            throw new EJBException(e);        }        debug("<clonePublisher()");    } // clonePublisher    /**     * Removes a publisher from the database.     *     * @throws EJBException if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void removePublisher(Admin admin, String name) {        debug(">removePublisher(name: " + name + ")");        try {            PublisherDataLocal htp = publisherhome.findByName(name);            htp.remove();            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "Publisher " + name + " removed.");        } catch (Exception e) {            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, "Error removing publisher " + name + ".", e);        }        debug("<removePublisher()");    } // removePublisher    /**     * Renames a publisher     *     * @throws PublisherExistsException if publisher already exists.     * @throws EJBException             if a communication or other error occurs.     * @ejb.interface-method view-type="both"     */    public void renamePublisher(Admin admin, String oldname, String newname) throws PublisherExistsException {        debug(">renamePublisher(from " + oldname + " to " + newname + ")");        boolean success = false;        try {            publisherhome.findByName(newname);        } catch (FinderException e) {            try {                PublisherDataLocal htp = publisherhome.findByName(oldname);                htp.setName(newname);                success = true;            } catch (FinderException g) {            }        }        if (success)            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, "Publisher " + oldname + " renamed to " + newname + ".");        else            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, " Error renaming publisher  " + oldname + " to " + newname + ".");        if (!success)            throw new PublisherExistsException();        debug("<renamePublisher()");    } // renameHardTokenProfile    /**     * Retrives a Collection of id:s (Integer) to authorized publishers.     *     * @return Collection of id:s (Integer)     * @ejb.interface-method view-type="both"     */    public Collection getAuthorizedPublisherIds(Admin admin) {        HashSet returnval = new HashSet();        Collection result = null;        boolean superadmin = false;        // If superadmin return all available publishers        try {            superadmin = getAuthorizationSession().isAuthorized(admin, AvailableAccessRules.ROLE_SUPERADMINISTRATOR);            result = this.publisherhome.findAll();            Iterator i = result.iterator();            while (i.hasNext()) {                PublisherDataLocal next = (PublisherDataLocal) i.next();                returnval.add(next.getId());            }        } catch (AuthorizationDeniedException e1) {        	log.debug("AuthorizationDeniedException: ", e1);        } catch (FinderException fe) {        	log.error("FinderException looking for all publishers: ", fe);        }        // If ca admin return        if (!superadmin) {            Iterator authorizedcas = this.getAuthorizationSession().getAuthorizedCAIds(admin).iterator();            while (authorizedcas.hasNext()) {                returnval.addAll(this.getCAAdminSession().getCAInfo(admin, ((Integer) authorizedcas.next()).intValue()).getCRLPublishers());            }        }        return returnval;    } // getAuthorizedPublisherIds    /**     * Method creating a hashmap mapping publisher id (Integer) to publisher name (String).     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public HashMap getPublisherIdToNameMap(Admin admin) {        HashMap returnval = new HashMap();        Collection result = null;        try {            result = publisherhome.findAll();            Iterator i = result.iterator();            while (i.hasNext()) {                PublisherDataLocal next = (PublisherDataLocal) i.next();                returnval.put(next.getId(), next.getName());            }        } catch (FinderException e) {        }        return returnval;    } // getPublisherIdToNameMap    /**     * Retrives a named publisher.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public BasePublisher getPublisher(Admin admin, String name) {        BasePublisher returnval = null;        try {            returnval = (publisherhome.findByName(name)).getPublisher();        } catch (FinderException e) {            // return null if we cant find it        }        return returnval;    } //  getPublisher    /**     * Finds a publisher by id.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public BasePublisher getPublisher(Admin admin, int id) {        BasePublisher returnval = null;        try {            returnval = (publisherhome.findByPrimaryKey(new Integer(id))).getPublisher();        } catch (FinderException e) {            // return null if we cant find it        }        return returnval;    } // getPublisher    /**     * Help method used by publisher proxys to indicate if it is time to     * update it's data.     *     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public int getPublisherUpdateCount(Admin admin, int publisherid) {        int returnval = 0;        try {            returnval = (publisherhome.findByPrimaryKey(new Integer(publisherid))).getUpdateCounter();        } catch (FinderException e) {        }        return returnval;    }    /**     * Returns a publisher id, given it's publishers name     *     * @return the id or 0 if the publisher cannot be found.     * @ejb.transaction type="Supports"     * @ejb.interface-method view-type="both"     */    public int getPublisherId(Admin admin, String name) {        int returnval = 0;        try {            Integer id = (publisherhome.findByName(name)).getId();            returnval = id.intValue();        } catch (FinderException e) {        }        return returnval;    } // getPublisherId    /**     * Returns a publishers 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 getPublisherName(Admin admin, int id) {        debug(">getPublisherName(id: " + id + ")");        String returnval = null;        PublisherDataLocal htp = null;        try {            htp = publisherhome.findByPrimaryKey(new Integer(id));            if (htp != null) {                returnval = htp.getName();            }        } catch (FinderException e) {        }        debug("<getPublisherName()");        return returnval;    } // getPublisherName    private Integer findFreePublisherId() {        Random ran = (new Random((new Date()).getTime()));        int id = ran.nextInt();        boolean foundfree = false;        while (!foundfree) {            try {                if (id > 1)                    publisherhome.findByPrimaryKey(new Integer(id));                id = ran.nextInt();            } catch (FinderException e) {                foundfree = true;            }        }        return new Integer(id);    } // findFreeHardTokenIssuerId} // LocalPublisherSessionBean

⌨️ 快捷键说明

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