Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getString

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getString

Introduction

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

Prototype

public static String getString(PortletPreferences preferences, String name, String defaultValue) 

Source Link

Usage

From source file:com.liferay.shibboleth.hook.events.ShibbolethLogoutAction.java

License:Open Source License

@Override
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {

    try {/*from  ww w.j a  va2 s .  co m*/
        long companyId = PortalUtil.getCompanyId(request);

        if (!ShibbolethUtil.isEnabled(companyId)) {
            return;
        }

        String pathInfo = request.getPathInfo();

        if (pathInfo.contains("/portal/logout")) {
            HttpSession session = request.getSession();

            String shibbolethLogoutURL = PrefsPropsUtil.getString(companyId, PropsKeys.SHIBBOLETH_LOGOUT_URL,
                    PropsValues.SHIBBOLETH_LOGOUT_URL);

            session.invalidate();

            if (Validator.isNotNull(shibbolethLogoutURL)) {
                response.sendRedirect(shibbolethLogoutURL);
            }
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.shibboleth.hook.security.auth.ShibbolethAutoLogin.java

License:Open Source License

@Override
protected String[] doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Company company = PortalUtil.getCompany(request);

    long companyId = company.getCompanyId();

    if (!ShibbolethUtil.isEnabled(companyId)) {
        return null;
    }/* ww  w. j  a  va2 s . c  o m*/

    String shibbolethUserHeader = request.getHeader(PrefsPropsUtil.getString(companyId,
            PropsKeys.SHIBBOLETH_USER_HEADER, PropsValues.SHIBBOLETH_USER_HEADER));

    if (Validator.isNull(shibbolethUserHeader)) {
        return null;
    }

    String authType = company.getAuthType();

    User user = null;

    if (PrefsPropsUtil.getBoolean(companyId, PropsKeys.SHIBBOLETH_IMPORT_FROM_LDAP,
            PropsValues.SHIBBOLETH_IMPORT_FROM_LDAP)) {

        try {
            if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                user = PortalLDAPImporterUtil.importLDAPUser(companyId, shibbolethUserHeader, StringPool.BLANK);
            } else {
                user = PortalLDAPImporterUtil.importLDAPUser(companyId, StringPool.BLANK, shibbolethUserHeader);
            }
        } catch (SystemException se) {
        }
    }

    if (user == null) {
        if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
            user = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, shibbolethUserHeader);
        } else {
            user = UserLocalServiceUtil.fetchUserByScreenName(companyId, shibbolethUserHeader);
        }
    }

    String[] credentials = new String[3];

    credentials[0] = String.valueOf(user.getUserId());
    credentials[1] = user.getPassword();
    credentials[2] = Boolean.TRUE.toString();

    return credentials;
}

From source file:com.rivetlogic.crafter.social.listeners.CustomTrashEntryListener.java

License:Open Source License

