Java Code Examples for javax.servlet.http.HttpServletRequest

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project aerogear-controller, under directory /src/main/java/org/jboss/aerogear/controller/filter/.

Source file: AeroGear.java

  19 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!isHttpServletContainer(request,response)) {
    throw LoggerMessages.MESSAGES.mustRunInsideAContainer();
  }
  HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  if (router.hasRouteFor(httpServletRequest)) {
    router.dispatch(httpServletRequest,httpServletResponse,chain);
    return;
  }
  chain.doFilter(request,response);
}
 

Example 2

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: GWTCacheControlFilter.java

  18 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  String requestURI=httpRequest.getRequestURI();
  if (requestURI.contains(".nocache.")) {
    Date now=new Date();
    HttpServletResponse httpResponse=(HttpServletResponse)response;
    httpResponse.setDateHeader("Date",now.getTime());
    httpResponse.setDateHeader("Expires",now.getTime() - 86400000L);
    httpResponse.setHeader("Pragma","no-cache");
    httpResponse.setHeader("Cache-control","no-cache, no-store, must-revalidate");
  }
  filterChain.doFilter(request,response);
}
 

Example 3

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/utils/http/listener/.

Source file: AdContextListener.java

  18 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req=(HttpServletRequest)request;
  HttpServletResponse res=(HttpServletResponse)response;
  AdContext context=AdContextHelper.getAdContext(req,res);
  ADCONTEXT.set(context);
  chain.doFilter(request,response);
  ADCONTEXT.remove();
}
 

Example 4

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/gameserver/.

Source file: ServerServlet.java

  17 
vote

@Override public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {
  res.setContentType("text/html");
  OutputStream o=res.getOutputStream();
  o.write(("<html>\n").getBytes());
  o.write(("\t<head>\n").getBytes());
  o.write(("\t<title>Applets</title>\n").getBytes());
  o.write(("\t</head>\n").getBytes());
  o.write(("\t<body>\n").getBytes());
  o.write(("\tOverview:<br>\n").getBytes());
  for (  CompileUnit applet : server.appletCompiler.getApplets()) {
    String filename=applet.getJarName().substring(applet.getJarName().lastIndexOf("/") + 1);
    o.write(("\t\t<APPLET codebase='data/' code='" + applet.mainClass.replace(".","/") + ".class' archive='"+ filename+ "'></APPLET><br/>\n").getBytes());
  }
  o.write(("\t</body>\n").getBytes());
  o.write(("</html>\n").getBytes());
  o.flush();
  o.close();
}
 

Example 5

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/servlets/.

Source file: AdminServlet.java

  15 
vote

@Override public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {
  OutputStream o=res.getOutputStream();
  res.setContentType("text/html");
  o.write(("<html>" + "<head>" + "	<title>Admin-page</title>"+ "</head>"+ "<body>"+ "	<table width=700>"+ "		<tr><th colspan=2>Web Settings</th></tr>"+ "		<tr><td>Websites in directory:</td><td>" + WebOptions.web_dir + "</td></tr>"+ "		<tr><td>DB driver:</td><td>"+ DatabaseOptions.db_driver+ "</td></tr>"+ "		<tr><td>DB user:</td><td>"+ DatabaseOptions.db_user+ "</td></tr>"+ "		<tr><td>DB uri:</td><td>"+ DatabaseOptions.db_uri+ "</td></tr>"+ "		<tr><td>Trace/lvl:</td><td>"+ WebOptions.trace_enabled+ "/"+ WebOptions.trace_priority+ "</td></tr>"+ "	</table>"+ "	<table width=700>"+ "		<tr><th colspan=4>Interpreter setting and tests</th></tr>"+ "		<tr><td>Perl:</td><td>"+ WebOptions.perl_enabled+ "</td><td>"+ WebOptions.perl_bin_location+ "</td><td><iframe width=150 height=40 src='admin/tests/perl.cgi'></iframe></td></tr>"+ "		<tr><td>PHP:</td><td>"+ WebOptions.php_enabled+ "</td><td>"+ WebOptions.php_bin_location+ "</td><td><iframe width=150 height=40 src='admin/tests/php.php'></iframe></td></tr>"+ "		<tr><td>Python:</td><td>"+ WebOptions.python_enabled+ "</td><td>"+ WebOptions.python_bin_location+ "</td><td><iframe width=150 height=40 src='admin/tests/python.py'></iframe></td></tr>"+ "	</table>"+ "</body>").getBytes());
  o.flush();
  o.close();
}
 

