Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » How to pass attributes from java filter to doFilter(PLEASE HELP... I have a filter that gets the LDAP info, I'm just trying to pass the empid from the public boolean isUserAuthorized section to the doFilter section empid = attributes.get("empid&qu)
How to pass attributes from java filter to doFilter [message #1732318] Sun, 15 May 2016 18:29
Deon Gee is currently offline Deon GeeFriend
Messages: 2
Registered: May 2016
Junior Member
I have a filter that gets the LDAP info, I'm just trying to pass the empid from the public boolean isUserAuthorized section to the doFilter section empid = attributes.get("empid").toString(); System.out.print("DoFilter empid: " +empid); but it is not working. What am I doing wrong?

PLEASE HELP I've been working on this for 2 weeks.

import java.io.IOException;
import javax.naming.directory.Attributes;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.sql.DataSource;

import org.apache.commons.configuration.Configuration;

public class myFilter extends LdapFilter {
public static FilterConfig filterConfig;
public static Attributes attributes;
public AuditOracleImpl auditor = null;

public void init(FilterConfig filterConfig) throws ServletException {
  super.init(filterConfig);
  List<String>categories = new ArrayList<String>();
  categories.add("LDAP");
  try {
    super.setConfig(categories);
  } catch (Exception ex) { 
    throw new ServletException(ex);
  } 
  try {
   // Load configuration properties.
   List<String> configList = new ArrayList<String>();
   configList.add("TC");
   configList.add("TCA");
   configList.add("LDAP");

   Configuration config = SystemUtils.getConfiguration(configList);
   String strDbConnTCA = config.getString("DB_CONN_TCA");
   String strDbUserTCA = config.getString("DB_USER_TCA");
   String strDbPassTCA = config.getString("DB_PASS_TCA");
   String strWallet = config.getString("WALLET_FILE");

   //Obtain connection to the database.
   DataSource dataSourceCa = OracleClient.getDataSource(strDbConnTCA, strDbUserTCA, trDbPassTCA, strWallet);
   auditor = new AuditOracleImpl(dataSourceCa);
   } catch (Exception ex) {
   logger.error("Unable to create auditor {}", ex.getMessage());
   }
 }

 @Override 
 public boolean isUserAuthorized(Attributes attributes) {
  boolean isAuthorized = false;
  if (attributes !=null && attributes.size() > 0 ) {
    isAuthorized = true;
    logger.info("Authorized: " + isAuthorized);
    Properties properties = new Properties();
  try {
   propertiesUser.setProperty("CN", attributes.get("actualdn").get().toString().replaceFirst("CN=", "")); 
   propertiesUser.setProperty("EID", attributes.get("empid").get().toString();
   propertiesUser.setProperty("EMAIL", attributes.get("empemail").get().toString();
   auditor.user(propertiesUser);

  } catch (Exception e) {
   logger.error("Error updating user:{}", e.getMessage());
   e.printStackTrace();
  } 
  String[] items = {"accesstime", "empid", "ipAddress", "actualdn", "empemail"};
  String result = parseData(items, attributes);
  String empid = attributes.get("empid").toString(); 
  //this is what i'm tyring to put in parameter to pass to the next servlet.

    logger.info(result);
    System.out.print("This is the empID: " + empid); 
    //this prints out okay
   }
 logger.info("isAuthorized: " + isAuthorized);
 return isAuthorized;
}

public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain, Attributes attributes) throws IOException, ServletException {
     empid = attributes.get("empid").toString();
     chain.doFilter(request, response);
     request.getAttribute(empid);
     System.out.print("DoFilter empid: " +empid); 
     //Nothing prints out.
}
public void destroy() {
}
Previous Topic:!MESSAGE [SCR] Method was not found:
Next Topic:Tomcat with Equinox OSGi Bridge and Gemini Blueprint
Goto Forum:
  


Current Time: Wed Oct 09 13:08:34 GMT 2024

Powered by FUDForum. Page generated in 0.03146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top