
« Volver a Wiki - Pending...
Adding Custom Properties
Table of Contents [-]
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 #
71229 Accesos