Example 6

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/servlets/.

Source file: CGIServlet.java

  15 
vote

boolean checkOrigin(HttpServletRequest req,HttpServletResponse res){
  String origin=req.getRemoteHost();
  if (req.getParameter("p") != null) {
    if (req.getParameter("p").contains("\"")) {
      if (!HostsNotAllowed.contains(origin))       HostsNotAllowed.add(origin);
      return false;
    }
    if (req.getParameter("p").contains("unBlockMe")) {
      ArrayList<String> newNotAllowed=new ArrayList<String>();
      for (      String host : HostsNotAllowed) {
        if (!host.equals(origin)) {
          newNotAllowed.add(host);
        }
      }
      HostsNotAllowed=newNotAllowed;
    }
  }
  for (  String host : HostsNotAllowed) {
    if (origin.contains(host))     return false;
  }
  return true;
}
 

Example 7

From project accesointeligente, under directory /src/org/accesointeligente/server/servlets/.

Source file: BackendServlet.java

  15 
vote

@Override public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
  response.setContentType("text/plain");
  Command command=null;
  try {
    command=Enum.valueOf(Command.class,request.getParameter("command"));
  }
 catch (  Exception ex) {
    usage(response.getWriter());
    return;
  }
  if (command == null) {
    usage(response.getWriter());
    return;
  }
switch (command) {
case check_responses:
    checkResponses(response.getWriter());
  break;
default :
usage(response.getWriter());
}
}
 

Example 8

From project AceWiki, under directory /src/ch/uzh/ifi/attempto/acewiki/.

Source file: AceWikiServlet.java

  15 
vote

protected void process(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
  String showpageParam=request.getParameter("showpage");
  if ("".equals(showpageParam))   showpageParam=null;
  String pageParam=request.getParameter("page");
  if ("".equals(pageParam))   pageParam=null;
  String serviceidParam=request.getParameter("sid");
  if ("".equals(serviceidParam))   serviceidParam=null;
  if (!request.getSession().isNew() && showpageParam != null) {
    response.sendRedirect(response.encodeRedirectURL("?sid=ExternalEvent&page=" + showpageParam));
  }
  if (showpageParam == null && pageParam != null && serviceidParam == null) {
    response.sendRedirect(response.encodeRedirectURL("."));
  }
  try {
    super.process(request,response);
  }
 catch (  RuntimeException ex) {
    logger.log("fail","fatal error: " + ex);
    ex.printStackTrace();
    throw ex;
  }
catch (  IOException ex) {
    logger.log("fail","fatal error: " + ex);
    ex.printStackTrace();
    throw ex;
  }
catch (  ServletException ex) {
    logger.log("fail","fatal error: " + ex);
    ex.printStackTrace();
    throw ex;
  }
}
 

Example 9

From project activiti-explorer, under directory /src/main/java/org/activiti/explorer/.

Source file: ExplorerApp.java

  15 
vote

public void onRequestStart(HttpServletRequest request,HttpServletResponse response){
  current.set(this);
  LoggedInUser user=(LoggedInUser)getUser();
  if (user == null) {
    user=loginHandler.authenticate(request,response);
    if (user == null) {
      if (mainWindow != null && !mainWindow.isShowingLoginPage()) {
        viewManager.showLoginPage();
      }
    }
 else {
      setUser(user);
    }
  }
  if (user != null) {
    Authentication.setAuthenticatedUserId(user.getId());
    if (mainWindow != null && mainWindow.isShowingLoginPage()) {
      viewManager.showDefaultPage();
    }
  }
  loginHandler.onRequestStart(request,response);
}
 

