package com.plugin; /* Copyright (c) 2012 Novell, Inc. All Rights Reserved. Novell grants permission, free of charge, to any person obtaining copies of this software and its associated documentation files (the "Software"), to deal in the Software without restriction, including to use, copy, adapt, publish, distribute, display, perform, sublicense, and sell copies of the Software, subject to the following condition: You must include the above copyright notice and this permission notice in all full or partial copies of the Software. NOVELL PROVIDES THE SOFTWARE "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGMENT. NOVELL, THE AUTHORS OF THE SOFTWARE, AND THE OWNERS OF COPYRIGHT IN THE SOFTWARE ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import com.novell.nxpe.NxpeContextDataElement; import com.novell.nxpe.NxpeException; import com.novell.nxpe.NxpeInformationContext; import com.novell.nxpe.NxpeParameter; import com.novell.nxpe.NxpeParameterList; import com.novell.nxpe.NxpeResponseContext; import com.novell.nxpe.NxpeResult; /** * This is an example code for a "Data" type of Policy Extension. getValue() is * the method which has to be modified by the user to code the data logic. Most * of other code can be retained as it is. */ public class MyDataExtn implements NxpeContextDataElement { private static final int EV_LDAP_EMPLOYEE_TYPE = 100; /** NxpeContextDataElement values */ private final String strName; private final int iEnumerativeValue; private final String strParameter; /** NxpeParameterList will be initialized during initialize() call */ private NxpeParameterList configurationValues; /** Constructor. Called by PolicyDataExtTemplateFactory class */ public MyDataExtn(String name, int enumerationValue, String parameter) { this.strName = name; this.iEnumerativeValue = enumerationValue; this.strParameter = parameter; } /** * Initialize the configuration values * * @required * @param configurationValues * :NxpeParameterList: The configuration parameters passed by * policy engine are used to initialize the * NxpeContextDataElement object and are the parameters that the * extension requires to retrieve data. * * @throws com.novell.nxpe.NxpeException */ @Override public void initialize(NxpeParameterList configurationValues) throws NxpeException { this.configurationValues = configurationValues; } @Override public int getEnumerativeValue() { return this.iEnumerativeValue; } @Override public String getName() { return this.strName; } @Override public String getParameter() { return this.strParameter; } @Override public Object getValue(NxpeInformationContext informationContext, NxpeResponseContext responseContext) throws NxpeException { Object res = ""; try { String strEmployeeType = ""; strEmployeeType = getLDAPEmloyeeType(informationContext); /** * Write your business logic here and return and Object * sample logic: Starts */ if (strEmployeeType != null && strEmployeeType.equalsIgnoreCase("employee")) { res = "Full Time Employee"; System.out.println("MyDataExtn Plugin: Return Value --> "+res); } else if(strEmployeeType != null && (strEmployeeType.equalsIgnoreCase("vendor") ||strEmployeeType.equalsIgnoreCase("contractor"))) { res = "Contractor"; System.out.println("MyDataExtn Plugin: Return Value --> "+res); } else{ res = ""; System.out.println("MyDataExtn Plugin: Return Value --> "+res); } /** * sample logic: ends */ } catch (NxpeException ex) { ex.printStackTrace(); res = ""; } return res; } private String getLDAPEmloyeeType(NxpeInformationContext informationContext) throws NxpeException { NxpeParameter pLDAPemployeeType; if ((pLDAPemployeeType = this.configurationValues.getParameter(EV_LDAP_EMPLOYEE_TYPE)) != null) { Object strEmployeeType = informationContext.getData(pLDAPemployeeType); String empType =null; if (strEmployeeType instanceof String[]) empType = ((String[])strEmployeeType)[0]; else empType = (String)strEmployeeType; return empType; } else { NxpeException nxpeException = new NxpeException( NxpeResult.ErrorDataUnavailable, "MyDataExtn Plugin : employeeType not present."); throw (nxpeException); } } }