« Zurück zu Wiki - Pending...

Adding Custom Properties

Asset-Tag: customization

This article is pending deletion for not enough information. For more information, please see Wiki - Pending Deletion.

Introduction #

This guide explains how to do add your own custom properties in Liferay. It attempts to leverage the Liferay properties infrastructure to maintain consistency.

Requirements #

The only prerequisite to customizing your own set of properties is that the Liferay development environment is setup (see the topic Setting up the Extension Environment).

How it works #

This is a custom deployment -- there are however other ways of doing this.

  • Subclass com.liferay.portal.util.PropsUtil and define your custom properties. For example we created a class com.liferay.portal.util.USCPropsUtil:
package com.liferay.portal.util;
import com.liferay.portal.util.PropsUtil;
/* *
* This class extends the PropsUtil class for additional properties needed. *
*/
public class USCPropsUtil extends PropsUtil {
        // Shibboleth Authentication properties        public static final String USC_AUTH_SHIB_UID = "usc.auth.shibboleth.uid";        public static final String USC_AUTH_SHIB_USCOWNERPVID = "usc.auth.shibboleth.uscownerpvid";        public static final String USC_AUTH_SHIB_MAIL = "usc.auth.shibboleth.mail";        public static final String USC_AUTH_SHIB_DISPLAYNAME = "usc.auth.shibboleth.displayname";//

// Shibboleth User Group properties }}}}//

*Add/map the custom properties to /ext-impl/classes/portal-ext.properties.  For example we created a section within portal-ext.properties for our custom properties:

{{{
##
## USC specific properties 
##

    #
    # Shibboleth Authentication properties.  
    # These define the HTTP header variables that will contain the user attributes.
    # All variables must be populated otherwise the user cannot successfully authenticate.
    #
    usc.auth.shibboleth.uid=shib-person-uid
    usc.auth.shibboleth.uscownerpvid=shib-person-uscownerpvid
    usc.auth.shibboleth.mail=shib-person-mail
    usc.auth.shibboleth.displayname=shib-person-displayname
  • Use it in your classes. For example we read our properties within our custom AutoLogin module. The value returned can optionally be passed through one of the methods in com.liferay.util.PrefPropsUtil to translate into various data types:
    try {
        companyId = PortalUtil.getCompany(req).getCompanyId();

        userScreenName = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_UID));
        uscpvid = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_USCOWNERPVID));
        mail = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_MAIL));
        displayName = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_DISPLAYNAME));
    }
    catch (Exception e) {
               _log.error(StackTraceUtil.getStackTrace(e));
    }

Notes #

  • This has not been tested with Portlets!
  • This has been tested with Liferay Core

Related Articles #

Development in the ext environment

0 Anhänge
71231 Angesehen
Durchschnitt (1 Stimme)
Die durchschnittliche Bewertung ist 2.0 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
Is this still a valid way to add custom... Dave Morris 2. Juni 2009 17:57
I noticed that these properties are now stored... Dave Morris 2. Juni 2009 18:02
I've done something to the point of: /* * *... Rob J Pontious 4. Juni 2009 12:28
I was able to add a custom property by... Matthieu Levesque 23. August 2011 08:42
In portal-ext add your own property... Mohammad Azharuddin 31. Mai 2013 07:51
I have added property in portal-ext.properties ... Suman Chatterjee 7. Juli 2014 02:58

Is this still a valid way to add custom properties in the ext environment? I'm getting this error when I try to follow this pattern:

Implicit super constructor PropsUtil() is not visible for default constructor. Must define an explicit constructor

This is because the PropsUtil constructor is private. Is this correct? What is the proper way to extend the portal-ext.properties file in Liferay 5.2.2?
Gepostet am 02.06.09 17:57.
I noticed that these properties are now stored in PropsKeys.java

Maybe this is the correct class to extend. Can anyone confirm this? If so, I will update this wiki page, or create a new version.

Thanks for the help,

Dave Morris
Gepostet am 02.06.09 18:02 als Antwort auf Dave Morris.
I've done something to the point of:

/*
*
* This class extends the PropsUtil class for additional properties needed.
*
*/
public class CustomPropsUtil extends PropsValues {

// Default phases
public static final String DEFAULT_VAR = PropsUtil.get("default.var");
}

In portal-ext.properties I've added a default.var with a value, but when I call as:

String defaultPhasesString = CustomPropsUtil.DEFAULT_PHASES;

I get a value of null returned. So I'm missing something somehow. But maybe that'll help you Dave?
Gepostet am 04.06.09 12:28 als Antwort auf Dave Morris.
I was able to add a custom property by implementing the com.liferay.portal.kernel.util.PropsKeys and declaring final static string vars.

public class WebPortalKeys implements PropsKeys {
public static final String LCC_PORTAL_GRP_EMP = "lcc.portal.group.emp";
public static final String LCC_PORTAL_GRP_ETU = "lcc.portal.group.etu";

public static final String LCC_PORTAL_PORTAL_COMMUNITY_EMP = "lcc.portal.community.emp";
public static final String LCC_PORTAL_PORTAL_COMMUNITY_ETU = "lcc.portal.community.etu";
}

Using this call I was able to retreive the value "gr-emp" set in my portal-ext.properties:
PrefsPropsUtil.getString(companyId, WebPortalKeys.LCC_PORTAL_GRP_EMP);
Gepostet am 23.08.11 08:42 als Antwort auf Rob J Pontious.
In portal-ext add your own property
showroom.city.names=bangalore,mangalore,chennai


And in Java use below code to get the values
import com.liferay.portal.kernel.util.PropsUtil;
String type = PropsUtil.get("showroom.city.names");
Gepostet am 31.05.13 07:51 als Antwort auf Matthieu Levesque.
I have added property in portal-ext.properties

endpoint_url=http\://myip\:8180/

here myip is a end point url

but when i try to fetch the same in my ext impl class the value is coming as null
String strEndPointURL = PropsUtil.get("endpoint_url");
everything was working fine before but since i have made update to the file and redeployed it is not working.
As informed in other posts i have deployed and restarted my jboss server twice once for the extensive environment to load and second for other plugins to load but still with no success, any help would be appreciated
Gepostet am 07.07.14 02:58 als Antwort auf mohammad azaruddin.