Package com.knowgate.jcifs.smb

Examples of com.knowgate.jcifs.smb.NtlmPasswordAuthentication


            if( loadBalance ) {
                dc = new UniAddress( NbtAddress.getByName( domainController, 0x1C, null ));
            } else {
                dc = UniAddress.getByName( domainController, true );
            }
            NtlmPasswordAuthentication ntlm;
            if (msg.startsWith("NTLM ")) {
                byte[] challenge = SmbSession.getChallenge(dc);
                ntlm = NtlmSsp.authenticate(request, response, challenge);
                if (ntlm == null) return;
            } else {
                String auth = new String(Base64Decoder.decodeToBytes(msg.substring(6)), "US-ASCII");
                int index = auth.indexOf(':');
                String user = (index != -1) ? auth.substring(0, index) : auth;
                String password = (index != -1) ? auth.substring(index + 1) :
                        "";
                index = user.indexOf('\\');
                if (index == -1) index = user.indexOf('/');
                String domain = (index != -1) ? user.substring(0, index) :
                        defaultDomain;
                user = (index != -1) ? user.substring(index + 1) : user;
                ntlm = new NtlmPasswordAuthentication(domain, user, password);
            }
            try {
                SmbSession.logon(dc, ntlm);
            } catch (SmbAuthException sae) {
                response.setHeader("WWW-Authenticate", "NTLM");
                if (offerBasic) {
                    response.addHeader("WWW-Authenticate", "Basic realm=\"" +
                            realm + "\"");
                }
                response.setHeader("Connection", "close");
                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                response.flushBuffer();
                return;
            }
            HttpSession ssn = request.getSession();
            ssn.setAttribute("NtlmHttpAuth", ntlm);
            ssn.setAttribute( "ntlmdomain", ntlm.getDomain() );
            ssn.setAttribute( "ntlmuser", ntlm.getUsername() );
        } else {
            HttpSession ssn = request.getSession(false);
            if (ssn == null || ssn.getAttribute("NtlmHttpAuth") == null) {
                response.setHeader("WWW-Authenticate", "NTLM");
                if (offerBasic) {
View Full Code Here


        HttpServletRequest req;
        HttpServletResponse resp;
        UniAddress dc;
        String msg;

        NtlmPasswordAuthentication ntlm = null;
        req = (HttpServletRequest)request;
        resp = (HttpServletResponse)response;
        msg = req.getHeader( "Authorization" );
        boolean offerBasic = enableBasic && (insecureBasic || req.isSecure());

        if( msg != null && (msg.startsWith( "NTLM " ) ||
                    (offerBasic && msg.startsWith("Basic ")))) {
            if( loadBalance ) {
                dc = new UniAddress( NbtAddress.getByName( domainController, 0x1C, null ));
            } else {
                dc = UniAddress.getByName( domainController, true );
            }
            if (msg.startsWith("NTLM ")) {
                req.getSession();
                byte[] challenge = SmbSession.getChallenge( dc );
                if(( ntlm = NtlmSsp.authenticate( req, resp, challenge )) == null ) {
                    return;
                }
            } else {
                String auth = new String(Base64Decoder.decodeToBytes(msg.substring(6)), "US-ASCII");
                int index = auth.indexOf(':');
                String user = (index != -1) ? auth.substring(0, index) : auth;
                String password = (index != -1) ? auth.substring(index + 1) :
                        "";
                index = user.indexOf('\\');
                if (index == -1) index = user.indexOf('/');
                String domain = (index != -1) ? user.substring(0, index) :
                        defaultDomain;
                user = (index != -1) ? user.substring(index + 1) : user;
                ntlm = new NtlmPasswordAuthentication(domain, user, password);
            }
            try {

                SmbSession.logon( dc, ntlm );
View Full Code Here

    public void doGet( HttpServletRequest req,
                HttpServletResponse resp ) throws IOException, ServletException {
        UniAddress dc;
        String msg, pathInfo, server = null;
        boolean offerBasic, possibleWorkgroup = true;
        NtlmPasswordAuthentication ntlm = null;
        HttpSession ssn = req.getSession( false );

        if(( pathInfo = req.getPathInfo() ) != null ) {
            int i;
            server = parseServerAndShare( pathInfo );
            if( server != null && ( i = server.indexOf( '/' )) > 0 ) {
                server = server.substring( 0, i ).toLowerCase();
                possibleWorkgroup = false;
            }
        }

        msg = req.getHeader( "Authorization" );
        offerBasic = enableBasic && (insecureBasic || req.isSecure());

        if( msg != null && (msg.startsWith( "NTLM " ) ||
                    (offerBasic && msg.startsWith("Basic ")))) {

            if( msg.startsWith("NTLM ")) {
                byte[] challenge;

                if( pathInfo == null || server == null ) {
                    String mb = NbtAddress.getByName( NbtAddress.MASTER_BROWSER_NAME, 0x01, null ).getHostAddress();
                    dc = UniAddress.getByName( mb );
                } else {
                    dc = UniAddress.getByName( server, possibleWorkgroup );
                }

                req.getSession(); /* ensure session id is set for cluster env. */
                challenge = SmbSession.getChallenge( dc );
                if(( ntlm = NtlmSsp.authenticate( req, resp, challenge )) == null ) {
                    return;
                }
            } else { /* Basic */
                String auth = new String( Base64Decoder.decodeToBytes(msg.substring(6)), "US-ASCII" );
                int index = auth.indexOf( ':' );
                String user = (index != -1) ? auth.substring(0, index) : auth;
                String password = (index != -1) ? auth.substring(index + 1) : "";
                index = user.indexOf('\\');
                if (index == -1) index = user.indexOf('/');
                String domain = (index != -1) ? user.substring(0, index) : defaultDomain;
                user = (index != -1) ? user.substring(index + 1) : user;
                ntlm = new NtlmPasswordAuthentication(domain, user, password);
            }

            req.getSession().setAttribute( "npa-" + server, ntlm );

        } else if( !credentialsSupplied ) {
View Full Code Here

  public NtlmHipergateFilter() { }

  public void doFilter( ServletRequest request,ServletResponse response, FilterChain chain )
      throws IOException, ServletException {

      NtlmPasswordAuthentication ntlm = null;
      HttpServletRequest req = (HttpServletRequest)request;
      HttpServletResponse resp = (HttpServletResponse)response;

      String msg = req.getHeader( "Authorization" );

      if (DebugFile.trace) DebugFile.writeln("NtlmHipergateFilter Authorization=" + msg);

      UniAddress dc;
      String user = "", password = "", domain = "";

      boolean offerBasic = enableBasic && (insecureBasic || req.isSecure());

      if (DebugFile.trace) DebugFile.writeln("offerBasic=" + String.valueOf(offerBasic));

      if( msg != null && (msg.startsWith( "NTLM " ) || (offerBasic && msg.startsWith("Basic ")))) {
          if( loadBalance ) {
              if (DebugFile.trace) DebugFile.writeln("new UniAddress(" + NbtAddress.getByName( domainController, 0x1C, null ) + ")");
              dc = new UniAddress( NbtAddress.getByName( domainController, 0x1C, null ));
          } else {
              if (DebugFile.trace) DebugFile.writeln("UniAddress.getByName( " + domainController + ", true)");
              dc = UniAddress.getByName( domainController, true );
          }

          if (msg.startsWith("NTLM ")) {
              req.getSession();
              byte[] challenge = SmbSession.getChallenge( dc );


              if (( ntlm = NtlmSsp.authenticate( req, resp, challenge )) == null ) {
                  if (DebugFile.trace) DebugFile.writeln("NtlmPasswordAuthentication = null");
                  return;
              }
          } else {
              String auth = new String (Base64Decoder.decodeToBytes(msg.substring(6)), "US-ASCII");

              int index = auth.indexOf(':');

              user = (index != -1) ? auth.substring(0, index) : auth;

              if (DebugFile.trace) DebugFile.writeln("user=" + user);

              password = (index != -1) ? auth.substring(index + 1) : "";

              index = user.indexOf('\\');
              if (index == -1) index = user.indexOf('/');
              domain = (index != -1) ? user.substring(0, index) : defaultDomain;

              if (DebugFile.trace) DebugFile.writeln("domain=" + domain);

              user = (index != -1) ? user.substring(index + 1) : user;

              ntlm = new NtlmPasswordAuthentication(domain, user, password);

          } // fi (msg.startsWith("NTLM "))

          try {
              if (DebugFile.trace && (dc!=null) && (ntlm!=null))
                DebugFile.writeln("SmbSession.logon(" + dc.toString() + "," + ntlm.toString());

              SmbSession.logon( dc, ntlm );

          } catch( SmbAuthException sae ) {
              if (DebugFile.trace) DebugFile.writeln("SmbAuthException" + Gadgets.toHexString(sae.getNtStatus(), 8) + " " + sae.getMessage());

              if( sae.getNtStatus() == sae.NT_STATUS_ACCESS_VIOLATION ) {
                  /* Server challenge no longer valid for
                   * externally supplied password hashes.
                   */
                  HttpSession ssn = req.getSession(false);
                  if (ssn != null) {
                      ssn.removeAttribute( "NtlmHttpAuth" );
                  }

                  if (DebugFile.trace) DebugFile.writeln("HttpServletResponse.sendRedirect(" + req.getRequestURL().toString() + ")");

                  resp.sendRedirect( req.getRequestURL().toString() );
                  return;
              }
              if (DebugFile.trace) DebugFile.writeln("HttpServletResponse.setHeader(WWW-Authenticate, NTLM)");

              resp.setHeader( "WWW-Authenticate", "NTLM" );
              if (offerBasic) {
                  resp.addHeader( "WWW-Authenticate", "Basic realm=\"" + realm + "\"");
              }
              resp.setHeader( "Connection", "close" );
              resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
              resp.flushBuffer();
              return;
          }

          if (DebugFile.trace) DebugFile.writeln("HttpServletRequest.getSession().setAttribute(NtlmHttpAuth, " + ntlm.toString() + ")");

          req.getSession().setAttribute( "NtlmHttpAuth", ntlm );

          if (DebugFile.trace) DebugFile.writeln("HttpServletResponse.addCookie(domainnm, " + ntlm.getDomain().toUpperCase() + ")");
          if (DebugFile.trace) DebugFile.writeln("HttpServletResponse.addCookie(nickname, " + ntlm.getUsername() + ")");

          resp.addCookie(new Cookie("domainnm", ntlm.getDomain().toUpperCase()));
          resp.addCookie(new Cookie("NickCookie", ntlm.getUsername()));
          resp.addCookie(new Cookie("authstr", ntlm.getPassword()));

      } else {
          if (DebugFile.trace) DebugFile.writeln("HttpSession = HttpServletRequest.getSession(false)");

          HttpSession ssn = req.getSession(false);
View Full Code Here

                Type3Message type3 = new Type3Message(src);
                byte[] lmResponse = type3.getLMResponse();
                if (lmResponse == null) lmResponse = new byte[0];
                byte[] ntResponse = type3.getNTResponse();
                if (ntResponse == null) ntResponse = new byte[0];
                return new NtlmPasswordAuthentication(type3.getDomain(),
                        type3.getUser(), challenge, lmResponse, ntResponse);
            }
        } else {
            resp.setHeader("WWW-Authenticate", "NTLM");
            resp.setHeader("Connection", "close");
View Full Code Here

TOP

Related Classes of com.knowgate.jcifs.smb.NtlmPasswordAuthentication

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.