PUMA== Portal User Management Architecture
SPI==Services Provider Interface.
PUMA SPI提供对portal用户或组的profiles访问。可以CRUD用户和组。当前登陆用户的Profiles信息可以获得。每个portal中的资源都有一个ObjectID,PUMA这里就是在portal用户注册表中的用户或者组。PUMA SPI提供的接口继承了ModelSPI的com.ibm.portal.Identifiable接口的getObjectID()方法。这个方法就是获得ObjectID用的。
PUMA中的一些Provider对象:
PumaProfile------包含了对user和group属性和标识符的只读访问。可以用这个接口来获取当前登陆的用户信息。
PumaLocator------包含了查找user和group的方法。可以用这个接口来获得当前用户所在的所有组的组列表。
PumaController------包含了创建,删除user和group的方法,还有修改user和group档案和成员。
在portlet能够使用这些接口之前,它必须先找到合适的home接口作为入口点。
Standard portlet
com.ibm.portal.um.portletservice.PumaHome
IBM portlet
com.ibm.portal.um.portletservice.legacy.PumaHome
Portal application (for example, theme or skin)
com.ibm.portal.um.PumaHome
上述接口如何使用在JavaDoc中有详细介绍,下面是一个JSR168标准portlet如何获得用户id的
PortletServiceHome psh;try{ javax.naming.Context ctx = new javax.naming.InitialContext(); psh = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome"); if (psh != null){ PumaHome service = (PumaHome) psh.getPortletService(PumaHome.class); PumaProfile pp = service.getProfile(request); User user = pp.getCurrentUser(); String user_objid = pp.getIdentifier(user); }}catch (PumaException pe){ // ... error handling ...} catch(javax.naming.NameNotFoundException ex) { // ... error handling ...} catch(javax.naming.NamingException ex) { // ... error handling ...}
PUMA SPI不能够被用于WSRP和远程Portlet.
Remote PUMA SPI 则提供了远程访问Portlet的方法。他通过REST架构模型实现。
下面再给一例子,这个例子我从网上找到的:
String groupName = "";
String userName = "";
PortletServiceHome psh;
try {
javax.naming.Context ctx = new javax.naming.InitialContext();
psh = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");
if (psh != null){
PumaHome service = (PumaHome) psh.getPortletService(PumaHome.class);
PumaProfile pp = service.getProfile(request);
User user = pp.getCurrentUser();
userName = pp.getIdentifier(user);
userName = user_id.substring(3,user_id.indexOf(","));
System.out.println("userName = " + userName);
PumaLocator pl = service.getLocator(request);
List li = pl.findGroupsByPrincipal(user, true);
Iterator iterator = li.iterator();
int size = li.size();
int count = 0;
while(iterator.hasNext()) {
Group group = (Group) iterator.next();
if (size != 1) {
if (count != size) {
groupName += group.getName() + ",";
} else {
groupName += group.getName();
}
} else {
groupName = group.getName();
}
System.out.println("groupName = " + group.getName());
count++;
}
}
} catch(javax.naming.NameNotFoundException e) {
e.printStackTrace();
} catch(javax.naming.NamingException e) {
e.printStackTrace();
} catch (PortletServiceUnavailableException e) {
e.printStackTrace();
} catch (com.ibm.portal.um.exceptions.PumaException e) {
e.printStackTrace();
}
本文介绍了PUMA(Portal User Management Architecture)及其SPI(Services Provider Interface),详细解释了PUMASPI如何提供对门户用户及组的档案访问,并展示了如何在Java环境中利用PumaHome接口获取当前登录用户的信息及所属组。
1571

被折叠的 条评论
为什么被折叠?



