本章介绍了 Sun Java System Content Delivery Server 用户管理 API。使用此 API 可以添加、删除、检索、更新、启用或禁用系统中的用户。
UserManager
类用于控制个人用户帐户的创建和状态,并且必须由 UserManager
类实现来实现。
User
接口用于管理每个用户的特定特性。
UserDeviceManager
接口提供有关订户正在使用的设备的信息,并可以用来防止订户只付一次费而将内容下载到多个设备上的情况。
有关本节中未介绍的类或方法的信息,请参见 $CDS_HOME/javadoc/cdsapi/index.html
中的用户配置文件 API 的 Javadoc 工具的 HTML 输出。
UserManager
类用于定义创建、删除或访问用户信息的方法。
如果用户帐户已经存在于给定用户 ID 的永久性存储中,将返回 true
。
创建新用户。
禁用用户帐户。用于锁定用户帐户。
启用用户帐户。
按指定顺序返回请求对象的迭代程序。
protected abstract void doAllLikeInOrder(String[] columns, String[] values, String[] orders, boolean isDescending, int pageNum, int recPerPage, String role)
根据用户角色返回永久存储中所有用户的迭代程序。
根据用户角色返回名字中包含指定子字符串的所有用户的迭代程序。
根据用户角色返回用户 ID 中包含指定子字符串的所有用户的迭代程序。
根据用户角色返回姓氏中包含指定子字符串的所有用户的迭代程序。
根据用户角色返回姓氏或名字中包含指定子字符串的所有用户的迭代程序。
为匿名访问系统返回一个来宾用户。
根据用户角色获取对应于某个字段常量的外部数据库中的字段名称。
返回与给定用户 ID 关联的用户对象。
返回与给定用户移动 ID 关联的用户对象。
返回与给定用户唯一设备 ID 关联的用户对象。
返回 addUser
方法中传递的用户类实现的实例。
如果与 userId
关联的用户帐户处于活动状态,则返回 true
。如果帐户处于非活动状态,则返回 false
。
如果允许通过提供的用户 ID 和密码进行访问,则返回 true
。
将用户从永久存储中删除。如果成功,则返回 true
。
更新现有的用户帐户。
User
接口用于定义获取、设置或删除用户特性的通用方法。
返回激活用户帐户的日期。
返回与特定用户关联的特性值。
返回与特定用户关联的特定特性的值或默认值(如果未找到属性)。
返回包含与特定用户关联的所有特性的散列表。
返回城市名称。
返回国家/地区名称。
返回用户帐户的创建日期。
返回用户帐户的激活日期。
返回用户的电子邮件 ID。
返回用户的名字。
返回用户的性别。
返回用户上次登录时间。
返回用户的姓氏。
返回用户的唯一登录 ID。
返回用户的中间名。
返回用户的移动 ID。
返回用户的唯一密码。
返回用户的联系电话号码。
返回用户帐户的邮政编码。
返回用户的称呼。
返回省/市/自治区名称。
返回用户街道地址的第一行。
返回用户街道地址的第二行。
返回用户的唯一设备 ID。
如果用户已经登录到系统,则返回 true
。
如果用户帐户已确认或验证,则返回 true
。
如果用户帐户当前已启用,则返回 true
;如果已禁用,则返回 false
。
如果用户帐户已预付,则返回 true
。
设置用户帐户的激活日期。
设置与特定用户关联的特性。
设置与特定用户关联的特性的列表。
设置城市名称。
设置国家/地区名称。
设置用户帐户的创建日期。
设置用户帐户取消激活的日期。
设置用户的电子邮件 ID。
设置用户的名字。
设置用户的性别。
设置用来表明用户已登录到系统的标志。
将帐户状态设置为“已启用”。
将帐户设置为“已预付”。
设置用户的姓氏。
设置用户的唯一登录 ID。
设置用户的中间名。
设置用户的移动 ID。
设置用户的密码。
设置用户的联系电话号码。
设置用户地址的邮政编码。
设置用户称呼(例如先生或女士)。
设置用户地址的省/市/自治区。
设置用户街道地址的第一行。
设置用户街道地址的第二行。
设置用户的唯一设备 ID。.
使用上次登录时间更新时间标记。
获取用于设备的唯一设备 ID,例如 MSISDN 提供的 ESN(电子序列号)。
用户配置文件 API 的类可以在 cdsapi.jar
(位于 $CDS_HOME/deployment/
deployment-name/lib/cdslib
目录)中找到。
编译适配器时,cdsapi.jar
文件必须位于类路径中。
为使适配器可用于 Content Delivery Server,请执行以下操作:
CDS_HOME/deployment/
deployment-name/lib/external
目录中,以便在执行过程中 Content Delivery Server 可以找到该文件。Content Delivery Server 需要重新启动才能发觉新的 JAR 文件。
$CDS_HOME/deployment/
deployment-name/conf
目录中修改 security.config
文件来设置 module.security.usermanagerfactory
和 module.security.subscriber.usermanager
属性。
将 module.security.subscriber.usermanager
设置为 UserManager
类的实现的名称。例如,
下例是 MyUserMgr
的类定义。该示例介绍了如何继承 UserManager
类以管理用户配置文件系统并将其集成到 Content Delivery Server 用户配置文件框架中。以下样例类提供了一个示例,即如何使用用户配置文件 API 来管理用户配置文件系统并将其集成到 Content Delivery Server 用户配置文件框架中。
用户配置文件 API 的样例实现使用特性和一个支持类。以下代码显示了所用的各个特性。
# This is a sample of typical Operator Integration properties file # for external user manager client/server connection settings. # # SAMPLE OPERATOR CONFIGURATIONS # externalserveraddress=localhost externalserverport=7779 cdsclientlogin=cds14sun cdsclientpasswd=cds4sun1
SampleExternalProxy
类用作 Content Delivery Server 与外部数据库之间的接口。
package com.sun.content.server.operator.security.adaptor; import java.util.*; import com.sun.content.server.service.security.*; import com.sun.content.server.service.security.util.*; // import external required packages to connect to the directory service public class SampleExternalProxy { // Create a Client facace for serach private ExternalClientObject externalUserMgr; // Create an instance of External Directorory server Client Proxy public SampleExternalProxy() throws Exception { // User the external package to instanciate the Proxu // You need to use the client/server setting in the // operatorproxy.properties // The following assume you implemented a class OperatorProxyProperties // to read the configuration values. String hostname = OperatorProxyProperties.EXTERNAL_SERVER_ADDRESS; String port = OperatorProxyProperties.EXTERNAL_SERVER_PORT; String clientLoginId = OperatorProxyProperties.CLIENT_LOGIN; String clientPassword = OperatorProxyProperties.CLIENT_PASSWRD; // instan try { externalUserMgr = new ExternalClientObject(hostname, port, clientLoginId, clientPassword); } catch (Exception expt) { // process the exception throw expt; } } public boolean searchUser(String userName) { boolean found = false; // Use the external User manager and search function for the given string // name // Typically the call will look like // found = externalUserMgr.searchUser(userName); // You may need to catch potential exception and display the appropriate // message return found; } public SampleUserImpl createUserFromExternal(String loginId) throw Exception { System.out.println("DEBUG:SampleExternal Proxy --- createUserFromExternal "); System.out.println(" Creating a SampleUserImpl from External Directory ...."); System.out.println(" Reference Login Id = "+loginId); try { // Assuming the external client has been created and connection is // established // The following call typically search for the UserName and return an // External UserProfile aUserProfileData aUPD = externalUserMgr.getUserProfileData(loginId); String password = aUPD.getCredential(); // Create basic User information (firstname, // middlename, lastname, // address, etc.) String firstName = aUPD.getFirstName(); String lastName = aUPD.getLastName(); String middleName = aUPD.getMiddleInitial(); String gender = aUPD.getGender(); String salutation = aUPD.getOccupation(); String street1 = aUPD.getStreet(); String street2 = aUPD.getStreetNumber(); String city = aUPD.getCity(); String state = aUPD.getState(); String postalcode = aUPD.getZipCode(); String country = aUPD.getCountry(); String phone = aUPD.getFixedPhone(); // Creating email information String email = aUPD.getMailAddress(); // Creating msisdn in this case Unique Device Id () String uniqueDeviceId = aUPD.getMsisdn(); // Creating Status data:User Enabled/Desabled and User is // Prepay/Non-Prepay are valued 1/0 boolean enabled = false; if (aUPD.getStatus().equals("1")) enabled = true; boolean prepay = false; if (aUPD.getPrepayType().equals("1")) prepay = true; // Create activation and deactivation dates if provided Date activatedate = new Date(); Date deactivatedate = null; // Create and return a Sample User Implementation return new SampleUserImpl( loginId, password, firstName, lastName, middleName, gender, street1, street2, city, state, postalcode, country, email, phone, activatedate, deactivatedate, salutation, enabled, uniqueDeviceId, prepay); } catch (Exception ex) { // procecss exception throw ex; } return null; } }
以下代码是用户接口的样例实现。此接口包括 Content Delivery Server 用于用户配置文件的字段。对于特定实现可能还需要添加其他字段。如果需要添加其他字段,请添加所需的方法以获得和设置这些值。
package com.sun.content.server.operator.security.adaptor; import com.sun.content.server.service.security.User; import java.util.Date; import java.util.Hashtable; public class SampleUserImpl implements User { private Hashtable fInfo; public SampleUserImpl() { fInfo = new Hashtable(); setLoginId("guest"); setFirstName("guest"); setLastName("guest"); setPassword ("guest"); setCreateDate(new Date()); setActivateDate(new Date()); fInfo.put("enabled", String.valueOf(true)); setMiddleName("guest"); setEmail("guest@email.com"); setUniqueDeviceId("1231231233"); } public SampleUserImpl(String uid, String pwd, String fname, String lname,String mname,String gender, String street1, String street2,String city, String state,String postalcode, String country,String email,String phone,Date actdate,Date deactdate, String salutation, boolean enabled, String uniqueDeviceId, boolean isprepay) { fInfo = new Hashtable(); setLoginId(uid); setPassword(pwd); setFirstName(fname); setLastName(lname); setMiddleName(mname); setGender(gender); setStreet1(street1); setStreet2(street2); setCity(city); setState(state); setPostalCode(postalcode); setCountry(country); setEmail(email); setPhone(phone); setFixedPhone(phone); // It is safe to check the activation date and use current date if null if ( actdate == null ) { setCreateDate(new Date()); setActivateDate(new Date()); } else { setCreateDate(actdate); setActivateDate(actdate); } setDeActivateDate(deactdate); setSalutation(salutation); setIsEnabled(enabled); setUniqueDeviceId(uniqueDeviceId); setIsPrepay(isprepay); } public SampleUserImpl(User inUser) { fInfo = new Hashtable(); setLoginId(inUser.getLoginId()); setFirstName(inUser.getFirstName()); setLastName(inUser.getLastName()); setMiddleName(inUser.getMiddleName()); setGender(inUser.getGender()); setStreet1(inUser.getStreet1()); setStreet2(inUser.getStreet2()); setCity(inUser.getCity()); setState(inUser.getState()); setPostalCode(inUser.getPostalCode()); setCountry(inUser.getCountry()); setEmail(inUser.getEmail()); setPhone(inUser.getPhone()); setSalutation(inUser.getSalutation()); setIsEnabled(inUser.isEnabled()); setPassword(inUser.getPassword()); setUniqueDeviceId(inUser.getUniqueDeviceId()); } // It is sometime useful to have the corresponding external user data as a // hashtable public Hashtable getExternalUserData() { // Create a hash table Hashtable externalData = new Hashtable(); // Get all the external data from fInfo and update the external data // externalData = parserUser(fInfo); return externalData; } public Date getLastLogin() { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method getLastLogin() not yet implemented."); } public Object getAttribute(String param1) { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method getAttribute() not yet implemented."); } public Object getAttribute(String param1, Object parm2) { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method getAttribute() not yet implemented."); } public Hashtable getAttributes() { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method getAttributes() not yet implemented."); } public void setHasLoggedIn(boolean param1) { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method setAttribute() not yet implemented."); } public boolean hasLoggedIn() { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method isConfirmed() not yet implemented."); } public void setAttribute(String param1, Object parm2) { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method setAttribute() not yet implemented."); } public void setAttributes(Hashtable param1) { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method setAttributes() not yet implemented."); } public String getLoginId() { return (String)fInfo.get("loginId"); } public void setLoginId(String param1) { if (param1 != null) fInfo.put("loginId", param1); } public String getFirstName() { return (String)fInfo.get("firstName"); } public void setFirstName(String param1) { if (param1 != null) fInfo.put("firstName", param1); } public String getLastName() { return (String)fInfo.get("lastName"); } public void setLastName(String param1) { if (param1 != null) fInfo.put("lastName", param1); } public Date getCreateDate() { return (Date)fInfo.get("createDate"); } public void setCreateDate(Date param1) { if (param1 != null) fInfo.put("createDate", param1); } public String getEmail() { return (String)fInfo.get("email"); } public void setEmail(String param1) { if (param1 != null) fInfo.put("email", param1); } public boolean isConfirmed() { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method isConfirmed() not yet implemented."); } public void updateLastLogin() throws java.lang.Exception { /**@todo:Implement this com.sun.content.server.service.security.User method*/ throw new java.lang.UnsupportedOperationException("Method updateLastLogin() not yet implemented."); } public String getMiddleName() { return (String)fInfo.get("middleName"); } public void setMiddleName(String param1) { if (param1 != null) fInfo.put("middleName", param1); } public String getGender() { return (String)fInfo.get("gender"); } public void setGender(String param1) { if (param1 != null) fInfo.put("gender", param1); } public String getStreet1() { return (String)fInfo.get("street1"); } public void setStreet1(String param1) { if (param1 != null) fInfo.put("street1", param1); } public String getStreet2() { return (String)fInfo.get("street2"); } public void setStreet2(String param1) { if (param1 != null) fInfo.put("street2", param1); } public String getPostalCode() { return (String)fInfo.get("postalCode"); } public void setPostalCode(String param1) { if (param1 != null) fInfo.put("postalCode", param1); } public String getCity() { return (String)fInfo.get("city"); } public void setCity(String param1) { if (param1 != null) fInfo.put("city", param1); } public String getState() { return (String)fInfo.get("state"); } public void setState(String param1) { if (param1 != null) fInfo.put("state", param1); } public String getCountry() { return (String)fInfo.get("country"); } public void setCountry(String param1) { if (param1 != null) fInfo.put("country", param1); } public String getPhone() { return (String)fInfo.get("phone"); } public void setPhone(String param1) { if (param1 != null) fInfo.put("phone", param1); } public Date getActivateDate() { return (Date)fInfo.get("activateDate"); } public void setActivateDate(Date param1) { if (param1 != null) fInfo.put("activateDate", param1); } public Date getDeActivateDate() { return (Date)fInfo.get("deactivateDate"); } public void setDeActivateDate(Date param1) { if (param1 != null) fInfo.put("deactivateDate", param1); } public String getSalutation() { return (String)fInfo.get("salutation"); } public void setSalutation(String param1) { if (param1 != null) fInfo.put("salutation", param1); } public boolean isEnabled() { return Boolean.valueOf((String)fInfo.get("enabled")).booleanValue(); } public void setIsEnabled(boolean param1) { fInfo.put("enabled", String.valueOf(param1)); } public String getPassword() { return (String)fInfo.get("password"); } public void setPassword(String param1) { if (param1 != null) fInfo.put("password", param1); } public String getUniqueDeviceId(){ return (String)fInfo.get("UniqueDeviceId"); } public void setUniqueDeviceId(String uniqueId){ if (uniqueId != null) fInfo.put("UniqueDeviceId", uniqueId); } public String getMobileId(){ return (String)fInfo.get("MobileId"); } public void setMobileId(String mobileId) { if (mobileId != null) fInfo.put("MobileId", mobileId); } public boolean isPrepay() { Boolean isprepay = (Boolean)fInfo.get("isPrepay"); return isprepay.booleanValue(); } public void setIsPrepay(boolean param1) { fInfo.put("isPrepay", new Boolean(param1)); } }
以下代码是 UserManager 类的样例实现。
package com.sun.content.server.operator.security.adaptor; import java.util.*; //import Content Delivery Server libraries import com.sun.content.server.service.security.*; import com.sun.content.server.service.security.util.*; //import here operator required packages // ....... public class SampleUserManagerImpl { private SampleExternalProxy proxy; public SampleUserManagerImpl() throws UserProfileResourceException { try { init(); } catch (Exception ex) { throw new com.sun.content.server.service.security.util.UserProfileResourceException( "Failed to instantiate SampleUserManagerImpl ", ex); } } // This method will create an External Directory Server Proxy and // initiatlize this User Manager private void init() throws UserProfileResourceException { System.out.println("Initializing External UserManager .... "); try { proxy = new SampleExternalProxy(); } catch (Exception ex) { System.out.println("Fatal Error " + ex.toString()); throw new com.sun.content.server.service.security.util.UserProfileResourceException(ex.toString()); } } protected boolean doIsAuthenticated(String inUserId, String inPassword) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doIsAuthenticated --- "); boolean isauthenticated = false; try { User aUser = proxy.createUserFromExternal(inUserId); isauthenticated = ( (aUser.getLoginId()==inUserId) && (aUser.getPassword()==inPassword)); if (isauthenticated) System.out.println("SampleUserManagerImpl.doIsAuthenticated:- User "+inUserId+" is successfully authenticated."); else System.out.println("SampleUserManagerImpl.doIsAuthenticated:- User "+inUserId+" :unable to authenticate (wrong login and password)"); } catch (Exception ex) { isauthenticated = false; System.out.println("SampleUserManagerImpl.doIsAuthenticated:- User "+inUserId+" can not authenticate (user not found)"); throw new com.sun.content.server.service.security.util.UserProfileResourceException(ex.toString()); } return isauthenticated; } protected boolean doAccountExists(String userId) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doAccountExists --- "); // Use the External Proxy search method to check if the account exist return proxy.searchUser(userId); } protected boolean doAddUser(User user) throws UserProfileResourceException{ boolean updated = false; //This is not an allowed operation.If this is not the case add the code to // implement it System.out.println("SampleUserManagerImpl.doAddUser - This operation is not implemented !"); return updated; } protected void doDisableUser(String userId) throws UserProfileResourceException { //This is not an allowed operation.If this is not the case add the code to // implement it System.out.println("SampleUserManagerImpl.doDisableUser - This operation is not implemented !"); } protected void doEnableUser(String userId) throws UserProfileResourceException { //This is not an allowed operation.If this is not the case add the code to // implement it System.out.println("SampleUserManagerImpl.doEnableUser - This operation is not implemented !"); } protected User doGetAnonymousUser() throws UserProfileResourceException { return new SampleUserImpl(); } protected User doGetUser(String userId) throws UserProfileResourceException { User aUser = null; try { aUser = proxy.createUserFromExternal(userId); if (aUser != null) System.out.println("SampleUserManagerImpl.doGetUserByUniqueDeviceId:- User with "+userId+" is found."); else System.out.println("SampleUserManagerImpl.doGetUserByUniqueDeviceId:- User with "+userId+" not found"); } catch (Exception ex) { System.out.println("SampleUserManagerImpl.doGetUserByUniqueDeviceId:- User "+userId+" not found)"); throw new com.sun.content.server.service.security.util.UserProfileResourceException(ex); } return aUser; } /* This method can be implemented the same way as doGetUser.Instead of * using the createUserFromExternal(loginId) you can extend the * SampleExternalProxy to implement a specific * createUserFromExternalUsingDeviceId(uniqueDeviceId). * For now we will assume that the string loginId can be replaced by a search * key ID and it will return the matching profile. */ protected User doGetUserByUniqueDeviceId(String inUniqueDeviceId) throws UserProfileResourceException { return doGetUser(inUniqueDeviceId); } // Sample implementation as doGetUser protected User doGetUserByMobileId(String inMobileId) throws UserProfileResourceException { return doGetUser(inMobileId); } protected Iterator doGetAllUsers(String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllUsers - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected Iterator doGetAllUsersContainingLastName(String lastName, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllUsersContainingLastName - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected Iterator doGetAllUsersContainingFirstName(String firstName, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllUsersContainingFirstName - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected Iterator doGetAllUsersContainingName(String name, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllUsersContainingName - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected Iterator doGetAllUsersContainingId(String userId, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllUsersContainingId - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected Iterator doGetAllLikeInOrder(String[] columns, String[] values, String[] orders, boolean isDescending, int pageNum, int recPerPage, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetAllLikeInOrder - This operation is not implemented !"); ArrayList users = new ArrayList(); return users.iterator(); } protected String doGetFieldName(int fieldContant, String role) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetFieldName - This operation is not implemented !"); return null; } protected boolean doIsActive(String userId) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doIsActive - This operation is not implemented !"); return false; } protected boolean doRemoveUser(String userId) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doRemoveUser - This operation is not implemented !"); return false; } protected boolean doUpdateUser(User user) throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doUpdateUser - This operation is not implemented !"); return false; } protected User doGetUserInstance() throws UserProfileResourceException { System.out.println("SampleUserManagerImpl.doGetUserInstance - This operation is not implemented !"); return null; } }
定制指南 Sun Java™ System Content Delivery Server,版本 2004Q1 |
版权所有 © 2004 Sun Microsystems, Inc. 保留所有权利。必须依据许可证条款使用。