private ServerContext createServerContext( String gitRemoteUrl, AuthenticationInfo authenticationInfo) { ServerContext.Type type = UrlHelper.isVSO(UrlHelper.getBaseUri(gitRemoteUrl)) ? ServerContext.Type.VSO_DEPLOYMENT : ServerContext.Type.TFS; final Client client = ServerContext.getClient(type, authenticationInfo); final Validator validator = new Validator(client); final UrlHelper.ParseResult uriParseResult = UrlHelper.tryParse(gitRemoteUrl, validator); if (uriParseResult.isSuccess()) { final ServerContextBuilder builder = new ServerContextBuilder() .type(type) .uri(gitRemoteUrl) .authentication(authenticationInfo) .teamProject(validator.getRepository().getProjectReference()) .repository(validator.getRepository()) .collection(validator.getCollection()); // Set the uri of the context to the server uri (TODO change context so that it can be any URI // in the hierarchy) final URI serverUri = URI.create(uriParseResult.getServerUrl()); builder.uri(serverUri); return builder.buildWithClient(client); } return null; }
private void loadRepositoriesInternal() { if (!authenticationProvider.isAuthenticated()) { addError( ModelValidationInfo.createWithResource( PROP_SERVER_NAME, TfPluginBundle.KEY_LOGIN_PAGE_ERRORS_TFS_CONNECT_FAILED, getServerName())); signOut(); return; } setConnectionStatus(true); setLoading(true); setUserName(authenticationProvider.getAuthenticationInfo().getUserNameForDisplay()); clearContexts(); final URI serverUrl = UrlHelper.getBaseUri(getServerName()); final ServerContext context = new ServerContextBuilder() .type(ServerContext.Type.TFS) .uri(serverUrl) .authentication(authenticationProvider.getAuthenticationInfo()) .build(); // successfully logged in and loading repositories, save this context if there is no active // context if (ServerContextManager.getInstance().getActiveContext() == ServerContext.NO_CONTEXT) { ServerContextManager.getInstance().setActiveContext(context); } getRepositoryProvider() .loadContexts( Collections.singletonList(context), ServerContextLookupOperation.ContextScope.REPOSITORY); }
/** * Use this method to get the appropriate AuthenticationProvider based on an url. * * @param url * @return */ public AuthenticationProvider getAuthenticationProvider(final String url) { if (UrlHelper.isVSO(UrlHelper.getBaseUri(url))) { return VsoAuthenticationProvider.getInstance(); } return new TfsAuthenticationProvider(); }