private void init(long companyId) {
    try {/* w ww  .j a  va 2s.c  om*/
        CrafterManager.init();

        // add crafterAuthCookie to HTTP client
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
        client.setCookieStore(new BasicCookieStore());
        AuthenticationCookie authCookie = CrafterManager
                .getCrafterProfileCookie(PrefsPropsUtil.getString(companyId, CrafterConstants.PROFILE_ADMIN_KEY,
                        GetterUtil.getString(PropsUtil.get(CrafterConstants.PROFILE_ADMIN_KEY),
                                CrafterConstants.PROFILE_DEFAULT_USER)));

        BasicClientCookie cookie = new BasicClientCookie(AuthenticationCookie.COOKIE,
                authCookie.toCookieValue());
        cookie.setDomain(CrafterConstants.CRAFTER_DOMAIN);
        cookie.setExpiryDate(authCookie.getProfileOutdatedAfter());
        cookie.setPath(StringPool.SLASH);
        client.getCookieStore().addCookie(cookie);

    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
}

From source file:com.rivetlogic.evernote.portlet.EvernoteKeys.java

License:Open Source License

public static String getConsumerKey(long companyId) throws SystemException {
    return PrefsPropsUtil.getString(companyId, EVERNOTE_CONSUMER_KEY,
            GetterUtil.getString(PropsUtil.get(EVERNOTE_CONSUMER_KEY)));
}

From source file:com.rivetlogic.evernote.portlet.EvernoteKeys.java

License:Open Source License

public static String getConsumerSecret(long companyId) throws SystemException {
    return PrefsPropsUtil.getString(companyId, EVERNOTE_CONSUMER_SECRET,
            GetterUtil.getString(PropsUtil.get(EVERNOTE_CONSUMER_SECRET)));
}

From source file:com.rivetlogic.portlet.GoogleDriveKeys.java

License:Open Source License

/**
 * Gets the client id./*w  ww. jav  a2  s.  c o m*/
 *
 * @param companyId the company id
 * @return the client id
 * @throws SystemException the system exception
 */
public static String getClientId(long companyId) throws SystemException {
    return PrefsPropsUtil.getString(companyId, GOOGLE_DRIVE_CLIENTID,
            GetterUtil.getString(PropsUtil.get(GOOGLE_DRIVE_CLIENTID)));
}

From source file:com.rivetlogic.portlet.GoogleDriveKeys.java

License:Open Source License

/**
 * Gets the dev key./*from   w  w w .  ja  va  2 s.  co m*/
 *
 * @param companyId the company id
 * @return the dev key
 * @throws SystemException the system exception
 */
public static String getDevKey(long companyId) throws SystemException {
    return PrefsPropsUtil.getString(companyId, GOOGLE_DRIVE_DEVKEY,
            GetterUtil.getString(PropsUtil.get(GOOGLE_DRIVE_DEVKEY)));
}

From source file:es.uib.owu.liferay.cas.service.impl.CasServiceUtilLocalServiceImpl.java

License:Open Source License

private TicketValidator getTicketValidator(long companyId, String proxyReceptorUrl, String allowAnyProxy,
        String allowedProxyChains, boolean renew) throws SystemException {
    if (_log.isDebugEnabled())
        _log.debug("getTicketValidator");
    Cas20ServiceTicketValidator ticketValidator = _ticketValidators.get(Long.valueOf(companyId));
    //Cas20ServiceTicketValidator ticketValidator = (Cas20ServiceTicketValidator) _ticketValidators.get(Long.valueOf(companyId));

    if (ticketValidator != null) {
        return ticketValidator;
    }//from  w  w  w  .  jav  a 2s .c  o  m

    String serverName = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_NAME,
            PropsUtil.get(PropsKeys.CAS_SERVER_NAME));
    String casServerUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_URL,
            PropsUtil.get(PropsKeys.CAS_SERVER_URL));
    String casLoginUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGIN_URL,
            PropsUtil.get(PropsKeys.CAS_LOGIN_URL));

    if ((CommonUtils.isNotBlank(allowAnyProxy) || CommonUtils.isNotBlank(allowedProxyChains))) {
        final Cas20ProxyTicketValidator v = new Cas20ProxyTicketValidator(casServerUrl);
        v.setAcceptAnyProxy(PrefsPropsUtil.getBoolean(allowAnyProxy));
        v.setAllowedProxyChains(createProxyList(allowedProxyChains));
        ticketValidator = v;
        if (_log.isDebugEnabled()) {
            _log.debug("Cas20ProxyTicketValidator");
            _log.debug("-setAcceptAnyProxy: " + allowAnyProxy);
            _log.debug("-setAllowedProxyChains: " + allowedProxyChains);
        }
    } else {
        ticketValidator = new Cas20ServiceTicketValidator(casServerUrl);
        if (_log.isDebugEnabled()) {
            _log.debug("Cas20ServiceValidator");
        }
    }

    if (proxyReceptorUrl != null) {
        ticketValidator.setProxyCallbackUrl(serverName + proxyReceptorUrl);
        ProxyGrantingTicketStorageImpl proxyGrantingTicketStorage = getPGTSI();
        if (_log.isDebugEnabled()) {
            _log.debug("Cas20ServiceValidator assigname proxyGrantingTicketStorage: "
                    + proxyGrantingTicketStorage);
        }
        ticketValidator.setProxyGrantingTicketStorage(proxyGrantingTicketStorage);
    }

    ticketValidator.setRenew(renew);

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("serverName", serverName);
    parameters.put("casServerUrlPrefix", casServerUrl);
    parameters.put("casServerLoginUrl", casLoginUrl);
    parameters.put("redirectAfterValidation", "false");

    if (allowAnyProxy != null)
        parameters.put("allowAnyProxy", allowAnyProxy);

    ticketValidator.setCustomParameters(parameters);
    _ticketValidators.put(Long.valueOf(companyId), ticketValidator);

    if (_log.isDebugEnabled()) {
        _log.debug("Returning cas20ProxyTicketValidator with..");
        _log.debug("- serverName: " + serverName);
        _log.debug("- casServerUrlPrefix: " + casServerUrl);
        _log.debug("- casServerLoginUrl: " + casLoginUrl);
        if (proxyReceptorUrl != null)
            _log.debug("- proxyCallbackUrl: " + serverName + proxyReceptorUrl);

    }

    return ticketValidator;

}

From source file:es.uib.owu.liferay.cas.service.impl.CasServiceUtilLocalServiceImpl.java

License:Open Source License

public String constructServiceUrl(Long companyId, HttpServletRequest request, HttpServletResponse response)
        throws SystemException {
    String casServerName = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_NAME,
            PropsUtil.get(PropsKeys.CAS_SERVER_NAME));
    String casServiceUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVICE_URL,
            PropsUtil.get(PropsKeys.CAS_SERVICE_URL));
    String casServerUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_URL,
            PropsUtil.get(PropsKeys.CAS_SERVER_URL));
    return CommonUtils.constructServiceUrl(request, response, casServiceUrl, casServerName, "ticket", true); //ENCODEURL TRUE

}