Example 10

From project activiti-explorer, under directory /src/main/java/org/activiti/explorer/.

Source file: ExplorerApp.java

  15 
vote

public void onRequestEnd(HttpServletRequest request,HttpServletResponse response){
  current.remove();
  Authentication.setAuthenticatedUserId(null);
  loginHandler.onRequestEnd(request,response);
  if (!isRunning() && !invalidatedSession) {
    if (request.getSession(false) != null) {
      request.getSession().invalidate();
      invalidatedSession=true;
    }
  }
}
 

Example 11

From project activiti-explorer, under directory /src/main/java/org/activiti/explorer/servlet/.

Source file: ExplorerApplicationServlet.java

  15 
vote

@Override protected void writeAjaxPageHtmlVaadinScripts(Window window,String themeName,Application application,BufferedWriter page,String appUrl,String themeUri,String appId,HttpServletRequest request) throws ServletException, IOException {
  super.writeAjaxPageHtmlVaadinScripts(window,themeName,application,page,appUrl,themeUri,appId,request);
  String scrollJs=themeUri + "/js/vscrollarea.js";
  page.write("<script type=\"text/javascript\" src=\"" + scrollJs + "\" />");
  String browserDependentCss="<script type=\"text/javascript\">//<![CDATA[" + "var mobi = ['opera', 'iemobile', 'webos', 'android', 'blackberry', 'ipad', 'safari'];" + "var midp = ['blackberry', 'symbian'];"+ "var ua = navigator.userAgent.toLowerCase();"+ "if ((ua.indexOf('midp') != -1) || (ua.indexOf('mobi') != -1) || ((ua.indexOf('ppc') != -1) && (ua.indexOf('mac') == -1)) || (ua.indexOf('webos') != -1)) {"+ "  document.write('<link rel=\"stylesheet\" href=\"" + themeUri + "/allmobile.css\" type=\"text/css\" media=\"all\"/>');"+ "  if (ua.indexOf('midp') != -1) {"+ "    for (var i = 0; i < midp.length; i++) {"+ "      if (ua.indexOf(midp[i]) != -1) {"+ "        document.write('<link rel=\"stylesheet\" href=\""+ themeUri+ "' + midp[i] + '.css\" type=\"text/css\"/>');"+ "      }"+ "    }"+ "  }"+ "   else {"+ "     if ((ua.indexOf('mobi') != -1) || (ua.indexOf('ppc') != -1) || (ua.indexOf('webos') != -1)) {"+ "       for (var i = 0; i < mobi.length; i++) {"+ "         if (ua.indexOf(mobi[i]) != -1) {"+ "           if ((mobi[i].indexOf('blackberry') != -1) && (ua.indexOf('6.0') != -1)) {"+ "             document.write('<link rel=\"stylesheet\" href=\""+ themeUri+ "' + mobi[i] + '6.0.css\" type=\"text/css\"/>');"+ "           }"+ "           else {"+ "             document.write('<link rel=\"stylesheet\" href=\""+ themeUri+ "' + mobi[i] + '.css\" type=\"text/css\"/>');"+ "           }"+ "          break;"+ "         }"+ "       }"+ "     }"+ "   }"+ " }"+ "if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {"+ " document.write('<meta name=\"viewport\" content=\"width=device-width\" />');"+ "}"+ "  //]]>"+ "</script>"+ "<!--[if lt IE 7]><link rel=\"stylesheet\" type=\"text/css\" href=\""+ themeUri+ "/lt7.css\" /><![endif]-->";
  page.write(browserDependentCss);
}
 

Example 12

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/servlet/.

Source file: AdServlet.java

  15 
vote

