Example usage for com.liferay.portal.kernel.struts LastPath LastPath

List of usage examples for com.liferay.portal.kernel.struts LastPath LastPath

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.struts LastPath LastPath.

Prototype

public LastPath(String contextPath, String path, String parameters) 

Source Link

Usage

From source file:it.publisys.liferay.hook.shibboleth.ShibbolethAutoLogin.java

License:Open Source License

@SuppressWarnings("unchecked")
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
    if (_log.isDebugEnabled()) {
        _log.debug(" - start");
    }//from  w w  w.ja v a  2s .  c o  m

    String[] credentials = null;
    //
    boolean _isNew = false;
    long companyId = 0;
    //
    String _ltype = request.getParameter(LTYPE_PARAM);
    String _login = null;
    User _user = null;
    try {
        // verifico se il request path e' quello di login
        if (request.getRequestURI().contains(LOGIN_PATH)) {
            if (_log.isDebugEnabled()) {
                _log.debug(LTYPE_PARAM + ": " + _ltype);
            }

            // verifico che il parametro 'ltype' sia 'shibb'
            if (Validator.isNotNull(_ltype) && LTYPE_VALUE.equals(_ltype)) {

                if (_log.isDebugEnabled()) {
                    Enumeration<Object> _ens = request.getHeaderNames();
                    while (_ens.hasMoreElements()) {
                        Object _o = _ens.nextElement();
                        if (_o.toString().startsWith(SHIB_PREFIX)) {
                            _log.debug("*=*=* " + _o + ": " + request.getHeader(_o.toString()));
                        }
                    }
                }

                String authType = getAuthType(companyId);

                // Parametro trasmesso dallo ShibbolethSP assunto come default
                _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_EMAIL);

                if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
                    _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_FISCAL_NUMBER);
                } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                    _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_EMAIL);
                }

                if (Validator.isNotNull(_login)) {
                    _login = _login.toUpperCase();

                    companyId = PortalUtil.getCompany(request).getCompanyId();

                    if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
                        _log.info("Login by ScreenName: " + _login);
                        _user = loginByScreenName(companyId, _login);
                    } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                        _log.info("Login by Email: " + _login);
                        _user = loginByEmail(companyId, _login);
                    }

                    if (_user == null) {
                        _log.warn(
                                String.format("Utente non presente in archivio Liferay. [_login:%s]", _login));
                        throw new NoSuchUserException("Utente non presente in archivio Liferay.");
                    }

                    credentials = new String[] { String.valueOf(_user.getUserId()), _user.getPassword(),
                            String.valueOf(_user.isPasswordEncrypted()) };

                    request.getSession().setAttribute(WebKeys.USER_ID, _user.getUserId());

                } else {
                    SessionMessages.add(request, "shibbError", "Parametri per la login non ricevuti.");
                    throw new AutoLoginException("Parametri per la login non ricevuti.");
                }
            }
        }
    } catch (NoSuchUserException e) {
        _log.warn("No Such User with login: " + _login + ". Insert new User.");
        _isNew = true;
    } catch (Exception e) {
        _log.error("Generic Error.", e);
        SessionMessages.add(request, "shibbError",
                "Si &egrave; verificato un errore. Riprovare pi&ugrave; tardi.");
        throw new AutoLoginException(e);
    }

    // creare nuovo utente se _isNew
    if (_isNew) {
        _user = _createNewUser(companyId, request);
        if (_user != null) {
            credentials = new String[] { String.valueOf(_user.getUserId()), _user.getPassword(),
                    String.valueOf(_user.isPasswordEncrypted()) };

            request.getSession().setAttribute(WebKeys.USER_ID, _user.getUserId());
        }
    }

    if (_user != null) {
        _updateUser(_user, request);

        // aggiorno la data di ultimo accesso
        try {
            UserLocalServiceUtil.updateLastLogin(_user.getUserId(), request.getRemoteAddr());
        } catch (PortalException e) {
            _log.warn(
                    "Impossibile aggiornare la data di ultimo accesso dell'utente [" + _user.getUserId() + "]",
                    e);
        } catch (SystemException e) {
            _log.warn(
                    "Impossibile aggiornare la data di ultimo accesso dell'utente [" + _user.getUserId() + "]",
                    e);
        }
    }

    String _redirecturl = request.getParameter("redirecturl");
    if (_redirecturl != null && "true".equals(_redirecturl)) {
        _log.info("============================================");
        _log.info("[Redirect URL] " + _redirecturl);
        _log.info("Effettuo la redirect");

        String _sname = request.getParameter("sname");
        _log.info("[sname] " + _sname);
        String _path = request.getParameter("path");
        _log.info("[path] " + _path);

        Map<String, String[]> params = new HashMap<String, String[]>();
        params.put("sname", new String[] { _sname });

        LastPath lastPath = new LastPath("/", _path, params);
        request.getSession().setAttribute(WebKeys.LAST_PATH, lastPath);
        _log.info("[LastPath] " + lastPath);
        _log.info("============================================");
    }

    return credentials;
}

From source file:it.webscience.kpeople.event.login.KpeoplePrivatePageRedirectAction.java

License:Open Source License

protected void doRun(HttpServletRequest request, HttpServletResponse response) throws Exception {

    long companyId = PortalUtil.getCompanyId(request);

    String path = PrefsPropsUtil.getString(companyId,
            PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING);

    path = path + "/" + PortalUtil.getUser(request).getScreenName();

    path = path + PrefsPropsUtil.getString(companyId, PropsKeys.DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL);

    _log.info(String.format("PrivatePageRedirectAction, path=%s...", path));

    if (_log.isInfoEnabled()) {
        _log.info("Private page path: " + StringPool.EQUAL + path);
    }/*from   w  ww  .  j a  v  a2 s  . c o  m*/

    if (Validator.isNotNull(path)) {
        LastPath lastPath = new LastPath(StringPool.BLANK, path, new HashMap<String, String[]>());

        HttpSession session = request.getSession();
        request.setAttribute(WebKeys.LAST_PATH, lastPath);
        session.setAttribute(WebKeys.LAST_PATH, lastPath);
    }
}