Example usage for com.liferay.portal.util PrefsPropsUtil getInteger

List of usage examples for com.liferay.portal.util PrefsPropsUtil getInteger

Introduction

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

Prototype

public static int getInteger(String name, int defaultValue) 

Source Link

Usage

From source file:com.liferay.mail.service.impl.MailServiceImpl.java

License:Open Source License

public Session getSession() throws SystemException {
    if (_session != null) {
        return _session;
    }/*from   w w w .j  a v a 2s .  c o  m*/

    Session session = InfrastructureUtil.getMailSession();

    if (!PrefsPropsUtil.getBoolean(PropsKeys.MAIL_SESSION_MAIL)) {
        _session = session;

        return _session;
    }

    String advancedPropertiesString = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES,
            PropsValues.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES);
    String pop3Host = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST,
            PropsValues.MAIL_SESSION_MAIL_POP3_HOST);
    String pop3Password = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD,
            PropsValues.MAIL_SESSION_MAIL_POP3_PASSWORD);
    int pop3Port = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT,
            PropsValues.MAIL_SESSION_MAIL_POP3_PORT);
    String pop3User = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_USER,
            PropsValues.MAIL_SESSION_MAIL_POP3_USER);
    String smtpHost = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST,
            PropsValues.MAIL_SESSION_MAIL_SMTP_HOST);
    String smtpPassword = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD,
            PropsValues.MAIL_SESSION_MAIL_SMTP_PASSWORD);
    int smtpPort = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT,
            PropsValues.MAIL_SESSION_MAIL_SMTP_PORT);
    String smtpUser = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER,
            PropsValues.MAIL_SESSION_MAIL_SMTP_USER);
    String storeProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL,
            PropsValues.MAIL_SESSION_MAIL_STORE_PROTOCOL);
    String transportProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL,
            PropsValues.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL);

    Properties properties = session.getProperties();

    // Incoming

    if (!storeProtocol.equals(Account.PROTOCOL_POPS)) {
        storeProtocol = Account.PROTOCOL_POP;
    }

    properties.setProperty("mail.store.protocol", storeProtocol);

    String storePrefix = "mail." + storeProtocol + ".";

    properties.setProperty(storePrefix + "host", pop3Host);
    properties.setProperty(storePrefix + "password", pop3Password);
    properties.setProperty(storePrefix + "port", String.valueOf(pop3Port));
    properties.setProperty(storePrefix + "user", pop3User);

    // Outgoing

    if (!transportProtocol.equals(Account.PROTOCOL_SMTPS)) {
        transportProtocol = Account.PROTOCOL_SMTP;
    }

    properties.setProperty("mail.transport.protocol", transportProtocol);

    String transportPrefix = "mail." + transportProtocol + ".";

    boolean smtpAuth = false;

    if (Validator.isNotNull(smtpPassword) || Validator.isNotNull(smtpUser)) {

        smtpAuth = true;
    }

    properties.setProperty(transportPrefix + "auth", String.valueOf(smtpAuth));
    properties.setProperty(transportPrefix + "host", smtpHost);
    properties.setProperty(transportPrefix + "password", smtpPassword);
    properties.setProperty(transportPrefix + "port", String.valueOf(smtpPort));
    properties.setProperty(transportPrefix + "user", smtpUser);

    // Advanced

    try {
        if (Validator.isNotNull(advancedPropertiesString)) {
            Properties advancedProperties = PropertiesUtil.load(advancedPropertiesString);

            Iterator<Map.Entry<Object, Object>> itr = advancedProperties.entrySet().iterator();

            while (itr.hasNext()) {
                Map.Entry<Object, Object> entry = itr.next();

                String key = (String) entry.getKey();
                String value = (String) entry.getValue();

                properties.setProperty(key, value);
            }
        }
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe, ioe);
        }
    }

    _session = Session.getInstance(properties);

    return _session;
}

From source file:com.liferay.portlet.documentlibrary.util.DocumentConversionUtil.java

License:Open Source License

