1818 */ 
1919package  org .apache .maven .plugins .gpg ;
2020
21+ import  javax .inject .Inject ;
22+ 
2123import  java .io .File ;
22- import  java .util .Collections ;
2324import  java .util .List ;
2425
2526import  org .apache .maven .execution .MavenSession ;
2627import  org .apache .maven .plugin .AbstractMojo ;
2728import  org .apache .maven .plugin .MojoExecutionException ;
2829import  org .apache .maven .plugin .MojoFailureException ;
29- import  org .apache .maven .plugins .annotations .Component ;
3030import  org .apache .maven .plugins .annotations .Parameter ;
3131import  org .apache .maven .project .MavenProject ;
3232import  org .apache .maven .settings .Server ;
3333import  org .apache .maven .settings .Settings ;
34- import  org .sonatype . plexus . components . cipher . DefaultPlexusCipher ;
35- import  org .sonatype . plexus . components . sec . dispatcher . DefaultSecDispatcher ;
36- import  org .sonatype . plexus . components . sec . dispatcher . SecDispatcher ;
37- import  org .sonatype . plexus . components . sec . dispatcher . SecDispatcherException ;
34+ import  org .apache . maven . settings . building . SettingsProblem ;
35+ import  org .apache . maven . settings . crypto . DefaultSettingsDecryptionRequest ;
36+ import  org .apache . maven . settings . crypto . SettingsDecrypter ;
37+ import  org .apache . maven . settings . crypto . SettingsDecryptionResult ;
3838
3939/** 
4040 * @author Benjamin Bentmann 
@@ -256,12 +256,6 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
256256 @ Parameter (property  = "gpg.signer" , defaultValue  = GpgSigner .NAME )
257257 private  String  signer ;
258258
259-  /** 
260-  * @since 3.0.0 
261-  */ 
262-  @ Component 
263-  protected  MavenSession  session ;
264- 
265259 /** 
266260 * Switch to improve plugin enforcement of "best practices". If set to {@code false}, plugin retains all the 
267261 * backward compatibility regarding getting secrets (but will warn). If set to {@code true}, plugin will fail 
@@ -285,14 +279,16 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
285279 protected  Settings  settings ;
286280
287281 /** 
288-  * Maven Security Dispatcher. 
289-  * 
290-  * @since 1.6 
291-  * @deprecated Provides quasi-encryption, should be avoided. 
282+  * @since 3.0.0 
292283 */ 
293-  @ Deprecated 
294-  private  final  SecDispatcher  secDispatcher  =
295-  new  DefaultSecDispatcher (new  DefaultPlexusCipher (), Collections .emptyMap (), "~/.m2/settings-security.xml" );
284+  @ Inject 
285+  protected  MavenSession  session ;
286+ 
287+  /** 
288+  * @since 3.2.6 
289+  */ 
290+  @ Inject 
291+  protected  SettingsDecrypter  settingsDecrypter ;
296292
297293 @ Override 
298294 public  final  void  execute () throws  MojoExecutionException , MojoFailureException  {
@@ -415,11 +411,23 @@ private String loadGpgPassphrase() throws MojoFailureException {
415411 Server  server  = settings .getServer (passphraseServerId );
416412 if  (server  != null ) {
417413 if  (isNotBlank (server .getPassphrase ())) {
418-  try  {
419-  return  secDispatcher .decrypt (server .getPassphrase ());
420-  } catch  (SecDispatcherException  e ) {
421-  throw  new  MojoFailureException ("Unable to decrypt gpg passphrase" , e );
414+  SettingsDecryptionResult  result  =
415+  settingsDecrypter .decrypt (new  DefaultSettingsDecryptionRequest (server ));
416+  for  (SettingsProblem  problem  : result .getProblems ()) {
417+  switch  (problem .getSeverity ()) {
418+  case  WARNING :
419+  case  ERROR :
420+  getLog ().warn (problem .getMessage (), problem .getException ());
421+  break ;
422+  case  FATAL :
423+  getLog ().error (problem .getMessage (), problem .getException ());
424+  throw  new  MojoFailureException (problem .getMessage (), problem .getException ());
425+  default :
426+  throw  new  IllegalStateException ("Unknown severity: " 
427+  + problem .getSeverity ().toString ());
428+  }
422429 }
430+  return  result .getServer ().getPassphrase ();
423431 }
424432 }
425433 }
0 commit comments