Package org.tmatesoft.svn.core.auth

Examples of org.tmatesoft.svn.core.auth.ISVNAuthenticationManager


                    }
                }

                err = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "HTTP proxy authorization failed");
                SVNURL location = myRepository.getLocation();
                ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
                ISVNProxyManager proxyManager = authManager != null ? authManager.getProxyManager(location) : null;
                if (proxyManager != null) {
                    proxyManager.acknowledgeProxyContext(false, err);
                }
                close();

                break;
            } else if (status.getCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                Collection authHeaderValues = request.getResponseHeader().getHeaderValues(HTTPHeader.AUTHENTICATE_HEADER);
                if (authHeaderValues == null || authHeaderValues.size() == 0) {
                    err = request.getErrorMessage();
                    status.setError(SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, err.getMessageTemplate(), err.getRelatedObjects()));
                    if ("LOCK".equalsIgnoreCase(method)) {
                        status.getError().setChildErrorMessage(SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE,
                                "Probably you are trying to lock file in repository that only allows anonymous access"));
                    }
                    SVNErrorManager.error(status.getError(), SVNLogType.NETWORK);
                    return status; 
                }

                //we should work around a situation when a server
                //does not support Basic authentication while we're
                //forcing it, credentials should not be immediately
                //thrown away
                boolean skip = false;
                isAuthForced = myRepository.getAuthenticationManager() != null ? myRepository.getAuthenticationManager().isAuthenticationForced() : false;
                if (isAuthForced) {
                    if (httpAuth != null && myChallengeCredentials != null && !HTTPAuthentication.isSchemeSupportedByServer(myChallengeCredentials.getAuthenticationScheme(), authHeaderValues)) {
                        skip = true;
                    }
                }
               
                try {
                    myChallengeCredentials = HTTPAuthentication.parseAuthParameters(authHeaderValues, myChallengeCredentials, myCharset);
                } catch (SVNException svne) {
                    err = svne.getErrorMessage();
                    break;
                }

                myChallengeCredentials.setChallengeParameter("methodname", method);
                myChallengeCredentials.setChallengeParameter("uri", path);
               
                if (skip) {
                    close();
                    continue;
                }
               
                if (myChallengeCredentials instanceof HTTPNTLMAuthentication) {
                    HTTPNTLMAuthentication ntlmAuth = (HTTPNTLMAuthentication)myChallengeCredentials;
                    if (ntlmAuth.isInType3State()) {
                        continue;
                    }
                } else if (myChallengeCredentials instanceof HTTPDigestAuthentication) {
                    // continue (retry once) if previous request was acceppted?
                    if (myLastValidAuth != null) {
                        myLastValidAuth = null;
                        continue;
                    }
                }

                myLastValidAuth = null;
               
                ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
                if (authManager == null) {
                    err = request.getErrorMessage();
                    break;
                }

                realm = myChallengeCredentials.getChallengeParameter("realm");
                realm = realm == null ? "" : " " + realm;
                realm = "<" + myHost.getProtocol() + "://" + myHost.getHost() + ":" + myHost.getPort() + ">" + realm;
                if (httpAuth == null) {
                    httpAuth = authManager.getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, realm, myRepository.getLocation());
                } else {
                    authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.PASSWORD, realm, request.getErrorMessage(), httpAuth);
                    httpAuth = authManager.getNextAuthentication(ISVNAuthenticationManager.PASSWORD, realm, myRepository.getLocation());
                }
                if (httpAuth == null) {
                    err = SVNErrorMessage.create(SVNErrorCode.CANCELLED, "HTTP authorization cancelled");
                    break;
                }
                myChallengeCredentials.setCredentials((SVNPasswordAuthentication)httpAuth);
                continue;
            } else if (status.getCode() == HttpURLConnection.HTTP_MOVED_PERM || status.getCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
                close();
                String newLocation = request.getResponseHeader().getFirstHeaderValue(HTTPHeader.LOCATION_HEADER);
                if (newLocation == null) {
                    err = request.getErrorMessage();
                    break;
                }
                int hostIndex = newLocation.indexOf("://");
                if (hostIndex > 0) {
                    hostIndex += 3;
                    hostIndex = newLocation.indexOf("/", hostIndex);
                }
                if (hostIndex > 0 && hostIndex < newLocation.length()) {
                    String newPath = newLocation.substring(hostIndex);
                    if (newPath.endsWith("/") &&
                            !newPath.endsWith("//") && !path.endsWith("/") &&
                            newPath.substring(0, newPath.length() - 1).equals(path)) {
                        path += "//";
                        continue;
                    }
                }
                err = request.getErrorMessage();
            } else if (request.getErrorMessage() != null) {
                err = request.getErrorMessage();
            }
            if (err != null) {
                break;
            }
           
            if (myIsProxied) {
                SVNURL location = myRepository.getLocation();
                ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
                ISVNProxyManager proxyManager = authManager != null ? authManager.getProxyManager(location) : null;
                if (proxyManager != null) {
                    proxyManager.acknowledgeProxyContext(true, null);
                }
            }
           
