OW2 Consortium contrail

Rev

Rev 2538 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2538 Rev 3040
Line 105... Line 105...
105
        }
105
        }
106
        else
106
        else
107
        {
107
        {
108
            try
108
            try
109
            {
109
            {
110
                ResultSet rs = db.query("select", "*", "user", "where username='" + username + "'");
-
 
111
                if(rs.next())
-
 
-
 
110
                isAdmin = VEPAccessControl.isAdmin(username);
-
 
111
                if(isAdmin)
112
                {
112
                {
113
                    int uid = rs.getInt("uid");
-
 
114
                    rs.close();
-
 
115
                    rs = db.query("select", "*", "ugroup", "where uid=" + uid + "");
-
 
116
                    String groupList = "";
-
 
-
 
113
                    ResultSet rs = db.query("select", "cid", "computenode", "");
117
                    while(rs.next())
114
                    while(rs.next())
118
                    {
115
                    {
119
                        groupList += rs.getString("gname") + ",";
-
 
120
                    }
-
 
121
                    groups = groupList.split(","); //the last index will be empty because of the trailing ,
-
 
122
                    logger.trace("GroupsList for user: " + username + " is: " + groupList);
-
 
123
                    for(int i=0; i<groups.length; i++)
-
 
124
                    {
-
 
125
                        if(groups[i].equalsIgnoreCase("admin") || groups[i].equalsIgnoreCase("cloudadministrator"))
-
 
126
                        {
-
 
127
                            isAdmin = true;
-
 
128
                            logger.trace("Setting isAdmin to true.");
-
 
129
                            break;
-
 
130
                        }
-
 
-
 
116
                        // read the result set
-
 
117
                        int nodeId = rs.getInt("cid");
-
 
118
                        arr.add("Computenode " + nodeId);
-
 
119
                        link.add("/host/" + nodeId);
-
 
120
                        count++;
131
                    }
121
                    }
132
                    rs.close();
122
                    rs.close();
133
                    if(isAdmin)
-
 
134
                    {
-
 
135
                        rs = db.query("select", "cid", "computenode", "");
-
 
136
                        while(rs.next())
-
 
137
                        {
-
 
138
                            // read the result set
-
 
139
                            int nodeId = rs.getInt("cid");
-
 
140
                            arr.add("Computenode " + nodeId);
-
 
141
                            link.add("/host/" + nodeId);
-
 
142
                            count++;
-
 
143
                        }
-
 
144
                        rs.close();
-
 
145
                        obj.put("hosts", arr);
-
 
146
                        obj.put("links", link);
-
 
147
                        obj.put("count", count);
-
 
148
                    }
-
 
149
                    else
-
 
150
                    {
-
 
151
                        this.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
-
 
152
                        obj.put("error", "CLIENT_ERROR_UNAUTHORIZED");
-
 
153
                    }
-
 
-
 
123
                    obj.put("hosts", arr);
-
 
124
                    obj.put("links", link);
-
 
125
                    obj.put("count", count);
154
                }
126
                }
155
                else
127
                else
156
                {
128
                {
157
                    this.setStatus(Status.CLIENT_ERROR_PRECONDITION_FAILED);
-
 
158
                    obj.put("error", "CLIENT_ERROR_PRECONDITION_FAILED");
-
 
-
 
129
                    this.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
-
 
130
                    obj.put("error", "CLIENT_ERROR_UNAUTHORIZED");
159
                }
131
                }
160
            }
132
            }
161
            catch(Exception ex)
133
            catch(Exception ex)
162
            {
134
            {
163
                obj.put("error", "SQL error occured.");
135
                obj.put("error", "SQL error occured.");
Line 186... Line 158...
186
        }
158
        }
187
        else
159
        else
188
        {
160
        {
189
            try
161
            try
190
            {
162
            {
191
                ResultSet rs = db.query("select", "*", "user", "where username='" + username + "'");
-
 
192
                if(rs.next())
-
 
-
 
163
                isAdmin = VEPAccessControl.isAdmin(username);
-
 
164
                if(isAdmin)
193
                {
165
                {
194
                    int uid = rs.getInt("uid");
-
 
195
                    rs.close();
-
 
196
                    rs = db.query("select", "*", "ugroup", "where uid=" + uid + "");
-
 
197
                    String groupList = "";
-
 
-
 
166
                    ResultSet rs = db.query("select", "cid", "computenode", "");
198
                    while(rs.next())
167
                    while(rs.next())
199
                    {
168
                    {
200
                        groupList += rs.getString("gname") + ",";
-
 
201
                    }
-
 
202
                    groups = groupList.split(","); //the last index will be empty because of the trailing ,
-
 
203
                    logger.trace("GroupsList for user: " + username + " is: " + groupList);
-
 
204
                    for(int i=0; i<groups.length; i++)
-
 
205
                    {
-
 
206
                        if(groups[i].equalsIgnoreCase("admin") || groups[i].equalsIgnoreCase("cloudadministrator"))
-
 
207
                        {
-
 
208
                            isAdmin = true;
-
 
209
                            logger.trace("Setting isAdmin to true.");
-
 
210
                            break;
-
 
211
                        }
-
 
-
 
169
                        // read the result set
-
 
170
                        int nodeId = rs.getInt("cid");
-
 
171
                        stringBuilder.append("<li>Computenode ").append(nodeId).append(" <a href='").append(nodeId).append("' title='details on computenode ").append(nodeId).append("'>/host/").append(rs.getInt("cid")).append("</a>");
-
 
172
                        count++;
212
                    }
173
                    }
213
                    rs.close();
174
                    rs.close();
214
                    if(isAdmin)
-
 
215
                    {
-
 
216
                        rs = db.query("select", "cid", "computenode", "");
-
 
217
                        while(rs.next())
-
 
218
                        {
-
 
219
                            // read the result set
-
 
220
                            int nodeId = rs.getInt("cid");
-
 
221
                            stringBuilder.append("<li>Computenode ").append(nodeId).append(" <a href='").append(nodeId).append("' title='details on computenode ").append(nodeId).append("'>/host/").append(rs.getInt("cid")).append("</a>");
-
 
222
                            count++;
-
 
223
                        }
-
 
224
                        rs.close();
-
 
225
                        stringBuilder.append("</ul>");
-
 
226
                    }
-
 
227
                    else
-
 
228
                    {
-
 
229
                        this.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
-
 
230
                        stringBuilder.append("</ul><b>Unauthorized user ... can not display host list.</b><br><br>");
-
 
231
                    }
-
 
-
 
175
                    stringBuilder.append("</ul>");
232
                }
176
                }
233
                else
177
                else
234
                {
178
                {
235
                    this.setStatus(Status.CLIENT_ERROR_PRECONDITION_FAILED);
-
 
236
                    stringBuilder.append("</ul><b>User not found ... can not display host list.</b><br><br>");
-
 
-
 
179
                    this.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
-
 
180
                    stringBuilder.append("</ul><b>Unauthorized user ... can not display host list.</b><br><br>");
237
                }
181
                }
238
            }
182
            }
239
            catch(Exception ex)
183
            catch(Exception ex)
240
            {
184
            {
-
 
185
                ex.printStackTrace(System.out);
241
                stringBuilder.append("</ul>");
186
                stringBuilder.append("</ul>");
242
                stringBuilder.append("<B>SQL Query Error!! Details of exception follows ...</B>");
187
                stringBuilder.append("<B>SQL Query Error!! Details of exception follows ...</B>");
243
                stringBuilder.append("<div style='border:1px;background:red;color:black;font-family:Times;font-size:9pt;'>");
188
                stringBuilder.append("<div style='border:1px;background:red;color:black;font-family:Times;font-size:9pt;'>");
244
                stringBuilder.append(ex.getMessage());
189
                stringBuilder.append(ex.getMessage());
245
                logger.debug("Exception caught: " + ex.getMessage());
190
                logger.debug("Exception caught: " + ex.getMessage());