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(String name, String defaultValue) 

Source Link

Usage

From source file:com.abubusoft.liferay.google.GoogleOAuth.java

License:Open Source License

protected GoogleAuthorizationCodeFlow getFlow(long companyId) throws Exception {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();

    InputStream is = GoogleOAuth.class.getResourceAsStream(_CLIENT_SECRETS_LOCATION);

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(is));

    //clientSecrets.getDetails().      
    String apiKey = PrefsPropsUtil.getString(companyId, "google.api.key");
    String apiSecret = PrefsPropsUtil.getString(companyId, "google.api.secret");
    String apiCallbackURL = PrefsPropsUtil.getString(companyId, "google.api.callback.url");

    if (apiKey != null && apiKey.trim().length() > 0) {
        clientSecrets.getDetails().setClientId(apiKey);
    }//from   w ww .  java 2  s.  c  o  m
    if (apiSecret != null && apiSecret.trim().length() > 0) {
        clientSecrets.getDetails().setClientSecret(apiSecret);
    }
    if (apiCallbackURL != null && apiCallbackURL.trim().length() > 0) {
        clientSecrets.getDetails().getRedirectUris().add(apiCallbackURL);
    }

    GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
            jsonFactory, clientSecrets, _SCOPES);

    builder.setAccessType("online");
    builder.setApprovalPrompt("force");

    return builder.build();
}

From source file:com.abubusoft.liferay.linkedin.LinkedinOAuth.java

License:Open Source License

public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

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

    long companyId = themeDisplay.getCompanyId();

    //String linkedinAuthURL = PropsUtil.get("linkedin.api.auth.url");
    String linkedinApiKey = PrefsPropsUtil.getString(companyId, "linkedin.api.key");
    String linkedinApiSecret = PrefsPropsUtil.getString(companyId, "linkedin.api.secret");
    String linkedinCallbackURL = PrefsPropsUtil.getString(companyId, "linkedin.api.callback.url");

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

    if (cmd.equals("login")) {
        final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret)
                .scope("r_basicprofile,r_emailaddress")
                // replace with desired scope
                .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance());

        // Obtain the Request Token
        String url = service.getAuthorizationUrl();

        response.sendRedirect(url);//from   www. j a va2s  .  c o m
    } else if (cmd.equals("token")) {
        final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret)
                .scope("r_basicprofile,r_emailaddress")
                // replace with desired scope
                .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance());

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

        final OAuth2AccessToken accessToken = service.getAccessToken(code);
        HttpSession session = request.getSession();

        Map<String, Object> linkedinData = getLinkedinData(service, accessToken);

        User user = getOrCreateUser(themeDisplay.getCompanyId(), linkedinData);

        if (user != null) {
            session.setAttribute(LinkedinConstants.LINKEDIN_ID_LOGIN, user.getUserId());

            sendLoginRedirect(request, response);

            return null;
        }

        session.setAttribute(LinkedinConstants.LINKEDIN_LOGIN_PENDING, Boolean.TRUE);

        sendCreateAccountRedirect(request, response, linkedinData);
    }

    return null;
}

From source file:com.abubusoft.liferay.twitter.TwitterOAuth.java

License:Open Source License