View Full Code Here


    if (!myIsSecured) {
      return null;
    }

    SVNURL location = myRepository.getLocation();
    ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
    String sslRealm = "<" + location.getProtocol() + "://" + location.getHost() + ":" + location.getPort() + ">";
    return new HTTPSSLKeyManager(authManager, sslRealm, location);
  }
View Full Code Here

            return getLocation().getUserInfo();
        }
        if (getAuthenticationManager() != null) {
            try {
                String realm = getRepositoryUUID(true);
                ISVNAuthenticationManager authManager = getAuthenticationManager();
                SVNAuthentication auth = authManager.getFirstAuthentication(ISVNAuthenticationManager.USERNAME, realm, getLocation());

                while (auth != null) {
                    String userName = auth.getUserName();
                    if (userName == null || "".equals(userName.trim())) {
                        userName = System.getProperty("user.name");
                    }
                    auth = new SVNUserNameAuthentication(userName, auth.isStorageAllowed());
                    if (userName != null && !"".equals(userName.trim())) {
                        authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.USERNAME, realm, null, auth);
                        return auth.getUserName();
                    }
                    SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.AUTHN_CREDS_UNAVAILABLE, "Empty user name is not allowed");
                    authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.USERNAME, realm, err, auth);
                    auth = authManager.getNextAuthentication(ISVNAuthenticationManager.USERNAME, realm, getLocation());
                }
                // auth manager returned null - that is cancellation.
                SVNErrorManager.cancel("Authentication cancelled", SVNLogType.FSFS);
            } catch (SVNCancelException e) {
                throw e;
View Full Code Here

          adminClient.doCreateRepository(reposRoot, null, true, true, false, false);
        else
        {
          SubversionSubmitter.setUpSVNKit();
          //SVNRepository repository = SVNRepositoryFactory.create(reposURL);
          ISVNAuthenticationManager m = SVNWCUtil.createDefaultAuthenticationManager("harry", "secret");
         //repository.setAuthenticationManager(m);
         clientManager.setAuthenticationManager(m);
        }
        logger.info("Repo URL = "+ reposURL);
        repos =  SVNRepositoryFactory.create(reposURL);
View Full Code Here

   * @param args
   */
  public static void main(String[] args)
  {
    try {
      ISVNAuthenticationManager m = SVNWCUtil.createDefaultAuthenticationManager("harry", "secret");
      SVNURL url = SVNURL.parseURIEncoded("svn://192.168.1.5/project1");
      SVNRepository repository = SVNRepositoryFactory.create(url);
      repository.setAuthenticationManager(m);
      addDirPath(repository, "/trunk/x/y/z");
      /*
 
View Full Code Here

     
      public ISVNAuthenticationManager getAuthManager( String userName)
      {
        if (userName == null)
          return defaultCredentials ;
        ISVNAuthenticationManager m = map.get(userName.trim());
        return  m == null? defaultCredentials : m;
      }
View Full Code Here

        ISVNAuthenticationManager m = map.get(userName.trim());
        return  m == null? defaultCredentials : m;
      }
      void addCredentials( String pToolUserName, String svnUserName, String svnPassword)
      {
        ISVNAuthenticationManager m = SVNWCUtil.createDefaultAuthenticationManager(svnUserName.trim(), svnPassword);
        if (map.size() == 0)
          defaultCredentials = m;
        if (pToolUserName != null)
          map.put(pToolUserName.trim(), m);
      }
View Full Code Here

      {
        parser.parse(((decodepcode.PeopleCodeContainer) c), w);
      }
      String path = basePath + mapper.getPath(c, "pcode");
      try {
        ISVNAuthenticationManager user = authMapper.getAuthManager(c.getLastChangedBy());
        if (user != null)
        {
          logger.info("setting mapped AuthManager for user " + c.getLastChangedBy());
          repository.setAuthenticationManager(user);
        }
View Full Code Here

    public void processSQL(SQLobject sql) throws IOException
    {
      String path = basePath + mapper.getPathForSQL(sql, "sql");
      try {
        ISVNAuthenticationManager user = authMapper.getAuthManager(sql.getLastChangedBy());
        if (user != null)
        {
          logger.info("Setting mapped AuthManager for user " + sql.getLastChangedBy());
          repository.setAuthenticationManager(user);
        }
View Full Code Here

      }
    }
    svnPassword = EncryptUtil.decrypt(svnPassword);//解密
   
       SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(svnUrl));
       ISVNAuthenticationManager authManager =
                    SVNWCUtil.createDefaultAuthenticationManager(svnUserName, svnPassword);
       repository.setAuthenticationManager(authManager);
      
       return repository;
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.svn.core.auth.ISVNAuthenticationManager

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.