protected boolean configureServerCredentials ( final GitHubClient client , final String serverId , final Settings settings , final MavenSession session ) throws MojoExecutionException { if ( StringUtils . isEmpty ( serverId ) ) return false ; String serverUsername = null ; String serverPassword = null ; // Maven 3.1.0 - It's now impossible to retrieve the username and password from the remote repository. // if (session != null) { // RepositorySystemSession systemSession = session // .getRepositorySession(); // if (systemSession != null) { // RemoteRepository.Builder builder = new RemoteRepository.Builder(serverId, "", ""); // Authentication authInfo = systemSession.getAuthenticationSelector().getAuthentication // (builder.build()); // if (authInfo != null) { // serverUsername = authInfo.getUsername(); // serverPassword = authInfo.getPassword(); // } // } // } // Always true. // if (StringUtils.isEmpty(serverPassword)) { Server server = getServer ( settings , serverId ) ; if ( server == null ) throw new MojoExecutionException ( MessageFormat . format ( "Server ''{0}'' not found in settings" , serverId ) ) ; if ( isDebug ( ) ) debug ( MessageFormat . format ( "Using ''{0}'' server credentials" , serverId ) ) ; { try { SettingsDecrypter settingsDecrypter = container . lookup ( SettingsDecrypter . class ) ; SettingsDecryptionResult result = settingsDecrypter . decrypt ( new DefaultSettingsDecryptionRequest ( server ) ) ; server = result . getServer ( ) ; } catch ( ComponentLookupException cle ) { throw new MojoExecutionException ( "Unable to lookup SettingsDecrypter: " + cle . getMessage ( ) , cle ) ; } } serverUsername = server . getUsername ( ) ; serverPassword = server . getPassword ( ) ; // } if ( ! StringUtils . isEmpty ( serverUsername , serverPassword ) ) { if ( isDebug ( ) ) debug ( "Using basic authentication with username: " + serverUsername ) ; client . setCredentials ( serverUsername , serverPassword ) ; return true ; } // A server password without a username is assumed to be an OAuth2 token if ( ! StringUtils . isEmpty ( serverPassword ) ) { if ( isDebug ( ) ) debug ( "Using OAuth2 access token authentication" ) ; client . setOAuth2Token ( serverPassword ) ; return true ; } if ( isDebug ( ) ) debug ( MessageFormat . format ( "Server ''{0}'' is missing username/password credentials" , serverId ) ) ; return false ; }
Configure client with credentials from given server id