Examples of ISVNAuthenticationManager


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) {
                authAttempts++;//how many times did we try?
               
                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", HTTPParser.getCanonicalPath(path, null).toString());
               
                if (skip) {
                    close();
                    continue;
                }
               
                HTTPNTLMAuthentication ntlmAuth = null;
                HTTPNegotiateAuthentication negoAuth = null;
                if (myChallengeCredentials instanceof HTTPNTLMAuthentication) {
                    ntlmAuthIsRequired = true;
                    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;
                    }
                } else if (myChallengeCredentials instanceof HTTPNegotiateAuthentication) {
                    negoAuthIsRequired = true;
                    negoAuth = (HTTPNegotiateAuthentication)myChallengeCredentials;
                    if (negoAuth.isStarted()) {
                        continue;
                    }
                }

                myLastValidAuth = null;

                if (ntlmAuth != null && ntlmAuth.isNative() && authAttempts == 1) {
                    /*
                     * if this is the first time we get HTTP_UNAUTHORIZED, NTLM is the target auth scheme
                     * and JNA is available, we should try a native auth mechanism first without calling
                     * auth providers.
                     */
                    continue;
                }

                if (negoAuth != null && !negoAuth.needsLogin()) {
                    continue;
                }

                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 if (authAttempts >= requestAttempts) {
                    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;
                }
                if (httpAuth != null) {
                    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();
            } else {
                ntlmProxyAuthIsRequired = false;
                ntlmAuthIsRequired = false;
                negoAuthIsRequired = false;
            }
           
            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

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

    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

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

        if (mechs == null || mechs.size() == 0) {
            return;
        }
        myRealm = SVNReader.getString(items, 1);
       
        ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();
        if (authManager != null && authManager.isAuthenticationForced() && mechs.contains("ANONYMOUS") &&
                (mechs.contains("CRAM-MD5") || mechs.contains("DIGEST-MD5"))) {
            mechs.remove("ANONYMOUS");
        }
        SVNAuthenticator authenticator = createSASLAuthenticator();
        authenticator.authenticate(mechs, myRealm, repository);