private DocumentConverter _getDocumentConverter() throws SystemException {
    if ((_openOfficeConnection != null) && (_documentConverter != null)) {
        return _documentConverter;
    }/*  w  ww  .j a  v  a  2 s  . c  o  m*/

    String host = PrefsPropsUtil.getString(PropsKeys.OPENOFFICE_SERVER_HOST);
    int port = PrefsPropsUtil.getInteger(PropsKeys.OPENOFFICE_SERVER_PORT, PropsValues.OPENOFFICE_SERVER_PORT);

    if (_isRemoteOpenOfficeHost(host)) {
        _openOfficeConnection = new SocketOpenOfficeConnection(host, port);
        _documentConverter = new StreamOpenOfficeDocumentConverter(_openOfficeConnection);
    } else {
        _openOfficeConnection = new SocketOpenOfficeConnection(port);
        _documentConverter = new OpenOfficeDocumentConverter(_openOfficeConnection);
    }

    return _documentConverter;
}

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

License:Apache 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);
    long companyId = themeDisplay.getCompanyId();

    if (!STORKUtil.isEnabled(companyId)) {
        throw new PrincipalException();
    }/*from w  w  w .j a  va2  s  .c o  m*/

    String storkMandatoryAttr = PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_AUTH_LOCAL_SEARCH_FILTER,
            FedPropsValues.STORK_AUTH_LOCAL_SEARCH_FILTER);
    Map<String, String> storkUserMapping = getAttrMap(
            PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_USER_MAPPING));

    if (ParamUtil.getString(actionRequest, "StorkAction", "none").equals("login")) {
        byte[] decSamlToken = PEPSUtil.decodeSAMLToken(ParamUtil.getString(actionRequest, "SAMLResponse"));
        STORKSAMLEngine storkEngine = STORKSAMLEngine.getInstance("SP");
        STORKAuthnResponse authnResponse = null;
        try {
            authnResponse = storkEngine.validateSTORKAuthnResponse(decSamlToken,
                    PortalUtil.getHttpServletRequest(actionRequest).getRemoteHost());
        } catch (Exception ex) {
            _log.error("Could not validate token for Saml Response");
            _log.error(ex);
            setForward(actionRequest, "portlet.login.stork.error");
            return;
        }
        _log.debug("Authentication response status: " + authnResponse.getStatusCode() + "(reason: "
                + authnResponse.getSubStatusCode() + ") and this is a fail: " + authnResponse.isFail());
        if (!authnResponse.isFail()) {
            Map<String, PersonalAttribute> mPersAttr = createPersonalAttributeMap(
                    authnResponse.getPersonalAttributeList().values());

            User user = null;
            if (storkMandatoryAttr.equals("screenName")) {
                _log.debug("Finding user using the " + storkUserMapping.get("screenName"));
                if (mPersAttr.containsKey(storkUserMapping.get("screenName"))) {
                    Iterator<String> pa = mPersAttr.get(storkUserMapping.get("screenName")).getValue()
                            .iterator();

                    while (pa.hasNext() && user == null) {
                        String screenName = pa.next();
                        try {
                            user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);
                        } catch (NoSuchUserException nse) {
                            _log.info("User screenName: " + screenName + " is not registered");
                        }
                    }
                } else {
                    actionResponse.sendRedirect(
                            PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_AUTH_PAGE_MISS_ATTRIBUTE,
                                    FedPropsValues.STORK_AUTH_PAGE_MISS_ATTRIBUTE));
                    _log.info("Stork authentication miss the matching attribute. Impossible to identify users");
                    return;
                }
            }
            if (storkMandatoryAttr.equals("uuid")) {
                _log.debug("Finding user using the " + storkUserMapping.get("uuid"));
                if (mPersAttr.containsKey(storkUserMapping.get("uuid"))) {
                    Iterator<String> pa = mPersAttr.get(storkUserMapping.get("uuid")).getValue().iterator();

                    while (pa.hasNext() && user == null) {
                        String uuid = pa.next();
                        try {
                            user = UserLocalServiceUtil.getUserByUuid(uuid);
                        } catch (NoSuchUserException nse) {
                            _log.info("User uuid: " + uuid + " is not registered");
                        }
                    }
                } else {
                    actionResponse.sendRedirect(
                            PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_AUTH_PAGE_MISS_ATTRIBUTE,
                                    FedPropsValues.STORK_AUTH_PAGE_MISS_ATTRIBUTE));
                    _log.info("Stork authentication miss the matching attribute. Impossible to identify users");
                    return;
                }

            }
            if (storkMandatoryAttr.equals("emailAddress")) {
                _log.debug("Finding user using the " + storkUserMapping.get("emailAddress"));
                if (mPersAttr.containsKey(storkUserMapping.get("emailAddress"))) {
                    Iterator<String> pa = mPersAttr.get(storkUserMapping.get("emailAddress")).getValue()
                            .iterator();

                    while (pa.hasNext() && user == null) {
                        Pattern pat = Pattern.compile("[\\w\\-]([\\.\\w\\-])+@([\\w\\-]+\\.)+[a-zA-Z]{2,4}");
                        Matcher mailMatch;

                        mailMatch = pat.matcher(pa.next());
                        while (mailMatch.find() && user == null) {
                            if (Validator.isNotNull(mailMatch.group())) {
                                try {
                                    user = UserLocalServiceUtil.getUserByEmailAddress(companyId,
                                            mailMatch.group());
                                } catch (NoSuchUserException nse) {
                                    _log.info("Mail: " + mailMatch.group() + " is not registered");
                                }
                            }
                        }

                    }
                } else {
                    actionResponse.sendRedirect(
                            PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_AUTH_PAGE_MISS_ATTRIBUTE,
                                    FedPropsValues.STORK_AUTH_PAGE_MISS_ATTRIBUTE));
                    _log.info("Stork authentication miss the matching attribute. Impossible to identify users");
                    return;
                }

            }

            if (user == null && PrefsPropsUtil.getBoolean(companyId, FedPropsKeys.STORK_AUTH_LDLAP_CHECK,
                    FedPropsValues.STORK_AUTH_LDLAP_CHECK)) {
                _log.debug("User not found, check on LDAP");
                //                    user=getUserFromLdap();

                String originalLdapFilter = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                        FedPropsKeys.STORK_AUTH_LDAP_SEARCH_FILTER,
                        FedPropsValues.STORK_AUTH_LDAP_SEARCH_FILTER);
                List<String> lstLdapFilter = null;
                try {
                    lstLdapFilter = generateFilters(companyId,
                            mPersAttr.get(storkUserMapping.get("screenName")),
                            mPersAttr.get(storkUserMapping.get("emailAddress")),
                            mPersAttr.get(storkUserMapping.get("firstName")),
                            mPersAttr.get(storkUserMapping.get("lastName")), originalLdapFilter);
                } catch (STORKException se) {
                    _log.error(se.getMessage());
                    actionResponse.sendRedirect(
                            PrefsPropsUtil.getString(companyId, FedPropsKeys.STORK_AUTH_PAGE_MISS_ATTRIBUTE,
                                    FedPropsValues.STORK_AUTH_PAGE_MISS_ATTRIBUTE));
                    return;
                }
                String[] idLDAPS = PrefsPropsUtil.getStringArray(companyId, "ldap.server.ids", ",");
                String idLDAP;
                int idLDAPCounter = 0;
                while (user == null && idLDAPCounter < idLDAPS.length) {
                    idLDAP = idLDAPS[idLDAPCounter++];

                    String mailMap = null;
                    String userMaps[] = PrefsPropsUtil
                            .getString(companyId, PropsKeys.LDAP_USER_MAPPINGS + "." + idLDAP).split("\n");
                    int mIndex = 0;
                    while (mailMap == null && mIndex < userMaps.length) {
                        String map = userMaps[mIndex++];
                        if (map.indexOf("=") == -1 || map.split("=").length != 2) {
                            continue;
                        }
                        String[] sMap = map.split("=");
                        if (sMap[0].equals("emailAddress")) {
                            mailMap = sMap[1];
                        }
                    }

                    if (mailMap == null) {
                        _log.warn("LDAP server configured without the mail map");
                        continue;
                    }

                    LDAPUtil samlLdapUtil = new LDAPUtil(
                            PrefsPropsUtil.getString(companyId,
                                    PropsKeys.LDAP_BASE_PROVIDER_URL + "." + idLDAP),
                            PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN + "." + idLDAP));

                    Iterator<String> ldapFilter = lstLdapFilter.iterator();

                    while (ldapFilter.hasNext() && user == null) {
                        String mail = samlLdapUtil.getUserAttribute(
                                PrefsPropsUtil.getString(companyId,
                                        PropsKeys.LDAP_IMPORT_USER_SEARCH_FILTER + "." + idLDAP),
                                ldapFilter.next(), mailMap);

                        if (mail != null) {
                            try {
                                user = UserLocalServiceUtil.getUserByEmailAddress(companyId, mail);
                            } catch (NoSuchUserException nse) {
                                _log.debug("Mail: " + mail + " found in LDAP but it is not registered");
                            }
                        }
                    }
                }

            }

            if (user == null) {
                _log.info("Impossible to find a user with the current attributes");
                actionResponse.sendRedirect(PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                        FedPropsKeys.STORK_AUTH_PAGE_MISS_USER, FedPropsValues.STORK_AUTH_PAGE_MISS_USER));
                return;
            }

            HttpSession session = PortalUtil.getHttpServletRequest(actionRequest).getSession();
            session.setAttribute(FedWebKeys.STORK_ID_LOGIN, new Long(user.getUserId()));

            //                sendRedirect(actionRequest, actionResponse, PortalUtil.getPortalURL(actionRequest) + themeDisplay.getURLSignIn());
            sendRedirect(actionRequest, actionResponse, ParamUtil.getString(actionRequest, "redirect",
                    PortalUtil.getPortalURL(actionRequest) + themeDisplay.getURLSignIn()));
        } else {
            setForward(actionRequest, "portlet.login.stork.notAuth");
        }

    } else {

        if (Validator.isNull(ParamUtil.getString(actionRequest, "citizenCountry"))) {
            SessionErrors.add(actionRequest, "missUserCountry");
            return;
        }
        STORKAuthnRequest authnRequest = new STORKAuthnRequest();

        authnRequest.setCitizenCountryCode(ParamUtil.getString(actionRequest, "citizenCountry"));

        authnRequest
                .setIssuer(PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_NAME));

        authnRequest.setDestination(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SPEPS_URL));

        authnRequest.setProviderName(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_NAME));

        authnRequest
                .setQaa(PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_QAALEVEL));

        ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse;
        PortletURL portletURL = actionResponseImpl.createActionURL();
        portletURL.setParameter("struts_action", "/login/stork");
        portletURL.setParameter("StorkAction", "login");
        portletURL.setParameter("saveLastPath", "0");
        portletURL.setParameter("redirect",
                ParamUtil.getString(actionRequest, "redirect", themeDisplay.getPathMain()));
        portletURL.setWindowState(WindowState.NORMAL);

        authnRequest.setAssertionConsumerServiceURL(portletURL.toString());
        _log.debug("STORK Return url: " + portletURL.toString());

        authnRequest.setSpSector(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_SECTOR));

        authnRequest.setSpInstitution(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_NAME));

        authnRequest.setSpApplication(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_APLICATION));

        authnRequest.setSpCountry(
                PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_COUNTRY));

        authnRequest.setSPID(PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SP_NAME));

        IPersonalAttributeList pAttList = new PersonalAttributeList();

        boolean eIdentifier = false;
        if (storkUserMapping != null) {

            for (String attrMap : storkUserMapping.keySet()) {
                PersonalAttribute attr = new PersonalAttribute();
                attr.setName(storkUserMapping.get(attrMap));
                if (attrMap.equals(storkMandatoryAttr) && storkUserMapping.get(attrMap).equals("eIdentifier")) {
                    attr.setIsRequired(true);
                    eIdentifier = true;
                    _log.debug("Attribute " + attrMap + " mapped in " + storkUserMapping.get(attrMap)
                            + " is required");
                } else {
                    if (attrMap.equals(storkMandatoryAttr)) {
                        attr.setIsRequired(true);
                        _log.debug("Attribute " + attrMap + " mapped in " + storkUserMapping.get(attrMap)
                                + " is required");
                    } else {
                        attr.setIsRequired(false);
                        _log.debug("Attribute " + attrMap + " mapped in " + storkUserMapping.get(attrMap)
                                + " is not required");

                    }
                }
                pAttList.add(attr);
            }
            if (!eIdentifier) {
                pAttList.add(new PersonalAttribute("eIdentifier", true, null, null));
            }
        }

        authnRequest.setPersonalAttributeList(pAttList);

        byte token[] = null;
        try {

            STORKSAMLEngine storkEngine = STORKSAMLEngine.getInstance("SP");
            token = storkEngine.generateSTORKAuthnRequest(authnRequest).getTokenSaml();

        } catch (Exception ex) {
            _log.error("Impossible to create the SAML token");
            _log.error(ex);
            setForward(actionRequest, "portlet.login.stork.error");
        }

        if (token != null) {
            actionResponse.setRenderParameter("SAMLToken", PEPSUtil.encodeSAMLToken(token));
            actionResponse.setRenderParameter("CCountry", ParamUtil.getString(actionRequest, "citizenCountry"));
            actionResponse.setRenderParameter("PEPSUrl",
                    PrefsPropsUtil.getString(themeDisplay.getCompanyId(), FedPropsKeys.STORK_SPEPS_URL));
            setForward(actionRequest, "portlet.login.stork.peps");
        }
    }
}