Example usage for com.liferay.portal.kernel.util Constants READ

List of usage examples for com.liferay.portal.kernel.util Constants READ

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Constants READ.

Prototype

String READ

To view the source code for com.liferay.portal.kernel.util Constants READ.

Click Source Link

Usage

From source file:com.liferay.login.authentication.openid.web.internal.portlet.action.OpenIdLoginMVCActionCommand.java

License:Open Source License

@Override
public void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!_openId.isEnabled(themeDisplay.getCompanyId())) {
        throw new PrincipalException.MustBeEnabled(themeDisplay.getCompanyId(), OpenId.class.getName());
    }//from   w  ww .j  av  a 2 s .  com

    if (actionRequest.getRemoteUser() != null) {
        actionResponse.sendRedirect(themeDisplay.getPathMain());

        return;
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
        if (cmd.equals(Constants.READ)) {
            String redirect = _openIdServiceHandler.readResponse(themeDisplay, actionRequest);

            if (Validator.isNull(redirect)) {
                redirect = themeDisplay.getURLSignIn();
            }

            redirect = _portal.escapeRedirect(redirect);

            actionResponse.sendRedirect(redirect);
        } else {
            _openIdServiceHandler.sendRequest(themeDisplay, actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof OpenIdServiceException) {
            if (_log.isInfoEnabled()) {
                _log.info("Error communicating with OpenID provider: " + e.getMessage());
            }

            SessionErrors.add(actionRequest, e.getClass());
        } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

            SessionErrors.add(actionRequest, e.getClass());
        } else {
            _log.error("Error processing the OpenID login", e);

            _portal.sendError(e, actionRequest, actionResponse);
        }
    }
}

From source file:com.liferay.portlet.login.action.OpenIdAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (actionRequest.getRemoteUser() != null) {
        actionResponse.sendRedirect(themeDisplay.getPathMain());

        return;/*from   w ww .j a  v a2  s.  co  m*/
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
        if (cmd.equals(Constants.READ)) {
            String redirect = readOpenIdResponse(themeDisplay, actionRequest, actionResponse);

            if (Validator.isNull(redirect)) {
                redirect = PortalUtil.getPortalURL(actionRequest) + themeDisplay.getURLSignIn();
            }

            sendRedirect(actionRequest, actionResponse, redirect);
        } else {
            sendOpenIdRequest(themeDisplay, actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof DuplicateUserEmailAddressException) {
            SessionErrors.add(actionRequest, e.getClass().getName());
        } else if (e instanceof OpenIDException) {
            if (_log.isInfoEnabled()) {
                _log.info("Error communicating with OpenID provider: " + e.getMessage());
            }

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            _log.error("Error processing the OpenID login", e);

            PortalUtil.sendError(e, actionRequest, actionResponse);
        }
    }
}

From source file:com.liferay.portlet.login.action.OpenIdAction.java

License:Open Source License

protected void sendOpenIdRequest(ThemeDisplay themeDisplay, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    if (!OpenIdUtil.isEnabled(themeDisplay.getCompanyId())) {
        return;/*from w  w w . j  av  a  2s  .  c  o m*/
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
    HttpSession session = request.getSession();

    ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse;

    String openId = ParamUtil.getString(actionRequest, "openId");

    PortletURL portletURL = actionResponseImpl.createActionURL();

    portletURL.setParameter("struts_action", "/login/open_id");
    portletURL.setParameter(Constants.CMD, Constants.READ);
    portletURL.setParameter("saveLastPath", "0");

    ConsumerManager manager = OpenIdUtil.getConsumerManager();

    List<DiscoveryInformation> discoveries = manager.discover(openId);

    DiscoveryInformation discovered = manager.associate(discoveries);

    session.setAttribute(WebKeys.OPEN_ID_DISCO, discovered);

    AuthRequest authRequest = manager.authenticate(discovered, portletURL.toString(),
            themeDisplay.getPortalURL());

    try {
        UserLocalServiceUtil.getUserByOpenId(themeDisplay.getCompanyId(), openId);
    } catch (NoSuchUserException nsue) {
        String screenName = OpenIdUtil.getScreenName(openId);

        try {
            User user = UserLocalServiceUtil.getUserByScreenName(themeDisplay.getCompanyId(), screenName);

            UserLocalServiceUtil.updateOpenId(user.getUserId(), openId);
        } catch (NoSuchUserException nsue2) {
            FetchRequest fetch = FetchRequest.createFetchRequest();

            fetch.addAttribute("email", "http://schema.openid.net/contact/email", true);
            fetch.addAttribute("firstName", "http://schema.openid.net/namePerson/first", true);
            fetch.addAttribute("lastName", "http://schema.openid.net/namePerson/last", true);

            authRequest.addExtension(fetch);

            SRegRequest sregRequest = SRegRequest.createFetchRequest();

            sregRequest.addAttribute("fullname", true);
            sregRequest.addAttribute("email", true);

            authRequest.addExtension(sregRequest);
        }
    }

    response.sendRedirect(authRequest.getDestinationUrl(true));
}