📄 userdatabean.java
字号:
/** * Sets the time when the user was last modified. * * @ejb.interface-method */ public abstract void setTimeModified(long createtime); /** * Returns the end entity profile id the user belongs to. * * @ejb.persistence column-name="endEntityProfileId" * @ejb.interface-method */ public abstract int getEndEntityProfileId(); /** * Sets the end entity profile id the user should belong to. 0 if profileid is not applicable. * * @ejb.interface-method */ public abstract void setEndEntityProfileId(int endentityprofileid); /** * Returns the certificate profile id that should be generated for the user. * * @ejb.persistence column-name="certificateProfileId" * @ejb.interface-method */ public abstract int getCertificateProfileId(); /** * Sets the certificate profile id that should be generated for the user. 0 if profileid is not applicable. * * @ejb.interface-method */ public abstract void setCertificateProfileId(int certificateprofileid); /** * Returns the token type id that should be generated for the user. * * @ejb.persistence column-name="tokenType" * @ejb.interface-method */ public abstract int getTokenType(); /** * Sets the token type that should be generated for the user. Available token types can be found in SecConst. * * @ejb.interface-method */ public abstract void setTokenType(int tokentype); /** * Returns the hard token issuer id that should genererate for the users hard token. * * @ejb.persistence column-name="hardTokenIssuerId" * @ejb.interface-method */ public abstract int getHardTokenIssuerId(); /** * Sets the hard token issuer id that should genererate for the users hard token. 0 if issuerid is not applicable. * * @ejb.interface-method */ public abstract void setHardTokenIssuerId(int hardtokenissuerid); /** * Non-searchable information about a user. * * @ejb.persistence jdbc-type="LONGVARCHAR" column-name="extendedInformationData" */ public abstract String getExtendedInformationData(); /** * Non-searchable information about a user. * */ public abstract void setExtendedInformationData(String data); // Reserved for future use. /** * @ejb.persistence column-name="keyStorePassword" */ public abstract String getKeyStorePassword(); /** */ public abstract void setKeyStorePassword(String keystorepassword); // // Public methods used to help us manage passwords // /** * Function that sets the BCDN representation of the string. * @ejb.interface-method */ public void setDN(String dn) { setSubjectDN(CertTools.stringToBCDNString(dn)); } /** * Sets password in ahsed form in the database, this way it cannot be read in clear form * @ejb.interface-method */ public void setPassword(String password) throws NoSuchAlgorithmException { String passwordHash = makePasswordHash(password); setPasswordHash(passwordHash); setClearPassword(null); } /** * Sets the password in clear form in the database, needed for machine processing, * also sets the hashed password to the same value * @ejb.interface-method */ public void setOpenPassword(String password) throws NoSuchAlgorithmException { String passwordHash = makePasswordHash(password); setPasswordHash(passwordHash); setClearPassword(password); } /** * Verifies password by verifying against passwordhash * @ejb.interface-method */ public boolean comparePassword(String password) throws NoSuchAlgorithmException { log.debug(">comparePassword()"); if (password == null) return false; log.debug("<comparePassword()"); //log.debug("Newhash="+makePasswordHash(password)+", OldHash="+passwordHash); return (makePasswordHash(password).equals(getPasswordHash())); } // // Helper functions // /** * Creates the hashed password */ private String makePasswordHash(String password) throws NoSuchAlgorithmException { log.debug(">makePasswordHash()"); if (password == null) return null; String ret = null; try { MessageDigest md = MessageDigest.getInstance("SHA1"); byte[] pwdhash = md.digest(password.trim().getBytes()); ret = new String(Hex.encode(pwdhash)); } catch (NoSuchAlgorithmException nsae) { log.error("SHA1 algorithm not supported.", nsae); throw nsae; } log.debug("<makePasswordHash()"); return ret; } /** * Non-searchable information about a user. for future use. * @ejb.interface-method */ public ExtendedInformation getExtendedInformation() { return UserDataVO.getExtendedInformation(getExtendedInformationData()); } /** * Non-searchable information about a user. for future use. * @ejb.interface-method */ public void setExtendedInformation(ExtendedInformation extendedinformation) { if(extendedinformation != null){ // We must base64 encode string for UTF safety HashMap a = new Base64PutHashMap(); a.putAll((HashMap)extendedinformation.saveData()); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); java.beans.XMLEncoder encoder = new java.beans.XMLEncoder(baos); encoder.writeObject(a); encoder.close(); try { setExtendedInformationData(baos.toString("UTF8")); } catch (UnsupportedEncodingException e) { throw new EJBException("Problems storing extended information for user :" + getUsername(),e); } } } // // Fields required by Container // /** * Entity Bean holding info about a User. * Create by sending in the instance, username, password and subject DN. * SubjectEmail, Status and Type are set to default values (null, STATUS_NEW, USER_INVALID). * and should be set using the respective set-methods. Clear text password is not set at all and must be set using setClearPassword(); * * @param username the unique username used for authentication. * @param password the password used for authentication. This inly sets passwordhash, to set cleartext password, the setPassword() method must be used. * @param dn the DN the subject is given in his certificate. * @return UserDataPK primary key * @ejb.create-method */ public UserDataPK ejbCreate(String username, String password, String dn, int caid) throws CreateException, NoSuchAlgorithmException { long time = (new Date()).getTime(); setUsername(StringTools.strip(username)); setClearPassword(null); setPasswordHash(makePasswordHash(password)); setSubjectDN(CertTools.stringToBCDNString(dn)); setCaId(caid); setSubjectAltName(null); setSubjectEmail(null); setStatus(UserDataConstants.STATUS_NEW); setType(SecConst.USER_INVALID); setTimeCreated(time); setTimeModified(time); setEndEntityProfileId(0); setCertificateProfileId(0); setTokenType(SecConst.TOKEN_SOFT_BROWSERGEN); setHardTokenIssuerId(0); setExtendedInformationData(null); UserDataPK pk = new UserDataPK(username); log.debug("Created user " + username); return pk; } public void ejbPostCreate(String username, String password, String dn, int caid) { // Do nothing. Required. } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -