Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Created June 8, 2017 07:12
Show Gist options
  • Save marcgeld/322aebda587751631ba73ab0588dc4a7 to your computer and use it in GitHub Desktop.
Save marcgeld/322aebda587751631ba73ab0588dc4a7 to your computer and use it in GitHub Desktop.
Decodes maven passwords in configuration
#!/usr/bin/env groovy
// for logging: #!/usr/bin/env JAVA_OPTS=-Dgroovy.grape.report.downloads=true groovy
@Grab(group='commons-codec', module='commons-codec', version='1.10')
@Grab(group='org.sonatype.plexus', module='plexus-cipher', version='1.7')
import java.nio.file.Paths
import org.apache.commons.codec.binary.Base64
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher
String SYSTEM_PROPERTY_SEC_LOCATION = "settings.security";
DefaultPlexusCipher cipher = new DefaultPlexusCipher();
String masterPasswd = ""
File settingsSecurityFile = Paths.get( System.getProperty("user.home"), ".m2", "settings-security.xml").toFile()
def rootNode = new XmlSlurper().parse( settingsSecurityFile )
rootNode.children().findAll{ it.name() == 'master' }.each{ m ->
m.toString().find(/(?<=\{).*(?=\})/) { encodedText ->
masterPasswd = cipher.decryptDecorated( encodedText, SYSTEM_PROPERTY_SEC_LOCATION )
println "master password: ${masterPasswd}"
}
}
File settingsFile = Paths.get( System.getProperty("user.home"), ".m2", "settings.xml").toFile()
rootNode = new XmlSlurper().parse( settingsFile )
rootNode.servers.children().findAll{ it.name() == 'server' }.each{ m ->
String pw = cipher.isEncryptedString(m.password.text()) ?
cipher.decryptDecorated( m.password.text(), masterPasswd ) : m.password.text()
println "server id: ${m.id} username: ${m.username} password: ${pw}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment