Package org.apache.tomcat.util.buf

Examples of org.apache.tomcat.util.buf.CharChunk


            }
        }

        // acquire references to objects we will need to evaluate.
        MessageBytes uriMB = MessageBytes.newInstance();
        CharChunk uriCC = uriMB.getCharChunk();
        uriCC.setLimit(-1);
        String contextPath = request.getContextPath();
        String requestURI = request.getDecodedRequestURI();

        // is this the action request from the login page?
        boolean loginAction = requestURI.startsWith(contextPath) && requestURI.endsWith(Constants.FORM_ACTION);
View Full Code Here


          }
      }

      // Acquire references to objects we will need to evaluate
      MessageBytes uriMB = MessageBytes.newInstance();
      CharChunk uriCC = uriMB.getCharChunk();
      uriCC.setLimit(-1);
      String contextPath = request.getContextPath();
      String requestURI = request.getDecodedRequestURI();
      response.setContext(request.getContext());

      // Is this the action request from the login page?
View Full Code Here

          if (authorizationBC.startsWithIgnoreCase("basic ", 0)) {
              authorizationBC.setOffset(authorizationBC.getOffset() + 6);
              // FIXME: Add trimming
              // authorizationBC.trim();
             
              CharChunk authorizationCC = authorization.getCharChunk();
              Base64.decode(authorizationBC, authorizationCC);
             
              // Get username and password
              int colon = authorizationCC.indexOf(':');
              if (colon < 0) {
                  username = authorizationCC.toString();
              } else {
                  char[] buf = authorizationCC.getBuffer();
                  username = new String(buf, 0, colon);
                  password = new String(buf, colon + 1,
                          authorizationCC.getEnd() - colon - 1);
              }
             
              authorizationBC.setOffset(authorizationBC.getOffset() - 6);
          }

          principal = context.getRealm().authenticate(username, password);
          if (principal != null) {
             registerWithCallbackHandler(principal, username, password);
            
              /*register(request, response, principal, Constants.BASIC_METHOD,
                       username, password);*/
             return AuthStatus.SUCCESS;
          }
      }

      // Send an "unauthorized" response and an appropriate challenge
      MessageBytes authenticate =
          response.getCoyoteResponse().getMimeHeaders()
          .addValue(AUTHENTICATE_BYTES, 0, AUTHENTICATE_BYTES.length);
      CharChunk authenticateCC = authenticate.getCharChunk();
      try
      {
         authenticateCC.append("Basic realm=\"");
         if (config.getRealmName() == null) {
            authenticateCC.append(request.getServerName());
            authenticateCC.append(':');
            authenticateCC.append(Integer.toString(request.getServerPort()));
         } else {
            authenticateCC.append(config.getRealmName());
         }
         authenticateCC.append('\"');       
         authenticate.toChars();

         response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      }
      catch (IOException e)
View Full Code Here

   protected void convertURI(MessageBytes uri, RequestMap request)
         throws Exception
   {

      ByteChunk bc = uri.getByteChunk();
      CharChunk cc = uri.getCharChunk();
      cc.allocate(bc.getLength(), -1);

      String enc = URIEncoding;
      if(enc != null)
      {
         B2CConverter conv = request.getURIConverter();
         try
         {
            if(conv == null)
            {
               conv = new B2CConverter(enc);
               request.setURIConverter(conv);
            }
            else
            {
               conv.recycle();
            }
         }
         catch(IOException e)
         {
            // Ignore
            log.error("Invalid URI encoding; using HTTP default");
            URIEncoding = null;
         }
         if(conv != null)
         {
            try
            {
               conv.convert(bc, cc);
               uri.setChars(cc.getBuffer(), cc.getStart(),
                            cc.getLength());
               return;
            }
            catch(IOException e)
            {
               log.error("Invalid URI character encoding; trying ascii");
               cc.recycle();
            }
         }
      }

      // Default encoding: fast conversion
      byte[] bbuf = bc.getBuffer();
      char[] cbuf = cc.getBuffer();
      int start = bc.getStart();
      for(int i = 0; i < bc.getLength(); i++)
      {
         cbuf[i] = (char) (bbuf[i + start] & 0xff);
      }
View Full Code Here

      {
         return;
      }

      ByteChunk bc = mb.getByteChunk();
      CharChunk cc = mb.getCharChunk();
      cc.allocate(bc.getLength(), -1);

      // Default encoding: fast conversion
      byte[] bbuf = bc.getBuffer();
      char[] cbuf = cc.getBuffer();
      int start = bc.getStart();
      for(int i = 0; i < bc.getLength(); i++)
      {
         cbuf[i] = (char) (bbuf[i + start] & 0xff);
      }
View Full Code Here

            }
        }

        // Acquire references to objects we will need to evaluate
        MessageBytes uriMB = MessageBytes.newInstance();
        CharChunk uriCC = uriMB.getCharChunk();
        uriCC.setLimit(-1);
        String contextPath = request.getContextPath();
        String requestURI = request.getDecodedRequestURI();
        response.setContext(request.getContext());

        // Is this the action request from the login page?
View Full Code Here

          }
      }

      // Acquire references to objects we will need to evaluate
      MessageBytes uriMB = MessageBytes.newInstance();
      CharChunk uriCC = uriMB.getCharChunk();
      uriCC.setLimit(-1);
      String contextPath = request.getContextPath();
      String requestURI = request.getDecodedRequestURI();
      response.setContext(request.getContext());

      // Is this the action request from the login page?
View Full Code Here

        if (mb.getType() == MessageBytes.T_BYTES) {
            ByteChunk bc = mb.getByteChunk();
            write(bc);
        } else if (mb.getType() == MessageBytes.T_CHARS) {
            CharChunk cc = mb.getCharChunk();
            write(cc);
        } else {
            write(mb.toString());
        }
View Full Code Here

     */
    public void map(MessageBytes uri, MappingData mappingData)
        throws Exception {

        uri.toChars();
        CharChunk uricc = uri.getCharChunk();
        uricc.setLimit(-1);
        internalMapWrapper(context, uricc, mappingData);

    }
View Full Code Here

     * FIXME: Optimize this.
     */
    protected void parseSessionId(Request req, CoyoteRequest request) {

        req.decodedURI().toChars();
        CharChunk uriCC = req.decodedURI().getCharChunk();
        int semicolon = uriCC.indexOf(match, 0, match.length(), 0);

        if (semicolon > 0) {

            // Parse session ID, and extract it from the decoded request URI
            int start = uriCC.getStart();
            int end = uriCC.getEnd();

            int sessionIdStart = start + semicolon + match.length();
            int semicolon2 = uriCC.indexOf(';', sessionIdStart);
            if (semicolon2 >= 0) {
                request.setRequestedSessionId
                    (new String(uriCC.getBuffer(), sessionIdStart,
                                semicolon2 - semicolon - match.length()));
                req.decodedURI().setString
                    (new String(uriCC.getBuffer(), start, semicolon) +
                            new String(uriCC.getBuffer(),
                                        semicolon2,
                                        end-semicolon2));
            } else {
                request.setRequestedSessionId
                    (new String(uriCC.getBuffer(), sessionIdStart,
                                end - sessionIdStart));
                req.decodedURI().setString
                    (new String(uriCC.getBuffer(), start, semicolon));
            }
            request.setRequestedSessionURL(true);

            // Extract session ID from request URI
            String uri = req.requestURI().toString();
View Full Code Here

TOP

Related Classes of org.apache.tomcat.util.buf.CharChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.