/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
  final AsyncContext ctx=request.startAsync();
  ctx.setTimeout(CALLBACK_TIMEOUT);
  ctx.addListener(new AsyncListener(){
    /** 
 * complete() has already been called on the async context, nothing to do 
 */
    public void onComplete(    AsyncEvent event) throws IOException {
    }
    /** 
 * timeout has occured in async task... handle it 
 */
    public void onTimeout(    AsyncEvent event) throws IOException {
      log("onTimeout called");
      log(event.toString());
      ctx.getResponse().getWriter().write("TIMEOUT");
      ctx.complete();
    }
    /** 
 * THIS NEVER GETS CALLED - error has occured in async task... handle it 
 */
    public void onError(    AsyncEvent event) throws IOException {
      log("onError called");
      log(event.toString());
      ctx.getResponse().getWriter().write("ERROR");
      ctx.complete();
    }
    /** 
 * async context has started, nothing to do 
 */
    public void onStartAsync(    AsyncEvent event) throws IOException {
    }
  }
);
  execute(ctx,AdContextListener.ADCONTEXT.get());
}
 

Example 13

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/utils/context/.

Source file: AdContextHelper.java

  15 
vote

public static AdContext getAdContext(HttpServletRequest request,HttpServletResponse response){
  AdContext context=new AdContext();
  String userID=null;
  Cookie cookie=CookieUtils.getCookie(request.getCookies(),AdServerConstants.Cookie.USERID);
  if (cookie != null) {
    userID=cookie.getValue();
  }
  if (Strings.isEmpty(userID)) {
    userID=UUID.randomUUID().toString();
    CookieUtils.addCookie(response,AdServerConstants.Cookie.USERID,userID,CookieUtils.ONE_YEAR,RuntimeContext.getProperties().getProperty(AdServerConstants.CONFIG.PROPERTIES.COOKIE_DOMAIN));
  }
  context.setUserid(userID);
  String requestID=(String)request.getParameter(RequestHelper.requestId);
  if (Strings.isEmpty(requestID)) {
    requestID=UUID.randomUUID().toString();
  }
  context.setRequestid(requestID);
  String slot=(String)request.getParameter(RequestHelper.slot);
  if (!Strings.isEmpty(slot)) {
    try {
      AdSlot aduuid=AdSlot.fromString(slot);
      context.setSlot(aduuid);
    }
 catch (    Exception e) {
      logger.error("",e);
    }
  }
  String clientIP=request.getRemoteAddr();
  if (request.getHeader("X-Real-IP") != null) {
    clientIP=request.getHeader("X-Real-IP");
  }
  context.setIp(clientIP);
  return context;
}
 

Example 14

From project aerogear-controller, under directory /src/main/java/org/jboss/aerogear/controller/router/.

Source file: DefaultRouter.java

  15 
vote

@Override public void dispatch(HttpServletRequest request,HttpServletResponse response,FilterChain chain) throws ServletException {
  try {
    final String requestPath=extractPath(request);
    Route route=routes.routeFor(extractMethod(request),requestPath);
    Object[] params;
    if (route.isSecured()) {
      securityProvider.isRouteAllowed(route);
    }
    if (route.isParameterized()) {
      params=extractPathParameters(requestPath,route);
    }
 else {
      params=extractParameters(request,route);
    }
    Object result=route.getTargetMethod().invoke(getController(route),params);
    String viewPath=viewResolver.resolveViewPathFor(route);
    View view=new View(viewPath,result);
    if (view.hasModelData()) {
      request.setAttribute(view.getModelName(),view.getModel());
    }
    request.getRequestDispatcher(view.getViewPath()).forward(request,response);
  }
 catch (  Exception e) {
    if (e instanceof HttpStatusAwareException) {
      response.setStatus(((HttpStatusAwareException)e).getStatus());
    }
    final Throwable rootCause=Throwables.getRootCause(e);
    final Route errorRoute=routes.routeFor(rootCause);
    invokeErrorRoute(errorRoute,rootCause);
    forwardErrorToView(errorRoute,rootCause,request,response);
  }
}
 

Example 15

From project aerogear-controller, under directory /src/main/java/org/jboss/aerogear/controller/router/.

Source file: DefaultRouter.java

  15 
vote

private void forwardErrorToView(final Route errorRoute,final Throwable rootCause,final HttpServletRequest request,final HttpServletResponse response) throws ServletException {
  try {
    final View view=new View(errorViewResolver.resolveViewPathFor(errorRoute),rootCause);
    request.setAttribute(EXCEPTION_ATTRIBUTE_NAME,view.getModel());
    request.getRequestDispatcher(view.getViewPath()).forward(request,response);
  }
 catch (  IOException e) {
    throw new ServletException(e.getMessage(),e);
  }
}
 

Example 16

From project aether-core, under directory /aether-connector-asynchttpclient/src/test/java/org/eclipse/aether/connector/async/.

Source file: Generate.java

  15 
vote

public boolean execute(HttpServletRequest request,HttpServletResponse response,Map<Object,Object> ctx) throws Exception {
  if ("GET".equals(request.getMethod())) {
    String path=request.getPathInfo();
    Long length=lengths.get(path);
    if (length != null) {
      response.setContentType("application/octet-stream");
      response.setContentLength(length.intValue());
      ServletOutputStream out=response.getOutputStream();
      for (int i=length.intValue(); i > 0; ) {
        int n=Math.min(i,bytes.length);
        i-=n;
        out.write(bytes,0,n);
      }
      out.close();
      return false;
    }
  }
  return true;
}
 

Example 17

From project aether-core, under directory /aether-connector-asynchttpclient/src/test/java/org/eclipse/aether/connector/async/.

Source file: HttpServer.java

  15 
vote

protected Handler newProxyHandler(){
  return new AbstractHandler(){
    public void handle(    String target,    HttpServletRequest request,    HttpServletResponse response,    int dispatch) throws IOException {
      String auth=request.getHeader("Proxy-Authorization");
      if (auth != null) {
        auth=auth.substring(auth.indexOf(' ') + 1).trim();
        auth=B64Code.decode(auth);
      }
      if (!(proxyUsername + ':' + proxyPassword).equals(auth)) {
        response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
        response.addHeader("Proxy-Authenticate","Basic realm=\"Squid proxy-caching web server\"");
        response.getWriter().println("Proxy authentication required");
        ((Request)request).setHandled(true);
      }
    }
  }
;
}
 

Example 18

From project aether-core, under directory /aether-connector-asynchttpclient/src/test/java/org/eclipse/aether/connector/async/.

Source file: HttpServer.java

  15 
vote

protected Handler newSslRedirectHandler(){
  return new AbstractHandler(){
    public void handle(    String target,    HttpServletRequest request,    HttpServletResponse response,    int dispatch){
      int httpsPort=getHttpsPort();
      if (!((Request)request).isHandled() && request.getServerPort() != httpsPort) {
        String url="https://" + request.getServerName() + ":"+ httpsPort+ request.getRequestURI();
        response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        response.setHeader("Location",url);
        ((Request)request).setHandled(true);
      }
    }
  }
;
}
 

Example 19

From project agile, under directory /agile-framework/src/main/java/org/apache/catalina/servlets/.

Source file: DefaultServlet.java

  15 
vote

/** 
 * Return the relative path associated with this servlet.
 * @param request The servlet request we are processing
 */
protected String getRelativePath(HttpServletRequest request){
  if (request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) != null) {
    String result=(String)request.getAttribute(Globals.INCLUDE_PATH_INFO_ATTR);
    if (result == null)     result=(String)request.getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
    if ((result == null) || (result.equals("")))     result="/";
    return (result);
  }
  String result=request.getPathInfo();
  if (result == null) {
    result=request.getServletPath();
  }
  if ((result == null) || (result.equals(""))) {
    result="/";
  }
  return (result);
}
 

Example 20

From project agile, under directory /agile-framework/src/main/java/org/apache/catalina/servlets/.

Source file: DefaultServlet.java

  15 
vote

