List of usage examples for com.liferay.portal.service.http GroupServiceHttp checkRemoteStagingGroup
public static void checkRemoteStagingGroup(HttpPrincipal httpPrincipal, long groupId) throws com.liferay.portal.kernel.exception.PortalException
From source file:com.liferay.exportimport.staging.StagingImpl.java
License:Open Source License
protected void validateRemoteGroup(long groupId, long remoteGroupId, String remoteAddress, int remotePort, String remotePathContext, boolean secureConnection) throws PortalException { if (remoteGroupId <= 0) { RemoteOptionsException roe = new RemoteOptionsException(RemoteOptionsException.REMOTE_GROUP_ID); roe.setRemoteGroupId(remoteGroupId); throw roe; }//from ww w. jav a 2 s .com Thread currentThread = Thread.currentThread(); ClassLoader contextClassLoader = currentThread.getContextClassLoader(); PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); User user = permissionChecker.getUser(); String remoteURL = buildRemoteURL(remoteAddress, remotePort, remotePathContext, secureConnection); HttpPrincipal httpPrincipal = new HttpPrincipal(remoteURL, user.getLogin(), user.getPassword(), user.getPasswordEncrypted()); try { currentThread.setContextClassLoader(PortalClassLoaderUtil.getClassLoader()); // Ping the remote host and verify that the remote group exists in // the same company as the remote user GroupServiceHttp.checkRemoteStagingGroup(httpPrincipal, remoteGroupId); // Ensure that the local group and the remote group are not the same // group and that they are either both company groups or both not // company groups Group group = _groupLocalService.getGroup(groupId); Group remoteGroup = GroupServiceHttp.getGroup(httpPrincipal, remoteGroupId); if (group.isCompany() ^ isCompanyGroup(httpPrincipal, remoteGroup)) { RemoteExportException ree = new RemoteExportException(RemoteExportException.INVALID_GROUP); ree.setGroupId(remoteGroupId); throw ree; } } catch (NoSuchGroupException nsge) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsge, nsge); } RemoteExportException ree = new RemoteExportException(RemoteExportException.NO_GROUP); ree.setGroupId(remoteGroupId); throw ree; } catch (PrincipalException pe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(pe, pe); } RemoteExportException ree = new RemoteExportException(RemoteExportException.NO_PERMISSIONS); ree.setGroupId(remoteGroupId); throw ree; } catch (RemoteAuthException rae) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(rae, rae); } rae.setURL(remoteURL); throw rae; } catch (SystemException se) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(se, se); } RemoteExportException ree = new RemoteExportException(RemoteExportException.BAD_CONNECTION, se.getMessage()); ree.setURL(remoteURL); throw ree; } finally { currentThread.setContextClassLoader(contextClassLoader); } }