public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

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

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

    long companyId = themeDisplay.getCompanyId();

    String twitterApiKey = PrefsPropsUtil.getString(companyId, "twitter.api.key");
    String twitterApiSecret = PrefsPropsUtil.getString(companyId, "twitter.api.secret");
    String twitterCallbackURL = PrefsPropsUtil.getString(companyId, "twitter.api.callback.url");

    if (cmd.equals("login")) {

        final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret)
                .callback(twitterCallbackURL).build(TwitterApi.instance());

        // Obtain the Request Token
        final OAuth1RequestToken requestToken = service.getRequestToken();
        String url = service.getAuthorizationUrl(requestToken);

        response.sendRedirect(url);// w  ww . j  a v  a 2s.  c  om
    } else if (cmd.equals("token")) {

        HttpSession session = request.getSession();

        String oauthVerifier = ParamUtil.getString(request, "oauth_verifier");
        String oauthToken = ParamUtil.getString(request, "oauth_token");

        if (Validator.isNull(oauthVerifier) || Validator.isNull(oauthToken)) {
            return null;
        }

        final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret)
                .callback(twitterCallbackURL).build(TwitterApi.instance());

        final OAuth1RequestToken requestToken = new OAuth1RequestToken(oauthToken, twitterApiSecret);
        final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);

        Map<String, Object> twitterData = getTwitterData(service, accessToken);

        User user = getOrCreateUser(themeDisplay.getCompanyId(), twitterData);

        if (user != null) {
            session.setAttribute(TwitterConstants.TWITTER_ID_LOGIN, user.getUserId());

            sendLoginRedirect(request, response);

            return null;
        }

        session.setAttribute(TwitterConstants.TWITTER_LOGIN_PENDING, Boolean.TRUE);

        sendCreateAccountRedirect(request, response, twitterData);
    }

    return null;
}

From source file:com.crm.subscriber.service.impl.SubscriberOrderLocalServiceImpl.java

License:Open Source License

public void emailTicket(long userId, long orderId, Date orderDate, String sendTo, String subject,
        String content) throws PortalException, SystemException {
    User user = userLocalService.getUser(userId);

    SubscriberOrder order = subscriberOrderPersistence.fetchByPrimaryKey(orderId);

    String endPoint = AppDomainLocalServiceUtil.getStringDomain("SERVICE", "resend");
    if (Validator.isNull(endPoint)) {
        endPoint = "http://183.91.14.218:8080/ChargingWS/services/charging";
    }/*from  w w  w .j  a  va 2  s  . c  o m*/
    System.out.println(endPoint);

    try {
        MerchantEntry merchant = MerchantEntryLocalServiceUtil.fetchMerchant(order.getMerchantId());
        MerchantAgent agent = MerchantAgentLocalServiceUtil.fetchAgent(order.getAgentId());
        ProductEntry product = ProductEntryLocalServiceUtil.fetchProduct(order.getProductId());

        if ((merchant != null) && (product != null)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");

            SMSRequest req = new SMSRequest();

            req.setIsdn(order.getIsdn());
            req.setCpId(order.getMerchantId());
            req.setAgentId(order.getAgentId());
            req.setDeliveryContent(order.getShippingTo());
            req.setPassword(agent.getPassword());
            req.setUsername(agent.getScreenName());
            req.setProduct(product.getAlias());
            req.setReqDate(dateFormat.format(new Date()));

            ChargingHttpBindingStub stub = new ChargingHttpBindingStub(new URL(endPoint), null);

            ServiceResponse res = stub.sendSMS(req);

            if (res != null) {
                if (!res.getStatus().equalsIgnoreCase("SV0000")) {
                    throw new PortalException("resend-error:" + res.getStatus());
                }
            }
        }

    } catch (PortalException e) {
        throw e;
    } catch (Exception e) {
        throw new PortalException(e.getMessage());
    }

    String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);

    if (Validator.isNull(fromAddress) || Validator.isNull(fromName)) {
        throw new PortalException("unknow-email-sender");
    }

    sendTo = Validator.isNull(sendTo) ? fromAddress : sendTo;
    subject = Validator.isNull(subject) ? "resend content to subscriber" : subject;

    if (Validator.isNull(content) && (order != null)) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:sss");

        content = "User " + user.getScreenName() + " request resend content to subscriber " + order.getIsdn()
                + ".\r\n";
        content += "Request date: " + dateFormat.format(new Date()) + "\r\n";
        content += "Order date   : " + dateFormat.format(order.getOrderDate()) + "\r\n";
        content += "Product      : " + DisplayUtil.getProductTitle(order.getProductId()) + "\r\n";
        content += "Content      : " + order.getShippingTo() + "\r\n";
    }

    // build bulk receivers
    try {
        InternetAddress from = new InternetAddress(fromAddress, fromName);

        String[] toAddress = StringUtil.split(sendTo);

        MailMessage message = null;

        if (toAddress.length == 1) {
            InternetAddress to = new InternetAddress(toAddress[0]);

            message = new MailMessage(from, to, subject, content, true);
        } else {
            InternetAddress[] to = new InternetAddress[toAddress.length];

            for (int j = 0; j < toAddress.length; j++) {
                to[j] = new InternetAddress(toAddress[j]);
            }

            message = new MailMessage(from, subject, content, true);
        }

        message.setHTMLFormat(true);
        MailEngine.send(message);
    } catch (MailEngineException e) {
        throw new PortalException(e);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.evolveum.liferay.usercreatehook.service.CustomUserLocalServiceImpl.java

License:Apache License

protected static void sendEmail(String wsCall, long companyId) {
    try {// w  w  w.  java 2 s  .c o m

        String fromName = PrefsPropsUtil.getString(companyId, "admin.email.from.name");
        String fromAddress = PrefsPropsUtil.getString(companyId, "admin.email.from.address");

        String toAddress = fromAddress;
        String toName = fromName;

        ClassLoader classLoader = CustomUserLocalServiceImpl.class.getClassLoader();

        SimpleDateFormat sdf = new SimpleDateFormat(TIME_PATTERN);
        String serverTime = sdf.format(new Date());

        String subject = StringUtil.read(classLoader, "content/email/email_ws_error_subject.tmpl");
        String body = StringUtil.read(classLoader, "content/email/email_ws_error_body.tmpl");

        subject = StringUtil.replace(subject,
                new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                        "[$WS_CALL$]", "[$SERVER_TIME$]" },
                new String[] { fromAddress, fromName, toAddress, toName, wsCall, serverTime });

        body = StringUtil.replace(body,
                new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                        "[$WS_CALL$]", "[$SERVER_TIME$]" },
                new String[] { fromAddress, fromName, toAddress, toName, wsCall, serverTime });

        InternetAddress from = new InternetAddress(fromAddress, fromName);

        InternetAddress to = new InternetAddress(toAddress, toName);

        MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

        MailServiceUtil.sendEmail(mailMessage);
    } catch (Exception e) {
        LOG.error("Error while sending email: " + e.getMessage(), e);
    }
}

