1   /**
2    * Copyright (c) 2000-2008 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  
35  /**
36   * <a href="RoleServiceHttp.java.html"><b><i>View Source</i></b></a>
37   *
38   * <p>
39   * ServiceBuilder generated this class. Modifications in this class will be
40   * overwritten the next time is generated.
41   * </p>
42   *
43   * <p>
44   * This class provides a HTTP utility for the
45   * <code>com.liferay.portal.service.RoleServiceUtil</code> service
46   * 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>
49   * parameter.
50   * </p>
51   *
52   * <p>
53   * The benefits of using the HTTP utility is that it is fast and allows for
54   * tunneling without the cost of serializing to text. The drawback is that it
55   * only works with Java.
56   * </p>
57   *
58   * <p>
59   * Set the property <code>tunnel.servlet.hosts.allowed</code> in
60   * portal.properties to configure security.
61   * </p>
62   *
63   * <p>
64   * The HTTP utility is only generated for remote services.
65   * </p>
66   *
67   * @author Brian Wing Shun Chan
68   *
69   * @see com.liferay.portal.security.auth.HttpPrincipal
70   * @see com.liferay.portal.service.RoleServiceUtil
71   * @see com.liferay.portal.service.http.RoleServiceSoap
72   *
73   */
74  public class RoleServiceHttp {
75      public static com.liferay.portal.model.Role addRole(
76          HttpPrincipal httpPrincipal, java.lang.String name,
77          java.lang.String description, int type)
78          throws com.liferay.portal.SystemException,
79              com.liferay.portal.PortalException {
80          try {
81              Object paramObj0 = name;
82  
83              if (name == null) {
84                  paramObj0 = new NullWrapper("java.lang.String");
85              }
86  
87              Object paramObj1 = description;
88  
89              if (description == null) {
90                  paramObj1 = new NullWrapper("java.lang.String");
91              }
92  
93              Object paramObj2 = new IntegerWrapper(type);
94  
95              MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
96                      "addRole", new Object[] { paramObj0, paramObj1, paramObj2 });
97  
98              Object returnObj = null;
99  
100             try {
101                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
102             }
103             catch (Exception e) {
104                 if (e instanceof com.liferay.portal.SystemException) {
105                     throw (com.liferay.portal.SystemException)e;
106                 }
107 
108                 if (e instanceof com.liferay.portal.PortalException) {
109                     throw (com.liferay.portal.PortalException)e;
110                 }
111 
112                 throw new com.liferay.portal.SystemException(e);
113             }
114 
115             return (com.liferay.portal.model.Role)returnObj;
116         }
117         catch (com.liferay.portal.SystemException se) {
118             _log.error(se, se);
119 
120             throw se;
121         }
122     }
123 
124     public static void addUserRoles(HttpPrincipal httpPrincipal, long userId,
125         long[] roleIds)
126         throws com.liferay.portal.SystemException,
127             com.liferay.portal.PortalException {
128         try {
129             Object paramObj0 = new LongWrapper(userId);
130 
131             Object paramObj1 = roleIds;
132 
133             if (roleIds == null) {
134                 paramObj1 = new NullWrapper("[J");
135             }
136 
137             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
138                     "addUserRoles", new Object[] { paramObj0, paramObj1 });
139 
140             try {
141                 TunnelUtil.invoke(httpPrincipal, methodWrapper);
142             }
143             catch (Exception e) {
144                 if (e instanceof com.liferay.portal.SystemException) {
145                     throw (com.liferay.portal.SystemException)e;
146                 }
147 
148                 if (e instanceof com.liferay.portal.PortalException) {
149                     throw (com.liferay.portal.PortalException)e;
150                 }
151 
152                 throw new com.liferay.portal.SystemException(e);
153             }
154         }
155         catch (com.liferay.portal.SystemException se) {
156             _log.error(se, se);
157 
158             throw se;
159         }
160     }
161 
162     public static void deleteRole(HttpPrincipal httpPrincipal, long roleId)
163         throws com.liferay.portal.SystemException,
164             com.liferay.portal.PortalException {
165         try {
166             Object paramObj0 = new LongWrapper(roleId);
167 
168             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
169                     "deleteRole", new Object[] { paramObj0 });
170 
171             try {
172                 TunnelUtil.invoke(httpPrincipal, methodWrapper);
173             }
174             catch (Exception e) {
175                 if (e instanceof com.liferay.portal.SystemException) {
176                     throw (com.liferay.portal.SystemException)e;
177                 }
178 
179                 if (e instanceof com.liferay.portal.PortalException) {
180                     throw (com.liferay.portal.PortalException)e;
181                 }
182 
183                 throw new com.liferay.portal.SystemException(e);
184             }
185         }
186         catch (com.liferay.portal.SystemException se) {
187             _log.error(se, se);
188 
189             throw se;
190         }
191     }
192 
193     public static com.liferay.portal.model.Role getGroupRole(
194         HttpPrincipal httpPrincipal, long companyId, long groupId)
195         throws com.liferay.portal.SystemException,
196             com.liferay.portal.PortalException {
197         try {
198             Object paramObj0 = new LongWrapper(companyId);
199 
200             Object paramObj1 = new LongWrapper(groupId);
201 
202             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
203                     "getGroupRole", new Object[] { paramObj0, paramObj1 });
204 
205             Object returnObj = null;
206 
207             try {
208                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
209             }
210             catch (Exception e) {
211                 if (e instanceof com.liferay.portal.SystemException) {
212                     throw (com.liferay.portal.SystemException)e;
213                 }
214 
215                 if (e instanceof com.liferay.portal.PortalException) {
216                     throw (com.liferay.portal.PortalException)e;
217                 }
218 
219                 throw new com.liferay.portal.SystemException(e);
220             }
221 
222             return (com.liferay.portal.model.Role)returnObj;
223         }
224         catch (com.liferay.portal.SystemException se) {
225             _log.error(se, se);
226 
227             throw se;
228         }
229     }
230 
231     public static java.util.List<com.liferay.portal.model.Role> getGroupRoles(
232         HttpPrincipal httpPrincipal, long groupId)
233         throws com.liferay.portal.SystemException,
234             com.liferay.portal.PortalException {
235         try {
236             Object paramObj0 = new LongWrapper(groupId);
237 
238             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
239                     "getGroupRoles", new Object[] { paramObj0 });
240 
241             Object returnObj = null;
242 
243             try {
244                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
245             }
246             catch (Exception e) {
247                 if (e instanceof com.liferay.portal.SystemException) {
248                     throw (com.liferay.portal.SystemException)e;
249                 }
250 
251                 if (e instanceof com.liferay.portal.PortalException) {
252                     throw (com.liferay.portal.PortalException)e;
253                 }
254 
255                 throw new com.liferay.portal.SystemException(e);
256             }
257 
258             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
259         }
260         catch (com.liferay.portal.SystemException se) {
261             _log.error(se, se);
262 
263             throw se;
264         }
265     }
266 
267     public static com.liferay.portal.model.Role getRole(
268         HttpPrincipal httpPrincipal, long roleId)
269         throws com.liferay.portal.SystemException,
270             com.liferay.portal.PortalException {
271         try {
272             Object paramObj0 = new LongWrapper(roleId);
273 
274             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
275                     "getRole", new Object[] { paramObj0 });
276 
277             Object returnObj = null;
278 
279             try {
280                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
281             }
282             catch (Exception e) {
283                 if (e instanceof com.liferay.portal.SystemException) {
284                     throw (com.liferay.portal.SystemException)e;
285                 }
286 
287                 if (e instanceof com.liferay.portal.PortalException) {
288                     throw (com.liferay.portal.PortalException)e;
289                 }
290 
291                 throw new com.liferay.portal.SystemException(e);
292             }
293 
294             return (com.liferay.portal.model.Role)returnObj;
295         }
296         catch (com.liferay.portal.SystemException se) {
297             _log.error(se, se);
298 
299             throw se;
300         }
301     }
302 
303     public static com.liferay.portal.model.Role getRole(
304         HttpPrincipal httpPrincipal, long companyId, java.lang.String name)
305         throws com.liferay.portal.SystemException,
306             com.liferay.portal.PortalException {
307         try {
308             Object paramObj0 = new LongWrapper(companyId);
309 
310             Object paramObj1 = name;
311 
312             if (name == null) {
313                 paramObj1 = new NullWrapper("java.lang.String");
314             }
315 
316             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
317                     "getRole", new Object[] { paramObj0, paramObj1 });
318 
319             Object returnObj = null;
320 
321             try {
322                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
323             }
324             catch (Exception e) {
325                 if (e instanceof com.liferay.portal.SystemException) {
326                     throw (com.liferay.portal.SystemException)e;
327                 }
328 
329                 if (e instanceof com.liferay.portal.PortalException) {
330                     throw (com.liferay.portal.PortalException)e;
331                 }
332 
333                 throw new com.liferay.portal.SystemException(e);
334             }
335 
336             return (com.liferay.portal.model.Role)returnObj;
337         }
338         catch (com.liferay.portal.SystemException se) {
339             _log.error(se, se);
340 
341             throw se;
342         }
343     }
344 
345     public static java.util.List<com.liferay.portal.model.Role> getUserGroupRoles(
346         HttpPrincipal httpPrincipal, long userId, long groupId)
347         throws com.liferay.portal.SystemException,
348             com.liferay.portal.PortalException {
349         try {
350             Object paramObj0 = new LongWrapper(userId);
351 
352             Object paramObj1 = new LongWrapper(groupId);
353 
354             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
355                     "getUserGroupRoles", new Object[] { paramObj0, paramObj1 });
356 
357             Object returnObj = null;
358 
359             try {
360                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
361             }
362             catch (Exception e) {
363                 if (e instanceof com.liferay.portal.SystemException) {
364                     throw (com.liferay.portal.SystemException)e;
365                 }
366 
367                 if (e instanceof com.liferay.portal.PortalException) {
368                     throw (com.liferay.portal.PortalException)e;
369                 }
370 
371                 throw new com.liferay.portal.SystemException(e);
372             }
373 
374             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
375         }
376         catch (com.liferay.portal.SystemException se) {
377             _log.error(se, se);
378 
379             throw se;
380         }
381     }
382 
383     public static java.util.List<com.liferay.portal.model.Role> getUserRelatedRoles(
384         HttpPrincipal httpPrincipal, long userId,
385         java.util.List<com.liferay.portal.model.Group> groups)
386         throws com.liferay.portal.SystemException,
387             com.liferay.portal.PortalException {
388         try {
389             Object paramObj0 = new LongWrapper(userId);
390 
391             Object paramObj1 = groups;
392 
393             if (groups == null) {
394                 paramObj1 = new NullWrapper("java.util.List");
395             }
396 
397             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
398                     "getUserRelatedRoles", new Object[] { paramObj0, paramObj1 });
399 
400             Object returnObj = null;
401 
402             try {
403                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
404             }
405             catch (Exception e) {
406                 if (e instanceof com.liferay.portal.SystemException) {
407                     throw (com.liferay.portal.SystemException)e;
408                 }
409 
410                 if (e instanceof com.liferay.portal.PortalException) {
411                     throw (com.liferay.portal.PortalException)e;
412                 }
413 
414                 throw new com.liferay.portal.SystemException(e);
415             }
416 
417             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
418         }
419         catch (com.liferay.portal.SystemException se) {
420             _log.error(se, se);
421 
422             throw se;
423         }
424     }
425 
426     public static java.util.List<com.liferay.portal.model.Role> getUserRoles(
427         HttpPrincipal httpPrincipal, long userId)
428         throws com.liferay.portal.SystemException,
429             com.liferay.portal.PortalException {
430         try {
431             Object paramObj0 = new LongWrapper(userId);
432 
433             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
434                     "getUserRoles", new Object[] { paramObj0 });
435 
436             Object returnObj = null;
437 
438             try {
439                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
440             }
441             catch (Exception e) {
442                 if (e instanceof com.liferay.portal.SystemException) {
443                     throw (com.liferay.portal.SystemException)e;
444                 }
445 
446                 if (e instanceof com.liferay.portal.PortalException) {
447                     throw (com.liferay.portal.PortalException)e;
448                 }
449 
450                 throw new com.liferay.portal.SystemException(e);
451             }
452 
453             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
454         }
455         catch (com.liferay.portal.SystemException se) {
456             _log.error(se, se);
457 
458             throw se;
459         }
460     }
461 
462     public static boolean hasUserRole(HttpPrincipal httpPrincipal, long userId,
463         long companyId, java.lang.String name, boolean inherited)
464         throws com.liferay.portal.SystemException,
465             com.liferay.portal.PortalException {
466         try {
467             Object paramObj0 = new LongWrapper(userId);
468 
469             Object paramObj1 = new LongWrapper(companyId);
470 
471             Object paramObj2 = name;
472 
473             if (name == null) {
474                 paramObj2 = new NullWrapper("java.lang.String");
475             }
476 
477             Object paramObj3 = new BooleanWrapper(inherited);
478 
479             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
480                     "hasUserRole",
481                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
482 
483             Object returnObj = null;
484 
485             try {
486                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
487             }
488             catch (Exception e) {
489                 if (e instanceof com.liferay.portal.SystemException) {
490                     throw (com.liferay.portal.SystemException)e;
491                 }
492 
493                 if (e instanceof com.liferay.portal.PortalException) {
494                     throw (com.liferay.portal.PortalException)e;
495                 }
496 
497                 throw new com.liferay.portal.SystemException(e);
498             }
499 
500             return ((Boolean)returnObj).booleanValue();
501         }
502         catch (com.liferay.portal.SystemException se) {
503             _log.error(se, se);
504 
505             throw se;
506         }
507     }
508 
509     public static boolean hasUserRoles(HttpPrincipal httpPrincipal,
510         long userId, long companyId, java.lang.String[] names, boolean inherited)
511         throws com.liferay.portal.SystemException,
512             com.liferay.portal.PortalException {
513         try {
514             Object paramObj0 = new LongWrapper(userId);
515 
516             Object paramObj1 = new LongWrapper(companyId);
517 
518             Object paramObj2 = names;
519 
520             if (names == null) {
521                 paramObj2 = new NullWrapper("[Ljava.lang.String;");
522             }
523 
524             Object paramObj3 = new BooleanWrapper(inherited);
525 
526             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
527                     "hasUserRoles",
528                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
529 
530             Object returnObj = null;
531 
532             try {
533                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
534             }
535             catch (Exception e) {
536                 if (e instanceof com.liferay.portal.SystemException) {
537                     throw (com.liferay.portal.SystemException)e;
538                 }
539 
540                 if (e instanceof com.liferay.portal.PortalException) {
541                     throw (com.liferay.portal.PortalException)e;
542                 }
543 
544                 throw new com.liferay.portal.SystemException(e);
545             }
546 
547             return ((Boolean)returnObj).booleanValue();
548         }
549         catch (com.liferay.portal.SystemException se) {
550             _log.error(se, se);
551 
552             throw se;
553         }
554     }
555 
556     public static void unsetUserRoles(HttpPrincipal httpPrincipal, long userId,
557         long[] roleIds)
558         throws com.liferay.portal.SystemException,
559             com.liferay.portal.PortalException {
560         try {
561             Object paramObj0 = new LongWrapper(userId);
562 
563             Object paramObj1 = roleIds;
564 
565             if (roleIds == null) {
566                 paramObj1 = new NullWrapper("[J");
567             }
568 
569             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
570                     "unsetUserRoles", new Object[] { paramObj0, paramObj1 });
571 
572             try {
573                 TunnelUtil.invoke(httpPrincipal, methodWrapper);
574             }
575             catch (Exception e) {
576                 if (e instanceof com.liferay.portal.SystemException) {
577                     throw (com.liferay.portal.SystemException)e;
578                 }
579 
580                 if (e instanceof com.liferay.portal.PortalException) {
581                     throw (com.liferay.portal.PortalException)e;
582                 }
583 
584                 throw new com.liferay.portal.SystemException(e);
585             }
586         }
587         catch (com.liferay.portal.SystemException se) {
588             _log.error(se, se);
589 
590             throw se;
591         }
592     }
593 
594     public static com.liferay.portal.model.Role updateRole(
595         HttpPrincipal httpPrincipal, long roleId, java.lang.String name,
596         java.lang.String description)
597         throws com.liferay.portal.SystemException,
598             com.liferay.portal.PortalException {
599         try {
600             Object paramObj0 = new LongWrapper(roleId);
601 
602             Object paramObj1 = name;
603 
604             if (name == null) {
605                 paramObj1 = new NullWrapper("java.lang.String");
606             }
607 
608             Object paramObj2 = description;
609 
610             if (description == null) {
611                 paramObj2 = new NullWrapper("java.lang.String");
612             }
613 
614             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
615                     "updateRole",
616                     new Object[] { paramObj0, paramObj1, paramObj2 });
617 
618             Object returnObj = null;
619 
620             try {
621                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
622             }
623             catch (Exception e) {
624                 if (e instanceof com.liferay.portal.SystemException) {
625                     throw (com.liferay.portal.SystemException)e;
626                 }
627 
628                 if (e instanceof com.liferay.portal.PortalException) {
629                     throw (com.liferay.portal.PortalException)e;
630                 }
631 
632                 throw new com.liferay.portal.SystemException(e);
633             }
634 
635             return (com.liferay.portal.model.Role)returnObj;
636         }
637         catch (com.liferay.portal.SystemException se) {
638             _log.error(se, se);
639 
640             throw se;
641         }
642     }
643 
644     private static Log _log = LogFactoryUtil.getLog(RoleServiceHttp.class);
645 }