1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.PortalException,
79              com.liferay.portal.SystemException {
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.PortalException) {
105                     throw (com.liferay.portal.PortalException)e;
106                 }
107 
108                 if (e instanceof com.liferay.portal.SystemException) {
109                     throw (com.liferay.portal.SystemException)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.PortalException,
127             com.liferay.portal.SystemException {
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.PortalException) {
145                     throw (com.liferay.portal.PortalException)e;
146                 }
147 
148                 if (e instanceof com.liferay.portal.SystemException) {
149                     throw (com.liferay.portal.SystemException)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.PortalException,
164             com.liferay.portal.SystemException {
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.PortalException) {
176                     throw (com.liferay.portal.PortalException)e;
177                 }
178 
179                 if (e instanceof com.liferay.portal.SystemException) {
180                     throw (com.liferay.portal.SystemException)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.PortalException,
196             com.liferay.portal.SystemException {
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.PortalException) {
212                     throw (com.liferay.portal.PortalException)e;
213                 }
214 
215                 if (e instanceof com.liferay.portal.SystemException) {
216                     throw (com.liferay.portal.SystemException)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         try {
235             Object paramObj0 = new LongWrapper(groupId);
236 
237             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
238                     "getGroupRoles", new Object[] { paramObj0 });
239 
240             Object returnObj = null;
241 
242             try {
243                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
244             }
245             catch (Exception e) {
246                 if (e instanceof com.liferay.portal.SystemException) {
247                     throw (com.liferay.portal.SystemException)e;
248                 }
249 
250                 throw new com.liferay.portal.SystemException(e);
251             }
252 
253             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
254         }
255         catch (com.liferay.portal.SystemException se) {
256             _log.error(se, se);
257 
258             throw se;
259         }
260     }
261 
262     public static com.liferay.portal.model.Role getRole(
263         HttpPrincipal httpPrincipal, long roleId)
264         throws com.liferay.portal.PortalException,
265             com.liferay.portal.SystemException {
266         try {
267             Object paramObj0 = new LongWrapper(roleId);
268 
269             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
270                     "getRole", new Object[] { paramObj0 });
271 
272             Object returnObj = null;
273 
274             try {
275                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
276             }
277             catch (Exception e) {
278                 if (e instanceof com.liferay.portal.PortalException) {
279                     throw (com.liferay.portal.PortalException)e;
280                 }
281 
282                 if (e instanceof com.liferay.portal.SystemException) {
283                     throw (com.liferay.portal.SystemException)e;
284                 }
285 
286                 throw new com.liferay.portal.SystemException(e);
287             }
288 
289             return (com.liferay.portal.model.Role)returnObj;
290         }
291         catch (com.liferay.portal.SystemException se) {
292             _log.error(se, se);
293 
294             throw se;
295         }
296     }
297 
298     public static com.liferay.portal.model.Role getRole(
299         HttpPrincipal httpPrincipal, long companyId, java.lang.String name)
300         throws com.liferay.portal.PortalException,
301             com.liferay.portal.SystemException {
302         try {
303             Object paramObj0 = new LongWrapper(companyId);
304 
305             Object paramObj1 = name;
306 
307             if (name == null) {
308                 paramObj1 = new NullWrapper("java.lang.String");
309             }
310 
311             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
312                     "getRole", new Object[] { paramObj0, paramObj1 });
313 
314             Object returnObj = null;
315 
316             try {
317                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
318             }
319             catch (Exception e) {
320                 if (e instanceof com.liferay.portal.PortalException) {
321                     throw (com.liferay.portal.PortalException)e;
322                 }
323 
324                 if (e instanceof com.liferay.portal.SystemException) {
325                     throw (com.liferay.portal.SystemException)e;
326                 }
327 
328                 throw new com.liferay.portal.SystemException(e);
329             }
330 
331             return (com.liferay.portal.model.Role)returnObj;
332         }
333         catch (com.liferay.portal.SystemException se) {
334             _log.error(se, se);
335 
336             throw se;
337         }
338     }
339 
340     public static java.util.List<com.liferay.portal.model.Role> getUserGroupGroupRoles(
341         HttpPrincipal httpPrincipal, long userId, long groupId)
342         throws com.liferay.portal.SystemException {
343         try {
344             Object paramObj0 = new LongWrapper(userId);
345 
346             Object paramObj1 = new LongWrapper(groupId);
347 
348             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
349                     "getUserGroupGroupRoles",
350                     new Object[] { paramObj0, paramObj1 });
351 
352             Object returnObj = null;
353 
354             try {
355                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
356             }
357             catch (Exception e) {
358                 if (e instanceof com.liferay.portal.SystemException) {
359                     throw (com.liferay.portal.SystemException)e;
360                 }
361 
362                 throw new com.liferay.portal.SystemException(e);
363             }
364 
365             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
366         }
367         catch (com.liferay.portal.SystemException se) {
368             _log.error(se, se);
369 
370             throw se;
371         }
372     }
373 
374     public static java.util.List<com.liferay.portal.model.Role> getUserGroupRoles(
375         HttpPrincipal httpPrincipal, long userId, long groupId)
376         throws com.liferay.portal.SystemException {
377         try {
378             Object paramObj0 = new LongWrapper(userId);
379 
380             Object paramObj1 = new LongWrapper(groupId);
381 
382             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
383                     "getUserGroupRoles", new Object[] { paramObj0, paramObj1 });
384 
385             Object returnObj = null;
386 
387             try {
388                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
389             }
390             catch (Exception e) {
391                 if (e instanceof com.liferay.portal.SystemException) {
392                     throw (com.liferay.portal.SystemException)e;
393                 }
394 
395                 throw new com.liferay.portal.SystemException(e);
396             }
397 
398             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
399         }
400         catch (com.liferay.portal.SystemException se) {
401             _log.error(se, se);
402 
403             throw se;
404         }
405     }
406 
407     public static java.util.List<com.liferay.portal.model.Role> getUserRelatedRoles(
408         HttpPrincipal httpPrincipal, long userId,
409         java.util.List<com.liferay.portal.model.Group> groups)
410         throws com.liferay.portal.SystemException {
411         try {
412             Object paramObj0 = new LongWrapper(userId);
413 
414             Object paramObj1 = groups;
415 
416             if (groups == null) {
417                 paramObj1 = new NullWrapper("java.util.List");
418             }
419 
420             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
421                     "getUserRelatedRoles", new Object[] { paramObj0, paramObj1 });
422 
423             Object returnObj = null;
424 
425             try {
426                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
427             }
428             catch (Exception e) {
429                 if (e instanceof com.liferay.portal.SystemException) {
430                     throw (com.liferay.portal.SystemException)e;
431                 }
432 
433                 throw new com.liferay.portal.SystemException(e);
434             }
435 
436             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
437         }
438         catch (com.liferay.portal.SystemException se) {
439             _log.error(se, se);
440 
441             throw se;
442         }
443     }
444 
445     public static java.util.List<com.liferay.portal.model.Role> getUserRoles(
446         HttpPrincipal httpPrincipal, long userId)
447         throws com.liferay.portal.SystemException {
448         try {
449             Object paramObj0 = new LongWrapper(userId);
450 
451             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
452                     "getUserRoles", new Object[] { paramObj0 });
453 
454             Object returnObj = null;
455 
456             try {
457                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
458             }
459             catch (Exception e) {
460                 if (e instanceof com.liferay.portal.SystemException) {
461                     throw (com.liferay.portal.SystemException)e;
462                 }
463 
464                 throw new com.liferay.portal.SystemException(e);
465             }
466 
467             return (java.util.List<com.liferay.portal.model.Role>)returnObj;
468         }
469         catch (com.liferay.portal.SystemException se) {
470             _log.error(se, se);
471 
472             throw se;
473         }
474     }
475 
476     public static boolean hasUserRole(HttpPrincipal httpPrincipal, long userId,
477         long companyId, java.lang.String name, boolean inherited)
478         throws com.liferay.portal.PortalException,
479             com.liferay.portal.SystemException {
480         try {
481             Object paramObj0 = new LongWrapper(userId);
482 
483             Object paramObj1 = new LongWrapper(companyId);
484 
485             Object paramObj2 = name;
486 
487             if (name == null) {
488                 paramObj2 = new NullWrapper("java.lang.String");
489             }
490 
491             Object paramObj3 = new BooleanWrapper(inherited);
492 
493             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
494                     "hasUserRole",
495                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
496 
497             Object returnObj = null;
498 
499             try {
500                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
501             }
502             catch (Exception e) {
503                 if (e instanceof com.liferay.portal.PortalException) {
504                     throw (com.liferay.portal.PortalException)e;
505                 }
506 
507                 if (e instanceof com.liferay.portal.SystemException) {
508                     throw (com.liferay.portal.SystemException)e;
509                 }
510 
511                 throw new com.liferay.portal.SystemException(e);
512             }
513 
514             return ((Boolean)returnObj).booleanValue();
515         }
516         catch (com.liferay.portal.SystemException se) {
517             _log.error(se, se);
518 
519             throw se;
520         }
521     }
522 
523     public static boolean hasUserRoles(HttpPrincipal httpPrincipal,
524         long userId, long companyId, java.lang.String[] names, boolean inherited)
525         throws com.liferay.portal.PortalException,
526             com.liferay.portal.SystemException {
527         try {
528             Object paramObj0 = new LongWrapper(userId);
529 
530             Object paramObj1 = new LongWrapper(companyId);
531 
532             Object paramObj2 = names;
533 
534             if (names == null) {
535                 paramObj2 = new NullWrapper("[Ljava.lang.String;");
536             }
537 
538             Object paramObj3 = new BooleanWrapper(inherited);
539 
540             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
541                     "hasUserRoles",
542                     new Object[] { paramObj0, paramObj1, paramObj2, paramObj3 });
543 
544             Object returnObj = null;
545 
546             try {
547                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
548             }
549             catch (Exception e) {
550                 if (e instanceof com.liferay.portal.PortalException) {
551                     throw (com.liferay.portal.PortalException)e;
552                 }
553 
554                 if (e instanceof com.liferay.portal.SystemException) {
555                     throw (com.liferay.portal.SystemException)e;
556                 }
557 
558                 throw new com.liferay.portal.SystemException(e);
559             }
560 
561             return ((Boolean)returnObj).booleanValue();
562         }
563         catch (com.liferay.portal.SystemException se) {
564             _log.error(se, se);
565 
566             throw se;
567         }
568     }
569 
570     public static void unsetUserRoles(HttpPrincipal httpPrincipal, long userId,
571         long[] roleIds)
572         throws com.liferay.portal.PortalException,
573             com.liferay.portal.SystemException {
574         try {
575             Object paramObj0 = new LongWrapper(userId);
576 
577             Object paramObj1 = roleIds;
578 
579             if (roleIds == null) {
580                 paramObj1 = new NullWrapper("[J");
581             }
582 
583             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
584                     "unsetUserRoles", new Object[] { paramObj0, paramObj1 });
585 
586             try {
587                 TunnelUtil.invoke(httpPrincipal, methodWrapper);
588             }
589             catch (Exception e) {
590                 if (e instanceof com.liferay.portal.PortalException) {
591                     throw (com.liferay.portal.PortalException)e;
592                 }
593 
594                 if (e instanceof com.liferay.portal.SystemException) {
595                     throw (com.liferay.portal.SystemException)e;
596                 }
597 
598                 throw new com.liferay.portal.SystemException(e);
599             }
600         }
601         catch (com.liferay.portal.SystemException se) {
602             _log.error(se, se);
603 
604             throw se;
605         }
606     }
607 
608     public static com.liferay.portal.model.Role updateRole(
609         HttpPrincipal httpPrincipal, long roleId, java.lang.String name,
610         java.util.Map<java.util.Locale, String> localeTitlesMap,
611         java.lang.String description, java.lang.String subtype)
612         throws com.liferay.portal.PortalException,
613             com.liferay.portal.SystemException {
614         try {
615             Object paramObj0 = new LongWrapper(roleId);
616 
617             Object paramObj1 = name;
618 
619             if (name == null) {
620                 paramObj1 = new NullWrapper("java.lang.String");
621             }
622 
623             Object paramObj2 = localeTitlesMap;
624 
625             if (localeTitlesMap == null) {
626                 paramObj2 = new NullWrapper("java.util.Map");
627             }
628 
629             Object paramObj3 = description;
630 
631             if (description == null) {
632                 paramObj3 = new NullWrapper("java.lang.String");
633             }
634 
635             Object paramObj4 = subtype;
636 
637             if (subtype == null) {
638                 paramObj4 = new NullWrapper("java.lang.String");
639             }
640 
641             MethodWrapper methodWrapper = new MethodWrapper(RoleServiceUtil.class.getName(),
642                     "updateRole",
643                     new Object[] {
644                         paramObj0, paramObj1, paramObj2, paramObj3, paramObj4
645                     });
646 
647             Object returnObj = null;
648 
649             try {
650                 returnObj = TunnelUtil.invoke(httpPrincipal, methodWrapper);
651             }
652             catch (Exception e) {
653                 if (e instanceof com.liferay.portal.PortalException) {
654                     throw (com.liferay.portal.PortalException)e;
655                 }
656 
657                 if (e instanceof com.liferay.portal.SystemException) {
658                     throw (com.liferay.portal.SystemException)e;
659                 }
660 
661                 throw new com.liferay.portal.SystemException(e);
662             }
663 
664             return (com.liferay.portal.model.Role)returnObj;
665         }
666         catch (com.liferay.portal.SystemException se) {
667             _log.error(se, se);
668 
669             throw se;
670         }
671     }
672 
673     private static Log _log = LogFactoryUtil.getLog(RoleServiceHttp.class);
674 }