The Remote PUMA SPI REST Service is implemented as a servlet that runs as a separate enterprise application on the WebSphere Portal Express server.
Operation | Description | Parameter(Method Name) |
/um/attributes/users | list of references to the attribute definitions that are available for users | expandRefs(GET) |
/um/attributes/users/attribute name | representation of the attribute definition | |
/um/attributes/groups | the list of references to the attribute definitions that are available for groups | expandRefs(GET) |
/um/attributes/groups/attribute name | a representation of the attribute definition | |
/um/currentuser/profile | profile of the current user. If this operation is performed without authentication, the profile of the anonymous user is returned. | Update(PUT OR POST) |
/um/users/profiles | the list of references to all user that correspond to the search criteria and other parameters. If there are no limiting parameters, all available users are returned. The list that is returned is access control filtered for the current user. | expandRefs(GET) includeAttributes(GET) memberOf(GET) showNested(GET) searchAttributes(GET) identifier(GET) resultsPerPage(GET) sortByAttributes(GET) descending(GET) |
/um/groups/profiles | the list of references to all groups that correspond to the search criteria and other parameters. If there are no limiting parameters, all available groups are returned. The list that is returned is access control filtered for the current user. | expandRefs(GET) includeAttributes(GET) memberOf(GET) showNested(GET) searchAttributes(GET) identifier(GET) resultsPerPage(GET) sortByAttributes(GET) descending(GET) |
/um/users/profiles/unique id of user | Returns a representation of a user profile. | update(PUT OR POST) |
/um/groups/profiles/unique id of group | Returns a representation of a group profile. | update(PUT OR POST) |
/um/groupmembership/unique id of user | Returns the list of references to all group profiles of the groups of which the user is a member. | expandRefs(GET) includeAttributes(GET) showNested(GET) update(PUT OR POST) |
/um/groupmembership/unique id of group | Returns the list of references to all group profiles of the groups of which the group is a member. | expandRefs(GET) includeAttributes(GET) showNested(GET) update(PUT OR POST) |
The portal Remote PUMA SPI REST Service allows requests to the following operations only for authenticated users by using the /um/secure path element:
- /um/attributes/users
- /um/attributes/users/attribute name
- /um/attributes/groups
- /um/attributes/groups/attribute name
Sample Code:
public class SampleTest {
public static void main(String[] args) {
try {
/**
/um/secure/users/profiles
/um/secure/attributes/groups
/um/secure/attributes/users/
**/
final String userName = "wasadmin";
final String password = "wasadmin";
HttpClient client = new HttpClient();
GetMethod get = new GetMethod ("http://localhost:10039/wps/mycontenthandler/!ut/p/um/secure/currentuser/profile");
Credentials defaultcreds = new UsernamePasswordCredentials(userName,password);
client.getState().setCredentials(null,null,defaultcreds);
get.setDoAuthentication(true);
// Open the URL: throws exception if not found
client.executeMethod(get);
InputStream inputStream = get.getResponseBodyAsStream();
System.out.println(convertStreamToString(inputStream));
} catch (MalformedURLException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
public static String convertStreamToString(InputStream inputStream) throws IOException {
if (inputStream != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
inputStream.close();
}
return sb.toString();
} else {
return "";
}
}
}
public static void main(String[] args) {
try {
/**
/um/secure/users/profiles
/um/secure/attributes/groups
/um/secure/attributes/users/
**/
final String userName = "wasadmin";
final String password = "wasadmin";
HttpClient client = new HttpClient();
GetMethod get = new GetMethod ("http://localhost:10039/wps/mycontenthandler/!ut/p/um/secure/currentuser/profile");
Credentials defaultcreds = new UsernamePasswordCredentials(userName,password);
client.getState().setCredentials(null,null,defaultcreds);
get.setDoAuthentication(true);
// Open the URL: throws exception if not found
client.executeMethod(get);
InputStream inputStream = get.getResponseBodyAsStream();
System.out.println(convertStreamToString(inputStream));
} catch (MalformedURLException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
public static String convertStreamToString(InputStream inputStream) throws IOException {
if (inputStream != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
inputStream.close();
}
return sb.toString();
} else {
return "";
}
}
}
In this example,i am able to get profile of "wasadmin".
Result XML
Click here to download the files
hello, the source file downloaded is a jar. How do I check source code? Could you re-upload or download link indicate the source. thanks
ReplyDeleteJorge ... Upload the file with source code
ReplyDeleteIts great post.
ReplyDeleteHow do we use put method to edit a user profile.
Lets say I want to edit user's last name. What would it require to get it done.
If you want to edit user's last name within portlet,you can use portlet client side programming.If you are using as standalone plain java application,then you need to Bulid and send XML to change User profile.I will post both approach next week.
ReplyDeleteThanks. I have portlet program through which I can edit user profile using puma portlet service.
ReplyDeletebut for this I need to login into portal and have to trigger portlet processAction.
Rather I want to have a stand alone app external to portal from where I can update the user information in bulk as and when needed.
It is not just the last name, I have certain LA attributes which updates periodic, so looking at the approach of creating input XML and update users in bulk.
Is it possible to upload sample program to use restful service to update profiles of multiple users at a time.
ReplyDeleteany further help please?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi Dillibabu,
ReplyDeleteThanks for the technote.It was very useful.
Can you please update the code for updating any attribute of a user using a plain java application.It will be of gr8 help to us and other blog members
Thanks in Advance!!!!!!!