From source file:com.liferay.content.targeting.analytics.util.AnalyticsUtil.java

License:Open Source License

private static String _getString(long groupId, String key, String defaultValue) {

    try {/*from  ww  w .  ja va 2s.  co m*/
        Group group = GroupLocalServiceUtil.getGroup(groupId);

        UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties();

        String companyValue = PrefsPropsUtil.getString(group.getCompanyId(), key);

        return GetterUtil.getString(typeSettingsProperties.getProperty(key), companyValue);
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:com.liferay.google.apps.connector.GAuthenticator.java

License:Open Source License

protected void doInit() throws Exception {
    if (_companyId > 0) {
        Company company = CompanyLocalServiceUtil.getCompany(_companyId);

        _domain = company.getMx();/*  w w w.  j a v a  2 s . co m*/
        _userName = PrefsPropsUtil.getString(_companyId, "google.apps.username");
        _password = PrefsPropsUtil.getString(_companyId, "google.apps.password");
    }

    Http.Options options = new Http.Options();

    options.addPart("accountType", "HOSTED");

    String emailAddress = _userName;

    if (!emailAddress.contains(StringPool.AT)) {
        emailAddress = _userName.concat(StringPool.AT).concat(_domain);
    }

    options.addPart("Email", emailAddress);

    options.addPart("Passwd", _password);
    options.addPart("service", "apps");
    options.setLocation("https://www.google.com/accounts/ClientLogin");
    options.setPost(true);

    String content = HttpUtil.URLtoString(options);

    Properties properties = PropertiesUtil.load(content);

    _error = properties.getProperty("Error");

    if ((_error != null) && _log.isInfoEnabled()) {
        _log.info("Unable to initialize authentication token: " + _error);
    }

    _authenticationToken = properties.getProperty("Auth");

    if ((_authenticationToken != null) && _log.isInfoEnabled()) {
        _log.info("Authentication token " + _authenticationToken);
    }

    _initTime = System.currentTimeMillis();
}

From source file:com.liferay.google.drive.repository.GoogleDriveRepository.java

License:Open Source License

protected GoogleDriveSession buildGoogleDriveSession() throws IOException, PortalException {

    long userId = PrincipalThreadLocal.getUserId();

    User user = UserLocalServiceUtil.getUser(userId);

    if (user.isDefaultUser()) {
        throw new PrincipalException("User is not authenticated");
    }/*from ww w .ja  v a  2 s  . com*/

    GoogleCredential.Builder builder = new GoogleCredential.Builder();

    String googleClientId = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-id");
    String googleClientSecret = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-secret");

    builder.setClientSecrets(googleClientId, googleClientSecret);

    JacksonFactory jsonFactory = new JacksonFactory();

    builder.setJsonFactory(jsonFactory);

    HttpTransport httpTransport = new NetHttpTransport();

    builder.setTransport(httpTransport);

    GoogleCredential googleCredential = builder.build();

    ExpandoBridge expandoBridge = user.getExpandoBridge();

    String googleAccessToken = GetterUtil.getString(expandoBridge.getAttribute("googleAccessToken", false));

    googleCredential.setAccessToken(googleAccessToken);

    String googleRefreshToken = GetterUtil.getString(expandoBridge.getAttribute("googleRefreshToken", false));

    googleCredential.setRefreshToken(googleRefreshToken);

    Drive.Builder driveBuilder = new Drive.Builder(httpTransport, jsonFactory, googleCredential);

    Drive drive = driveBuilder.build();

    Drive.About driveAbout = drive.about();

    Drive.About.Get driveAboutGet = driveAbout.get();

    About about = driveAboutGet.execute();

    return new GoogleDriveSession(drive, about.getRootFolderId());
}

From source file:com.liferay.google.GoogleOAuth.java

License:Open Source License

protected GoogleAuthorizationCodeFlow getFlow(long companyId) throws IOException, SystemException {

    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();

    GoogleAuthorizationCodeFlow.Builder builder = null;

    String googleClientId = PrefsPropsUtil.getString(companyId, "google.client.id");
    String googleClientSecret = PrefsPropsUtil.getString(companyId, "google.client.secret");

    List<String> scopes = null;

    if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) {
        scopes = _SCOPES_DRIVE;// www  .  j  a va  2  s  .com
    } else {
        scopes = _SCOPES_LOGIN;
    }

    if (Validator.isNull(googleClientId) || Validator.isNull(googleClientSecret)) {

        InputStream is = GoogleOAuth.class.getResourceAsStream(_CLIENT_SECRETS_LOCATION);

        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(is));

        builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, scopes);
    } else {
        builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, googleClientId,
                googleClientSecret, scopes);
    }

    String accessType = "online";

    if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) {
        accessType = "offline";
    }

    builder.setAccessType(accessType);
    builder.setApprovalPrompt("force");

    return builder.build();
}

From source file:com.liferay.google.login.hook.action.GoogleLoginAction.java

License:Open Source License

protected GoogleAuthorizationCodeFlow getGoogleAuthorizationCodeFlow(long companyId) throws Exception {

    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();
    String googleClientId = PrefsPropsUtil.getString(companyId, "google-client-id");
    String googleClientSecret = PrefsPropsUtil.getString(companyId, "google-client-secret");

    List<String> scopes = null;

    if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) {
        scopes = _SCOPES_DRIVE;//  w w w . j  a  va2s .c  o  m
    } else {
        scopes = _SCOPES_LOGIN;
    }

    GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
            jsonFactory, googleClientId, googleClientSecret, scopes);

    String accessType = "online";

    if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) {
        accessType = "offline";
    }

    builder.setAccessType(accessType);

    builder.setApprovalPrompt("force");

    return builder.build();
}