package com.plugin; import com.novell.nxpe.NxpeCondition; 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; public class MyConditionExtn implements NxpeCondition{ private String interfaceID; /** NxpeParameterList will be initialized during initialize() call */ private NxpeParameterList configurationValues; /** This parameter is Credential Profile:LDAP Credentials:LDAP User DN */ private static final int EV_LDAP_USER_DN = 100; /** This parameter is LDAP Attribute:employeeType */ private static final int EV_LDAP_EMPLOYEE_TYPE = 200; @Override public NxpeResult evaluate(NxpeInformationContext informationContext, NxpeResponseContext responseContext) throws NxpeException { NxpeResult conditionResult = NxpeResult.ConditionFalse; String strLDAPUserDN = ""; String employeeType=""; try { System.out.println("******************Inside the Condition Extension plugin*****************"); strLDAPUserDN = getLDAPUserDN(informationContext); employeeType = getLDAPemployeeType(informationContext); System.out.println("User DN: "+strLDAPUserDN); System.out.println("Employee Type: "+employeeType); /** * Write your complex and custom business logic here and return ConditionTrue or ConditionFalse */ //Following code is just an example if(strLDAPUserDN!=null && strLDAPUserDN.contains("OU=All Users")){ if(employeeType!=null && employeeType.equalsIgnoreCase("employee")){ System.out.println("Returning Condition = true for employee"); conditionResult = NxpeResult.ConditionTrue; } else{ System.out.println("Returning Condition = false for non-employee"); conditionResult = NxpeResult.ConditionFalse; } }else{ System.out.println("Returning Condition = false User DN is no in All User OU"); conditionResult = NxpeResult.ConditionFalse; } } catch (NxpeException ex) { ex.printStackTrace(); conditionResult = NxpeResult.ConditionFalse; } System.out.println("******************End of the Condition Extensopn plugin*****************"); return conditionResult; } @Override public void initialize(NxpeParameterList configurationValues) throws NxpeException { this.configurationValues = configurationValues; } @Override public void setInterfaceId(String arg0) throws NxpeException { this.interfaceID = arg0; } private String getLDAPUserDN(NxpeInformationContext informationContext) throws NxpeException { NxpeParameter pLDAPUserDN; if ((pLDAPUserDN = this.configurationValues.getParameter(EV_LDAP_USER_DN)) != null) { Object strLDAPUserDN = informationContext.getData(pLDAPUserDN); String userDN =null; if (strLDAPUserDN instanceof String[]){ userDN = ((String[])strLDAPUserDN)[0]; }else{ userDN = (String)strLDAPUserDN; } return userDN; } else { NxpeException nxpeException = new NxpeException(NxpeResult.ErrorDataUnavailable, "EV_LDAP_USER_DN not present."); throw (nxpeException); } } private String getLDAPemployeeType(NxpeInformationContext informationContext) throws NxpeException { NxpeParameter pLDAPemployeeType; if((pLDAPemployeeType = this.configurationValues.getParameter(EV_LDAP_EMPLOYEE_TYPE))!= null) { Object strLDAPemployeeType = informationContext.getData(pLDAPemployeeType); String employeeType =null; if (strLDAPemployeeType instanceof String[]){ employeeType = ((String[])strLDAPemployeeType)[0]; }else{ employeeType = (String)strLDAPemployeeType; } return employeeType; }else{ NxpeException nxpeException = new NxpeException(NxpeResult.ErrorDataUnavailable, "EV_LDAP_EMPLOYEE_TYPE not present."); throw (nxpeException); } } }