/** 
 * Process a GET request for the specified resource.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
  if (!isAuthenticated(request,response) || !isAuthorized(request,response)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN);
    return;
  }
  serveResource(request,response,true);
}
 

Example 21

From project agile, under directory /agile-framework/src/main/java/org/apache/catalina/servlets/.

Source file: DefaultServlet.java

  15 
vote

/** 
 * Process a HEAD request for the specified resource.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
protected void doHead(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
  if (!isAuthenticated(request,response) || !isAuthorized(request,response)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN);
    return;
  }
  serveResource(request,response,false);
}
 

Example 22

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/auth/.

Source file: AuthManager.java

  15 
vote

public SortedSet<CompanyInfo> getCompanies(HttpServletRequest request) throws DisallowedException, ObjectNotFoundException {
  if (!(this.authenticator.loggedInUserAllowedTo(request,PrivilegeType.MASTER))) {
    throw new DisallowedException(this.getLoggedInUser(request),PrivilegeType.MASTER);
  }
  return ((Authenticator)this.authenticator).getCompanies();
}
 

Example 23

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/auth/.

Source file: AuthManager.java

  15 
vote

public synchronized void addCompany(HttpServletRequest request,CompanyInfo company) throws DisallowedException, CantDoThatException, CodingErrorException, MissingParametersException, ObjectNotFoundException {
  if (!(this.authenticator.loggedInUserAllowedTo(request,PrivilegeType.MASTER))) {
    throw new DisallowedException(this.getLoggedInUser(request),PrivilegeType.MASTER);
  }
  HibernateUtil.activateObject(this.authenticator);
  ((Authenticator)this.authenticator).addCompany(company);
  String adminUsername="admin" + company.getCompanyName().toLowerCase();
  adminUsername=adminUsername.replaceAll("\\W","");
  String adminPassword=RandomString.generate();
  AppUserInfo adminUser=new AppUser(company,null,adminUsername,"User","Admin",adminPassword);
  String adminRolename=adminUsername;
  AppRoleInfo adminRole=new AppRole(company,null,adminRolename);
  HibernateUtil.currentSession().save(adminRole);
  try {
    this.addUser(request,adminUser);
    this.addRole(request,adminRole);
    this.assignUserToRole(request,adminUser,adminRole);
    ((Authenticator)this.authenticator).addRolePrivilege(adminRole,PrivilegeType.ADMINISTRATE);
  }
 catch (  MissingParametersException mpex) {
    throw new CodingErrorException("Error constructing/accessing user object",mpex);
  }
catch (  ObjectNotFoundException onfex) {
    throw new CodingErrorException("Error assigning user to role: user or role not found",onfex);
  }
}
 

Example 24

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/auth/.

Source file: AuthManager.java

  15 
vote

public synchronized void removeCompany(HttpServletRequest request,CompanyInfo company) throws DisallowedException, CodingErrorException, CantDoThatException, ObjectNotFoundException {
  if (!(this.authenticator.loggedInUserAllowedTo(request,PrivilegeType.MASTER))) {
    throw new DisallowedException(this.getLoggedInUser(request),PrivilegeType.MASTER);
  }
  Set<TableInfo> companyTables=company.getTables();
  if (companyTables.size() > 0) {
    throw new CantDoThatException("All tables must be removed before removing the company. Remaining tables are " + companyTables);
  }
  logger.info("removing users & roles");
  try {
    for (    AppUserInfo user : company.getUsers()) {
      logger.info("removing " + user);
      this.removeUser(request,user);
    }
    for (    AppRoleInfo role : company.getRoles()) {
      logger.info("removing " + role);
      this.removeRoleWithoutChecks(request,role);
    }
  }
 catch (  ObjectNotFoundException onfex) {
    throw new CodingErrorException("User or role in company " + company + " not found in authenticator");
  }
  logger.info("removing company " + company);
  HibernateUtil.activateObject(this.authenticator);
  ((Authenticator)this.authenticator).removeCompany(company);
  HibernateUtil.currentSession().delete(company);
}