View Full Code Here

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

        myIsUseConnectionPing = useConnectionPing;
        myIsUseSessionPing = useSessionPing;
    }

    public void open(SVNRepositoryImpl repository) throws SVNException {
        ISVNAuthenticationManager authManager = repository.getAuthenticationManager();
        if (authManager == null) {
            SVNErrorManager.authenticationFailed("Authentication required for ''{0}''", repository.getLocation());
            return;
        }

        String realm = repository.getLocation().getProtocol() + "://" + repository.getLocation().getHost();
        if (repository.getLocation().hasPort()) {
            realm += ":" + repository.getLocation().getPort();
        }
        if (repository.getLocation().getUserInfo() != null && !"".equals(repository.getLocation().getUserInfo())) {
            realm = repository.getLocation().getUserInfo() + "@" + realm;
        }

        int reconnect = 1;
        while(true) {
            SVNSSHAuthentication authentication = (SVNSSHAuthentication) authManager.getFirstAuthentication(ISVNAuthenticationManager.SSH, realm, repository.getLocation());
            SSHConnectionInfo connection = null;
           
            // lock SVNSSHSession to make sure connection opening and session creation is atomic.
            SVNSSHSession.lock(Thread.currentThread());
            try {
                while (authentication != null) {
                    try {
                        connection = SVNSSHSession.getConnection(repository.getLocation(), authentication, authManager.getConnectTimeout(repository), myIsUseConnectionPing);
                        if (connection == null) {
                            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_CONNECTION_CLOSED, "Cannot connect to ''{0}''", repository.getLocation().setPath("", false));
                            SVNErrorManager.error(err, SVNLogType.NETWORK);
                        }
                        authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.SSH, realm, null, authentication);
                        break;
                    } catch (SVNAuthenticationException e) {
                        SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, e);
                        authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.SSH, realm, e.getErrorMessage(), authentication);
                        authentication = (SVNSSHAuthentication) authManager.getNextAuthentication(ISVNAuthenticationManager.SSH, realm, repository.getLocation());
                        connection = null;
                    }
                }
                if (authentication == null) {
                    SVNErrorManager.cancel("authentication cancelled", SVNLogType.NETWORK);
                } else if (connection == null) {
                    SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_SVN_CONNECTION_CLOSED, "Can not establish connection to ''{0}''", realm), SVNLogType.NETWORK);
                }
                try {
                    mySession = connection.openSession();
                    SVNAuthentication author = authManager.getFirstAuthentication(ISVNAuthenticationManager.USERNAME, realm, repository.getLocation());
                    if (author == null) {
                        SVNErrorManager.cancel("authentication cancelled", SVNLogType.NETWORK);
                    }
                    String userName = author.getUserName();
                    if (userName == null || "".equals(userName.trim())) {
                        userName = authentication.getUserName();
                    }
                    if (author.getUserName() == null || author.getUserName().equals(authentication.getUserName()) ||
                            "".equals(author.getUserName())) {
                        repository.setExternalUserName("");
                    } else {
                        repository.setExternalUserName(author.getUserName());
                    }
                    author = new SVNUserNameAuthentication(userName, author.isStorageAllowed());
                    authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.USERNAME, realm, null, author);
   
                    if ("".equals(repository.getExternalUserName())) {
                        mySession.execCommand(SVNSERVE_COMMAND);
                    } else {
                        mySession.execCommand(SVNSERVE_COMMAND_WITH_USER_NAME + "\"" + repository.getExternalUserName() + "\"");
View Full Code Here

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

    public void authenticate(List mechs, String realm, SVNRepositoryImpl repos) throws SVNException {
        SVNErrorMessage failureReason = null;
        if (mechs == null || mechs.size() == 0) {
            return;
        }
        ISVNAuthenticationManager authManager = repos.getAuthenticationManager();
        if (authManager != null && authManager.isAuthenticationForced() && mechs.contains("ANONYMOUS") && mechs.contains("CRAM-MD5")) {
            mechs.remove("ANONYMOUS");
        }
        SVNURL location = repos.getLocation();
        SVNPasswordAuthentication auth = null;
        if (repos.getExternalUserName() != null && mechs.contains("EXTERNAL")) {
            getConnection().write("(w(s))", new Object[]{"EXTERNAL", ""});
            failureReason = readAuthResponse();
        } else if (mechs.contains("ANONYMOUS")) {
            getConnection().write("(w(s))", new Object[]{"ANONYMOUS", ""});
            failureReason = readAuthResponse();
        } else if (mechs.contains("CRAM-MD5")) {
            while (true) {
                CramMD5 authenticator = new CramMD5();
                if (location != null) {
                    realm = "<" + location.getProtocol() + "://"
                            + location.getHost() + ":"
                            + location.getPort() + "> " + realm;
                }
                try {
                    if (auth == null && authManager != null) {
                        auth = (SVNPasswordAuthentication) authManager.getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);
                    } else if (authManager != null) {
                        authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.PASSWORD, realm, failureReason, auth);
                        auth = (SVNPasswordAuthentication) authManager.getNextAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);
                    }
                } catch (SVNException e) {
                    if (e.getErrorMessage().getErrorCode() == SVNErrorCode.CANCELLED) {
                        throw e;
                    } else if (getLastError() != null) {
                        SVNErrorManager.error(getLastError(), SVNLogType.NETWORK);
                    }
                    throw e;
                }
                if (auth == null) {
                    failureReason = SVNErrorMessage.create(SVNErrorCode.CANCELLED, "Authentication cancelled");
                    setLastError(failureReason);
                    break;
                   
                }
                if (auth.getUserName() == null || auth.getPassword() == null) {
                    failureReason = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "Can''t get password. Authentication is required for ''{0}''", realm);
                    break;
                }
                getConnection().write("(w())", new Object[]{"CRAM-MD5"});
                while (true) {
                    authenticator.setUserCredentials(auth);
                    List items = getConnection().readTuple("w(?s)", true);
                    String status = SVNReader.getString(items, 0);
                    if (SVNAuthenticator.SUCCESS.equals(status)) {
                        authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.PASSWORD, realm, null, auth);
                        return;
                    } else if (SVNAuthenticator.FAILURE.equals(status)) {                       
                        failureReason = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "Authentication error from server: {0}", SVNReader.getString(items, 1));
                        String message = SVNReader.getString(items, 1);
                        if (message != null) {
View Full Code Here

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

     * @param  password    a user password
     * @return             a new <b>SVNClientManager</b> instance
     */
    public static SVNClientManager newInstance(DefaultSVNOptions options, String userName, String password) {
        boolean storeAuth = options == null ? true : options.isAuthStorageEnabled();
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(null, userName, password, storeAuth);
        return new SVNClientManager(options, authManager);
    }
View Full Code Here

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

            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

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

  }

  private void initClientManager(String url, String username, String password) {
    // 1# instantiate a new object of type SVNClientManager and
    SVNClientManager manager = SVNClientManager.newInstance(defaultOpts, username, password);
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
        username, password);
    manager.setAuthenticationManager(authManager);

    // 2# add the client manager to the pool, for later use
    clientManagers.put(url, manager);
View Full Code Here

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

  private void initRepository(String url, String username, String password) throws SvnException {
    try {
      // 1# instantiate a new object of type SVNRepository
      SVNRepository repo = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
      ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
          username, password);
      repo.setAuthenticationManager(authManager);

      // 2# add the repository to the pool, for later use
      repositories.put(url, repo);
View Full Code Here

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

    }

    private void init() throws SVNException {
        DAVRepositoryFactory.setup();
        ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
                SVNWCUtil.getDefaultConfigurationDirectory(), null, null, false);
        manager = SVNClientManager.newInstance(options, authManager);

        tryAuth();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.