技术开发 频道

Portal中调用PUMA SPI管理用户

    【IT168 技术文章】

    在Portal开发中,遇到需要获得用户、组信息时,就需要调用PUMA SPI(Portal User Management Architecture System programming interface)了。

    PUMA SPI提供获得当前及系统任何用户、组profile的方法,并可对用户和组进行增、删、改。

    PUMA SPI主要包括三个接口

    PumaProfile:可以获得当前或其他用户、组的属性值(profile)

    PumaLocator:可以查询任何用户、组的信息

    PumaController:可以新增、修改、删除用户和组的信息

    PUMA SPI的调用

    PUMA SPI可以在各种Portal应用中调用,不同类型的应用分别调用不同的home接口,包括

    标准(JSR168) portlet

    com.ibm.portal.um.portletservice.PumaHome

    IBM portlet

    com.ibm.portal.um.portletservice.legacy.PumaHome

    Portal 应用 (主要是theme和skin)

    com.ibm.portal.um.PumaHome

    以JSR 168Portlet中调用为例,调用代码段如下所示,忽略异常处理,有异常就直接向上抛好了,反正这里也处理不了:

    PumaHome service;

    if(service==null){

    InitialContext ctx = new InitialContext();//初始化上下文

    PortletServiceHome psh = (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome";//获得Home接口

    service = (PumaHome)psh.getPortletService(PumaHome.class);//获得服务接口

    }

    PumaLocator locator = service.getLocator(request);//获得PumaLocator 接口

    PumaProfile profile = service.getProfile(request);//获得PumaProfile接口

    User user = profile.getCurrentUser();//获得当前用户

    List groups = locator.findGroupsByPrincipal(user,true);//获得用户所处组

    List userGroupNames = new ArrayList();//用于保存用户所处组的名称

    List attr = new ArrayList();

    attr.add("cn";//用于从Group对象中获得cn属性

    Group group = null;

    for(Iterator it=groups.iterator();it.hasNext(){

    group = (Group)it.next();

    userGroupNames.add((String)profile.getAttributes(group,attr).get("cn");//将Group对象列表中的组名置入一个新的List对象中

    }

    JavaDoc文档未与PortalServer安装路径的doc目录下,如/opt/IBM/WebSphere/PortalServer/doc/Javadoc/spi_docs

    如果使用RAD开发,IDE可以自动添加依赖的Portal包;如果不使用RAD,则开发时需要手工添加需要依赖的jar包到classpath以便进行编译,打包时则不要把这些jar包添加到war包中。相关jar包可以在/opt/IBM/WebSphere/PortalServer/shared/app目录中找到。在JSR 168的Portlet的开发环境中,需要依赖的包有wp.user.api.jar,wp.pe.api.standard.jar,wp.base.jar
 

0
相关文章