1
2 package org.astrogrid.portal.cocoon.community;
3 import org.apache.avalon.framework.parameters.Parameters;
4 import org.apache.cocoon.acting.AbstractAction;
5 import org.apache.cocoon.environment.Request;
6 import org.apache.cocoon.environment.Session;
7 import org.apache.cocoon.environment.Redirector;
8 import org.apache.cocoon.environment.SourceResolver;
9 import org.apache.cocoon.environment.ObjectModelHelper;
10 //import org.astrogrid.community.common.CommunityConfig;
11 import java.util.Map;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 //import org.astrogrid.community.delegate.policy.AdministrationDelegate;
15
16 /***
17 *
18 * CredentialAction is a small custom cocoon Action object for handling the credentials page. Which consist of letting the
19 * user chose his/her credentials from a list of groups that come from a local or a remote community.
20 * @author Kevin Benson
21 *
22 */
23 public class CredentialAction extends AbstractAction
24 {
25 /***
26 * Switch for our debug statements.
27 *
28 */
29 public static boolean DEBUG_FLAG = true;
30
31 /***
32 * Cocoon param for the user param in the session.
33 *
34 */
35 public static final String USER_PARAM_NAME = "user" ;
36
37 private static final String PARAM_CREDENTIAL = "credential";
38
39 private static final String PARAM_MESSAGE = "message";
40
41 private static final String ACTION_GET_COMMUNITY_GROUPS = "communitygroups";
42
43 private static final String PARAM_COMMUNITY_LIST = "communitylist";
44
45 private static final String PARAM_COMMUNITY = "community";
46
47 private static final String PARAM_GROUP_LIST = "grouplist";
48
49 private static final String ACTION = "action";
50
51 private static final String ACTION_SET_GROUP = "setgroup";
52
53 /***
54 * Our action method.
55 *
56 */
57 public Map act(
58 Redirector redirector,
59 SourceResolver resolver,
60 Map objectModel,
61 String source,
62 Parameters params)
63 {
64
65 //
66 // Get our current request and session.
67 /*
68 Request request = ObjectModelHelper.getRequest(objectModel);
69 Session session = request.getSession();
70
71 String comm_account = (String)session.getAttribute("community_account");
72 if(comm_account == null || comm_account.length() <= 0) {
73 comm_account = (String)session.getAttribute("user");
74 }
75
76
77 String action = request.getParameter(ACTION);
78 if(DEBUG_FLAG) {
79 System.out.println("the action is = " + action);
80 }
81
82 AdministrationDelegate adminDelegate = new AdministrationDelegate();
83 ArrayList communityList = (ArrayList)session.getAttribute(PARAM_COMMUNITY_LIST);
84
85 if(communityList == null || communityList.size() <= 0) {
86 //call delegate to get the communities trusted by this local community.
87 try {
88 communityList = adminDelegate.getCommunityList();
89 }catch(Exception e) {
90 e.printStackTrace();
91 }
92 session.setAttribute(PARAM_COMMUNITY_LIST,communityList);
93 }
94
95 //Create a new HashMap for our results. Will be used to
96 //pass to the transformer (xsl page)
97 //Map results = new HashMap();
98
99 String community = (String)request.getParameter(PARAM_COMMUNITY);
100 if(community == null || community.length() <= 0) {
101 community = CommunityConfig.getCommunityName();
102 }
103
104 if(ACTION_SET_GROUP.equals(action)) {
105 session.setAttribute(PARAM_CREDENTIAL,(String)request.getParameter(PARAM_CREDENTIAL));
106 results.put(PARAM_CREDENTIAL,(String)request.getParameter(PARAM_CREDENTIAL));
107 }
108
109 try {
110 ArrayList groupList = adminDelegate.getAccountGroups(comm_account, community);
111 session.setAttribute(PARAM_GROUP_LIST,groupList);
112 }catch(Exception e) {
113 e.printStackTrace();
114 }
115
116 String credential = (String)session.getAttribute(PARAM_CREDENTIAL);
117 results.put(PARAM_CREDENTIAL,credential);
118 */
119 Map results = new HashMap();
120 return results;
121 }
122 }