Example usage for com.liferay.portal.kernel.security.auth RemoteAuthException setURL

List of usage examples for com.liferay.portal.kernel.security.auth RemoteAuthException setURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.auth RemoteAuthException setURL.

Prototype

public void setURL(String url) 

Source Link

Usage

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 w  w  w . j a v a  2s. 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);
    }
}