01: package com.sun.portal.taskadmin.test;
02:
03: import java.util.Iterator;
04: import java.util.Collection;
05: import java.util.Map;
06: import java.util.HashMap;
07: import java.util.List;
08: import java.util.ArrayList;
09: import java.util.Hashtable;
10: import java.util.Set;
11:
12: import java.net.URL;
13:
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16:
17: import com.sun.portal.providers.ProfileProviderAdapter;
18: import com.sun.portal.providers.ProviderException;
19: import com.sun.portal.providers.context.PropertiesFilter;
20: import com.sun.portal.providers.context.ProviderContext;
21: import com.sun.portal.providers.context.ProviderContextException;
22:
23: import com.sun.portal.taskadmin.UserTaskAdmin;
24: import com.sun.portal.taskadmin.TaskAdminException;
25:
26: public class TaskAdminUserTestProvider extends ProfileProviderAdapter {
27:
28: private UserTaskAdmin uta = null;
29: private static final String LIST_SEPARATOR = "|";
30:
31: public void init(String n, HttpServletRequest req)
32: throws ProviderException {
33: super .init(n, req);
34: try {
35: uta = new UserTaskAdmin(req);
36: } catch (TaskAdminException tae) {
37: throw new ProviderException("cannot initialize TaskAdmin",
38: tae);
39: }
40: }
41:
42: public StringBuffer getContent(HttpServletRequest req,
43: HttpServletResponse res) throws ProviderException {
44:
45: Hashtable tags = new Hashtable();
46: try {
47:
48: Set roles = uta.getBaseDNs();
49: Set users = uta.getUserDNs();
50: tags.put("roles", "Roles:" + getCollectionAsString(roles));
51: tags.put("users", "Users:" + getCollectionAsString(users));
52:
53: boolean aFlag = uta.assignRole(
54: "uid=jdcuadmin,ou=People,dc=india,dc=sun,dc=com",
55: "cn=JDC,dc=india,dc=sun,dc=com");
56: tags.put("assignStatus", "AssignStatus:" + aFlag);
57:
58: boolean rFlag = uta.removeRole(
59: "uid=jdcuadmin,ou=People,dc=india,dc=sun,dc=com",
60: "cn=JDC,dc=india,dc=sun,dc=com");
61: tags.put("removeStatus", "removeStatus:" + rFlag);
62: Set jdcusers = uta.searchUsers("jdc*");
63: tags.put("jdcusers", "Users with filter JDC*:"
64: + getCollectionAsString(jdcusers));
65: } catch (TaskAdminException tae) {
66: throw new ProviderException("error in taskadmin", tae);
67: }
68:
69: StringBuffer b = getTemplate("content.template", tags);
70: return b;
71: }
72:
73: private String getCollectionAsString(Collection c) {
74: StringBuffer sb = new StringBuffer();
75: Iterator i = c.iterator();
76: while (i.hasNext()) {
77: String s = (String) i.next();
78: sb.append(s).append(LIST_SEPARATOR);
79:
80: }
81: return sb.toString();
82: }
83:
84: }
|