Example usage for com.liferay.portal.kernel.util PropsKeys CAS_LOGOUT_URL

List of usage examples for com.liferay.portal.kernel.util PropsKeys CAS_LOGOUT_URL

Introduction

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

Prototype

String CAS_LOGOUT_URL

To view the source code for com.liferay.portal.kernel.util PropsKeys CAS_LOGOUT_URL.

Click Source Link

Usage

From source file:com.ext.portal.servlet.filters.sso.cas.CASFilterExt.java

License:Open Source License

@Override
protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    HttpSession session = request.getSession();

    long companyId = PortalUtil.getCompanyId(request);

    String pathInfo = request.getPathInfo();

    Object forceLogout = session.getAttribute(WebKeys.CAS_FORCE_LOGOUT);

    if (forceLogout != null) {
        session.removeAttribute(WebKeys.CAS_FORCE_LOGOUT);

        String logoutUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGOUT_URL,
                PropsValues.CAS_LOGOUT_URL);

        response.sendRedirect(logoutUrl);

        return;//from  w w w.jav a2s  .c  o  m
    }

    if (pathInfo.contains("/portal/logout")) {
        session.invalidate();

        String logoutUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGOUT_URL,
                PropsValues.CAS_LOGOUT_URL);

        response.sendRedirect(logoutUrl);

        return;
    } else {
        String login = (String) session.getAttribute(WebKeys.CAS_LOGIN);

        if (Validator.isNotNull(login)) {
            processFilter(CASFilterExt.class, request, response, filterChain);

            return;
        }

        String serverName = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_NAME,
                PropsValues.CAS_SERVER_NAME);

        String serviceUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVICE_URL,
                PropsValues.CAS_SERVICE_URL);

        if (Validator.isNull(serviceUrl)) {
            serviceUrl = CommonUtils.constructServiceUrl(request, response, serviceUrl, serverName, "ticket",
                    false);
        }

        String ticket = ParamUtil.getString(request, "ticket");

        if (Validator.isNull(ticket)) {
            String loginUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGIN_URL,
                    PropsValues.CAS_LOGIN_URL);

            loginUrl = HttpUtil.addParameter(loginUrl, "service", serviceUrl);

            response.sendRedirect(loginUrl);

            return;
        }

        TicketValidator ticketValidator = getTicketValidator(companyId);

        Assertion assertion = ticketValidator.validate(ticket, serviceUrl);

        if (assertion != null) {
            AttributePrincipal attributePrincipal = assertion.getPrincipal();

            login = attributePrincipal.getName();

            session.setAttribute(WebKeys.CAS_LOGIN, login);

            // Try to add user if it doesn't exist

            //_log.info(attributePrincipal);
            _createUserFromCAS(companyId, login, assertion);
        }
    }

    processFilter(CASFilterExt.class, request, response, filterChain);
}

From source file:com.liferay.portlet.portalsettings.action.EditCompanyAction.java

License:Open Source License

protected void validateCAS(ActionRequest actionRequest) throws Exception {
    boolean casEnabled = ParamUtil.getBoolean(actionRequest, "settings--" + PropsKeys.CAS_AUTH_ENABLED + "--");

    if (!casEnabled) {
        return;//from ww  w .j ava 2s .c  o m
    }

    String casLoginURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGIN_URL + "--");
    String casLogoutURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGOUT_URL + "--");
    String casServerName = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_NAME + "--");
    String casServerURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_URL + "--");
    String casServiceURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVICE_URL + "--");
    String casNoSuchUserRedirectURL = ParamUtil.getString(actionRequest,
            "settings--" + PropsKeys.CAS_NO_SUCH_USER_REDIRECT_URL + "--");

    if (!Validator.isUrl(casLoginURL)) {
        SessionErrors.add(actionRequest, "casLoginURLInvalid");
    }

    if (!Validator.isUrl(casLogoutURL)) {
        SessionErrors.add(actionRequest, "casLogoutURLInvalid");
    }

    if (Validator.isNull(casServerName)) {
        SessionErrors.add(actionRequest, "casServerNameInvalid");
    }

    if (Validator.isNotNull(casServerURL) && Validator.isNotNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLConflict");
    } else if (Validator.isNull(casServerURL) && Validator.isNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLNotSet");
    } else {
        if (Validator.isNotNull(casServerURL) && !Validator.isUrl(casServerURL)) {

            SessionErrors.add(actionRequest, "casServerURLInvalid");
        }

        if (Validator.isNotNull(casServiceURL) && !Validator.isUrl(casServiceURL)) {

            SessionErrors.add(actionRequest, "casServiceURLInvalid");
        }
    }

    if (Validator.isNotNull(casNoSuchUserRedirectURL) && !Validator.isUrl(casNoSuchUserRedirectURL)) {

        SessionErrors.add(actionRequest, "casNoSuchUserURLInvalid");
    }
}