Example usage for com.liferay.portal.kernel.model User getLogin

List of usage examples for com.liferay.portal.kernel.model User getLogin

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model User getLogin.

Prototype

public String getLogin() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

From source file:com.liferay.exportimport.internal.lifecycle.EventRemotePropagatorExportImportLifecycleListener.java

License:Open Source License

private Optional<HttpPrincipal> _getHttpPrincipal(User user, String remoteURL) {

    HttpPrincipal httpPrincipal = null;/*from ww  w  . java  2  s .  c o  m*/

    try {
        httpPrincipal = new HttpPrincipal(remoteURL, user.getLogin(), user.getPassword(),
                user.getPasswordEncrypted());
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to generate HttpPrincipal for user " + user.getFullName(), pe);
        }
    }

    return Optional.ofNullable(httpPrincipal);
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

@Override
public String getRemoteSiteURL(Group stagingGroup, boolean privateLayout) throws PortalException {

    if (!stagingGroup.isStagedRemotely()) {
        return StringPool.BLANK;
    }//from   w  w  w. j  a  va2s  .  c om

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    User user = permissionChecker.getUser();

    UnicodeProperties typeSettingsProperties = stagingGroup.getTypeSettingsProperties();

    HttpPrincipal httpPrincipal = new HttpPrincipal(buildRemoteURL(typeSettingsProperties), user.getLogin(),
            user.getPassword(), user.getPasswordEncrypted());

    long remoteGroupId = GetterUtil.getLong(typeSettingsProperties.getProperty("remoteGroupId"));
    boolean secureConnection = GetterUtil.getBoolean(typeSettingsProperties.getProperty("secureConnection"));

    String groupDisplayURL = GroupServiceHttp.getGroupDisplayURL(httpPrincipal, remoteGroupId, privateLayout,
            secureConnection);

    try {
        URL remoteSiteURL = new URL(groupDisplayURL);

        String remoteAddress = typeSettingsProperties.getProperty("remoteAddress");

        remoteSiteURL = new URL(remoteSiteURL.getProtocol(), remoteAddress, remoteSiteURL.getPort(),
                remoteSiteURL.getFile());

        return remoteSiteURL.toString();
    } catch (MalformedURLException murle) {
        throw new PortalException(murle);
    }
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

protected long doCopyRemoteLayouts(ExportImportConfiguration exportImportConfiguration, String remoteAddress,
        int remotePort, String remotePathContext, boolean secureConnection, boolean remotePrivateLayout)
        throws PortalException {

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");

    String backgroundTaskName = MapUtil.getString(parameterMap, "name", exportImportConfiguration.getName());

    Map<String, Serializable> taskContextMap = new HashMap<>();

    taskContextMap.put("exportImportConfigurationId",
            exportImportConfiguration.getExportImportConfigurationId());

    String remoteURL = buildRemoteURL(remoteAddress, remotePort, remotePathContext, secureConnection);

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    User user = permissionChecker.getUser();

    HttpPrincipal httpPrincipal = new HttpPrincipal(remoteURL, user.getLogin(), user.getPassword(),
            user.getPasswordEncrypted());

    taskContextMap.put("httpPrincipal", httpPrincipal);

    taskContextMap.put("privateLayout", remotePrivateLayout);

    BackgroundTask backgroundTask = _backgroundTaskManager.addBackgroundTask(user.getUserId(),
            exportImportConfiguration.getGroupId(), backgroundTaskName,
            BackgroundTaskExecutorNames.LAYOUT_REMOTE_STAGING_BACKGROUND_TASK_EXECUTOR, taskContextMap,
            new ServiceContext());

    return backgroundTask.getBackgroundTaskId();
}

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;
    }/* ww w .j av  a  2s.co m*/

    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);
    }
}