Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to pass boolean attributes within 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 to the doFilter section empid = attributes.get("empid"))
icon5.gif  How to pass boolean attributes within java filter to doFilter [message #1732694] Thu, 19 May 2016 02:25 Go to next message
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() {
}
Re: How to pass boolean attributes within java filter to doFilter [message #1732942 is a reply to message #1732694] Mon, 23 May 2016 09:14 Go to previous message
Alexander Bunkowski is currently offline Alexander BunkowskiFriend
Messages: 29
Registered: February 2014
Junior Member
Hey Deon.

Since your code has nothing to do with Eclipse, this forum is the wrong place for such a question.
If you post your Question again in an other Java Forum consider providing a minimal but complete code example and the exception.
These are two reasons why you don't get an answer here.

Hope that helps,
Alex
Previous Topic:How does one get the minimize and maximize view menu items to render on the view menu?
Next Topic:Eclipse 4.5.2 process suspends when launching RCP with debugger
Goto Forum:
  


Current Time: Thu Apr 25 18:09:56 GMT 2024

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

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

Back to the top