1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.http;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.BooleanWrapper;
28  import com.liferay.portal.kernel.util.IntegerWrapper;
29  import com.liferay.portal.kernel.util.LongWrapper;
30  import com.liferay.portal.kernel.util.MethodWrapper;
31  import com.liferay.portal.kernel.util.NullWrapper;
32  import com.liferay.portal.security.auth.HttpPrincipal;
33  import com.liferay.portal.service.RoleServiceUtil;
34  import com.liferay.portal.service.http.TunnelUtil;
35  
36  /**
37   * <a href="RoleServiceHttp.java.html"><b><i>View Source</i></b></a>
38   *
39   * <p>
40   * ServiceBuilder generated this class. Modifications in this class will be overwritten
41   * the next time is generated.
42   * </p>
43   *
44   * <p>
45   * This class provides a HTTP utility for the <code>com.liferay.portal.service.RoleServiceUtil</code>
46   * service utility. The static methods of this class calls the same methods of the
47   * service utility. However, the signatures are different because it requires an
48   * additional <code>com.liferay.portal.security.auth.HttpPrincipal</code> parameter.
49   * </p>
50   *
51   * <p>
52   * The benefits of using the HTTP utility is that it is fast and allows for tunneling
53   * without the cost of serializing to text. The drawback is that it only works with
54   * Java.
55   * </p>
56   *
57   * <p>
58   * Set the property <code>tunnel.servlet.hosts.allowed</code> in portal.properties
59   * to configure security.
60   * </p>
61   *
62   * <p>
63   * The HTTP utility is only generated for remote services.
64   * </p>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   * @see com.liferay.portal.security.auth.HttpPrincipal
69   * @see com.liferay.portal.service.RoleServiceUtil
70   * @see com.liferay.portal.service.http.RoleServiceSoap
71   *
72   */
73  public class RoleServiceHttp {
74      public static com.liferay.portal.model.Role addRole(
75          HttpPrincipal httpPrincipal, java.lang.String name, int type)
76          throws com.liferay.portal.SystemException, 
77              com.liferay.portal.PortalException {
78          try {
79              Object paramObj0 = name;
80  
81              if (name == null) {
82                  paramObj0 = new NullWrapper("java.lang.String");
83              }
84  
85              Object paramObj1 = new IntegerWrapper(type);
86              MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
87                      "addRole", new Object[] { paramObj0, paramObj1 });
88              Object returnObj = null;
89  
90              try {
91                  returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
92              }
93              catch (Exception e) {
94                  if (e instanceof com.liferay.portal.SystemException) {
95                      throw (com.liferay.portal.SystemException)e;
96                  }
97  
98                  if (e instanceof com.liferay.portal.PortalException) {
99                      throw (com.liferay.portal.PortalException)e;
100                 }
101 
102                 throw new com.liferay.portal.SystemException(e);
103             }
104 
105             return (com.liferay.portal.model.Role)returnObj;
106         }
107         catch (com.liferay.portal.SystemException se) {
108             _log.error(se, se);
109             throw se;
110         }
111     }
112 
113     public static void deleteRole(HttpPrincipal httpPrincipal, long roleId)
114         throws com.liferay.portal.SystemException, 
115             com.liferay.portal.PortalException {
116         try {
117             Object paramObj0 = new LongWrapper(roleId);
118             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
119                     "deleteRole", new Object[] { paramObj0 });
120 
121             try {
122                 TunnelUtil.invoke(httpPrincipal, methodWrapper);
123             }
124             catch (Exception e) {
125                 if (e instanceof com.liferay.portal.SystemException) {
126                     throw (com.liferay.portal.SystemException)e;
127                 }
128 
129                 if (e instanceof com.liferay.portal.PortalException) {
130                     throw (com.liferay.portal.PortalException)e;
131                 }
132 
133                 throw new com.liferay.portal.SystemException(e);
134             }
135         }
136         catch (com.liferay.portal.SystemException se) {
137             _log.error(se, se);
138             throw se;
139         }
140     }
141 
142     public static com.liferay.portal.model.Role getGroupRole(
143         HttpPrincipal httpPrincipal, long companyId, long groupId)
144         throws com.liferay.portal.SystemException, 
145             com.liferay.portal.PortalException {
146         try {
147             Object paramObj0 = new LongWrapper(companyId);
148             Object paramObj1 = new LongWrapper(groupId);
149             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
150                     "getGroupRole", new Object[] { paramObj0, paramObj1 });
151             Object returnObj = null;
152 
153             try {
154                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
155             }
156             catch (Exception e) {
157                 if (e instanceof com.liferay.portal.SystemException) {
158                     throw (com.liferay.portal.SystemException)e;
159                 }
160 
161                 if (e instanceof com.liferay.portal.PortalException) {
162                     throw (com.liferay.portal.PortalException)e;
163                 }
164 
165                 throw new com.liferay.portal.SystemException(e);
166             }
167 
168             return (com.liferay.portal.model.Role)returnObj;
169         }
170         catch (com.liferay.portal.SystemException se) {
171             _log.error(se, se);
172             throw se;
173         }
174     }
175 
176     public static java.util.List getGroupRoles(HttpPrincipal httpPrincipal,
177         long groupId)
178         throws com.liferay.portal.SystemException, 
179             com.liferay.portal.PortalException {
180         try {
181             Object paramObj0 = new LongWrapper(groupId);
182             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
183                     "getGroupRoles", new Object[] { paramObj0 });
184             Object returnObj = null;
185 
186             try {
187                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
188             }
189             catch (Exception e) {
190                 if (e instanceof com.liferay.portal.SystemException) {
191                     throw (com.liferay.portal.SystemException)e;
192                 }
193 
194                 if (e instanceof com.liferay.portal.PortalException) {
195                     throw (com.liferay.portal.PortalException)e;
196                 }
197 
198                 throw new com.liferay.portal.SystemException(e);
199             }
200 
201             return (java.util.List)returnObj;
202         }
203         catch (com.liferay.portal.SystemException se) {
204             _log.error(se, se);
205             throw se;
206         }
207     }
208 
209     public static com.liferay.portal.model.Role getRole(
210         HttpPrincipal httpPrincipal, long roleId)
211         throws com.liferay.portal.SystemException, 
212             com.liferay.portal.PortalException {
213         try {
214             Object paramObj0 = new LongWrapper(roleId);
215             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
216                     "getRole", new Object[] { paramObj0 });
217             Object returnObj = null;
218 
219             try {
220                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
221             }
222             catch (Exception e) {
223                 if (e instanceof com.liferay.portal.SystemException) {
224                     throw (com.liferay.portal.SystemException)e;
225                 }
226 
227                 if (e instanceof com.liferay.portal.PortalException) {
228                     throw (com.liferay.portal.PortalException)e;
229                 }
230 
231                 throw new com.liferay.portal.SystemException(e);
232             }
233 
234             return (com.liferay.portal.model.Role)returnObj;
235         }
236         catch (com.liferay.portal.SystemException se) {
237             _log.error(se, se);
238             throw se;
239         }
240     }
241 
242     public static com.liferay.portal.model.Role getRole(
243         HttpPrincipal httpPrincipal, long companyId, java.lang.String name)
244         throws com.liferay.portal.SystemException, 
245             com.liferay.portal.PortalException {
246         try {
247             Object paramObj0 = new LongWrapper(companyId);
248             Object paramObj1 = name;
249 
250             if (name == null) {
251                 paramObj1 = new NullWrapper("java.lang.String");
252             }
253 
254             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
255                     "getRole", new Object[] { paramObj0, paramObj1 });
256             Object returnObj = null;
257 
258             try {
259                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
260             }
261             catch (Exception e) {
262                 if (e instanceof com.liferay.portal.SystemException) {
263                     throw (com.liferay.portal.SystemException)e;
264                 }
265 
266                 if (e instanceof com.liferay.portal.PortalException) {
267                     throw (com.liferay.portal.PortalException)e;
268                 }
269 
270                 throw new com.liferay.portal.SystemException(e);
271             }
272 
273             return (com.liferay.portal.model.Role)returnObj;
274         }
275         catch (com.liferay.portal.SystemException se) {
276             _log.error(se, se);
277             throw se;
278         }
279     }
280 
281     public static java.util.List getUserGroupRoles(
282         HttpPrincipal httpPrincipal, long userId, long groupId)
283         throws com.liferay.portal.SystemException, 
284             com.liferay.portal.PortalException {
285         try {
286             Object paramObj0 = new LongWrapper(userId);
287             Object paramObj1 = new LongWrapper(groupId);
288             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
289                     "getUserGroupRoles", new Object[] { paramObj0, paramObj1 });
290             Object returnObj = null;
291 
292             try {
293                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
294             }
295             catch (Exception e) {
296                 if (e instanceof com.liferay.portal.SystemException) {
297                     throw (com.liferay.portal.SystemException)e;
298                 }
299 
300                 if (e instanceof com.liferay.portal.PortalException) {
301                     throw (com.liferay.portal.PortalException)e;
302                 }
303 
304                 throw new com.liferay.portal.SystemException(e);
305             }
306 
307             return (java.util.List)returnObj;
308         }
309         catch (com.liferay.portal.SystemException se) {
310             _log.error(se, se);
311             throw se;
312         }
313     }
314 
315     public static java.util.List getUserRelatedRoles(
316         HttpPrincipal httpPrincipal, long userId, java.util.List groups)
317         throws com.liferay.portal.SystemException, 
318             com.liferay.portal.PortalException {
319         try {
320             Object paramObj0 = new LongWrapper(userId);
321             Object paramObj1 = groups;
322 
323             if (groups == null) {
324                 paramObj1 = new NullWrapper("java.util.List");
325             }
326 
327             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
328                     "getUserRelatedRoles", new Object[] { paramObj0, paramObj1 });
329             Object returnObj = null;
330 
331             try {
332                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
333             }
334             catch (Exception e) {
335                 if (e instanceof com.liferay.portal.SystemException) {
336                     throw (com.liferay.portal.SystemException)e;
337                 }
338 
339                 if (e instanceof com.liferay.portal.PortalException) {
340                     throw (com.liferay.portal.PortalException)e;
341                 }
342 
343                 throw new com.liferay.portal.SystemException(e);
344             }
345 
346             return (java.util.List)returnObj;
347         }
348         catch (com.liferay.portal.SystemException se) {
349             _log.error(se, se);
350             throw se;
351         }
352     }
353 
354     public static java.util.List getUserRoles(HttpPrincipal httpPrincipal,
355         long userId)
356         throws com.liferay.portal.SystemException, 
357             com.liferay.portal.PortalException {
358         try {
359             Object paramObj0 = new LongWrapper(userId);
360             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
361                     "getUserRoles", new Object[] { paramObj0 });
362             Object returnObj = null;
363 
364             try {
365                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
366             }
367             catch (Exception e) {
368                 if (e instanceof com.liferay.portal.SystemException) {
369                     throw (com.liferay.portal.SystemException)e;
370                 }
371 
372                 if (e instanceof com.liferay.portal.PortalException) {
373                     throw (com.liferay.portal.PortalException)e;
374                 }
375 
376                 throw new com.liferay.portal.SystemException(e);
377             }
378 
379             return (java.util.List)returnObj;
380         }
381         catch (com.liferay.portal.SystemException se) {
382             _log.error(se, se);
383             throw se;
384         }
385     }
386 
387     public static boolean hasUserRole(HttpPrincipal httpPrincipal, long userId,
388         long companyId, java.lang.String name, boolean inherited)
389         throws com.liferay.portal.SystemException, 
390             com.liferay.portal.PortalException {
391         try {
392             Object paramObj0 = new LongWrapper(userId);
393             Object paramObj1 = new LongWrapper(companyId);
394             Object paramObj2 = name;
395 
396             if (name == null) {
397                 paramObj2 = new NullWrapper("java.lang.String");
398             }
399 
400             Object paramObj3 = new BooleanWrapper(inherited);
401             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
402                     "hasUserRole",
403                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
404             Object returnObj = null;
405 
406             try {
407                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
408             }
409             catch (Exception e) {
410                 if (e instanceof com.liferay.portal.SystemException) {
411                     throw (com.liferay.portal.SystemException)e;
412                 }
413 
414                 if (e instanceof com.liferay.portal.PortalException) {
415                     throw (com.liferay.portal.PortalException)e;
416                 }
417 
418                 throw new com.liferay.portal.SystemException(e);
419             }
420 
421             return ((Boolean)returnObj).booleanValue();
422         }
423         catch (com.liferay.portal.SystemException se) {
424             _log.error(se, se);
425             throw se;
426         }
427     }
428 
429     public static boolean hasUserRoles(HttpPrincipal httpPrincipal,
430         long userId, long companyId, java.lang.String[] names, boolean inherited)
431         throws com.liferay.portal.SystemException, 
432             com.liferay.portal.PortalException {
433         try {
434             Object paramObj0 = new LongWrapper(userId);
435             Object paramObj1 = new LongWrapper(companyId);
436             Object paramObj2 = names;
437 
438             if (names == null) {
439                 paramObj2 = new NullWrapper("[Ljava.lang.String;");
440             }
441 
442             Object paramObj3 = new BooleanWrapper(inherited);
443             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
444                     "hasUserRoles",
445                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
446             Object returnObj = null;
447 
448             try {
449                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
450             }
451             catch (Exception e) {
452                 if (e instanceof com.liferay.portal.SystemException) {
453                     throw (com.liferay.portal.SystemException)e;
454                 }
455 
456                 if (e instanceof com.liferay.portal.PortalException) {
457                     throw (com.liferay.portal.PortalException)e;
458                 }
459 
460                 throw new com.liferay.portal.SystemException(e);
461             }
462 
463             return ((Boolean)returnObj).booleanValue();
464         }
465         catch (com.liferay.portal.SystemException se) {
466             _log.error(se, se);
467             throw se;
468         }
469     }
470 
471     public static com.liferay.portal.model.Role updateRole(
472         HttpPrincipal httpPrincipal, long roleId, java.lang.String name)
473         throws com.liferay.portal.SystemException, 
474             com.liferay.portal.PortalException {
475         try {
476             Object paramObj0 = new LongWrapper(roleId);
477             Object paramObj1 = name;
478 
479             if (name == null) {
480                 paramObj1 = new NullWrapper("java.lang.String");
481             }
482 
483             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
484                     "updateRole", new Object[] { paramObj0, paramObj1 });
485             Object returnObj = null;
486 
487             try {
488                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
489             }
490             catch (Exception e) {
491                 if (e instanceof com.liferay.portal.SystemException) {
492                     throw (com.liferay.portal.SystemException)e;
493                 }
494 
495                 if (e instanceof com.liferay.portal.PortalException) {
496                     throw (com.liferay.portal.PortalException)e;
497                 }
498 
499                 throw new com.liferay.portal.SystemException(e);
500             }
501 
502             return (com.liferay.portal.model.Role)returnObj;
503         }
504         catch (com.liferay.portal.SystemException se) {
505             _log.error(se, se);
506             throw se;
507         }
508     }
509 
510     private static Log _log = LogFactoryUtil.getLog(RoleServiceHttp.class);
511 }