[MNG-8411][MNG-8412][MNG-8416] mvnenc fixes (#1959)

Cumulative mvnenc fixes:
* make the 3 goals (sans init) work in batch mode
* move the Maven DI SecDispatcher provider to test scope in maven-impl (duplicates components in Maven)
* update to SecDisparcher 4.0.3 (contains fix for MNG-8416 and one other bug)

---

https://issues.apache.org/jira/browse/MNG-8411
https://issues.apache.org/jira/browse/MNG-8412
https://issues.apache.org/jira/browse/MNG-8416
This commit is contained in:
Tamas Cservenak 2024-12-11 10:13:06 +01:00 committed by GitHub
parent 8706dd7edf
commit 6cb4482a98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 22 deletions

View File

@ -65,18 +65,6 @@ public class EncryptInvoker extends LookupInvoker<EncryptContext> {
protected int doExecute(EncryptContext context) throws Exception { protected int doExecute(EncryptContext context) throws Exception {
try { try {
if (!context.interactive) {
context.terminal.writer().println("This tool works only in interactive mode!");
context.terminal
.writer()
.println("Tool purpose is to configure password management on developer workstations.");
context.terminal
.writer()
.println(
"Note: Generated configuration can be moved/copied to headless environments, if configured as such.");
return BAD_OPERATION;
}
context.header = new ArrayList<>(); context.header = new ArrayList<>();
context.style = new AttributedStyle(); context.style = new AttributedStyle();
context.addInHeader( context.addInHeader(
@ -89,12 +77,7 @@ public class EncryptInvoker extends LookupInvoker<EncryptContext> {
Thread executeThread = Thread.currentThread(); Thread executeThread = Thread.currentThread();
context.terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt()); context.terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt());
ConsolePrompt.UiConfig config; ConsolePrompt.UiConfig config;
if (context.terminal.getType().equals(Terminal.TYPE_DUMB) if (OSUtils.IS_WINDOWS) {
|| context.terminal.getType().equals(Terminal.TYPE_DUMB_COLOR)) {
context.terminal.writer().println(context.terminal.getName() + ": " + context.terminal.getType());
throw new IllegalStateException("Dumb terminal detected.\nThis tool requires real terminal to work!\n"
+ "Note: On Windows Jansi or JNA library must be included in classpath.");
} else if (OSUtils.IS_WINDOWS) {
config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )"); config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )");
} else { } else {
config = new ConsolePrompt.UiConfig("", "", "", ""); config = new ConsolePrompt.UiConfig("", "", "", "");

View File

@ -54,7 +54,7 @@ import static org.apache.maven.cling.invoker.mvnenc.EncryptInvoker.OK;
*/ */
@Singleton @Singleton
@Named("init") @Named("init")
public class Init extends GoalSupport { public class Init extends InteractiveGoalSupport {
private static final String NONE = "__none__"; private static final String NONE = "__none__";
@Inject @Inject
@ -63,7 +63,7 @@ public class Init extends GoalSupport {
} }
@Override @Override
public int execute(EncryptContext context) throws Exception { public int doExecute(EncryptContext context) throws Exception {
context.addInHeader(context.style.italic().bold().foreground(Colors.rgbColor("yellow")), "goal: init"); context.addInHeader(context.style.italic().bold().foreground(Colors.rgbColor("yellow")), "goal: init");
context.addInHeader(""); context.addInHeader("");

View File

@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.cling.invoker.mvnenc.goals;
import org.apache.maven.api.services.MessageBuilderFactory;
import org.apache.maven.cling.invoker.mvnenc.EncryptContext;
import org.apache.maven.cling.invoker.mvnenc.EncryptInvoker;
import org.codehaus.plexus.components.secdispatcher.SecDispatcher;
/**
* The support class for interactive goal implementations.
*/
public abstract class InteractiveGoalSupport extends GoalSupport {
protected InteractiveGoalSupport(MessageBuilderFactory messageBuilderFactory, SecDispatcher secDispatcher) {
super(messageBuilderFactory, secDispatcher);
}
@Override
public int execute(EncryptContext context) throws Exception {
if (!context.interactive) {
context.terminal.writer().println("This tool works only in interactive mode!");
context.terminal
.writer()
.println("Tool purpose is to configure password management on developer workstations.");
context.terminal
.writer()
.println(
"Note: Generated configuration can be moved/copied to headless environments, if configured as such.");
return EncryptInvoker.BAD_OPERATION;
}
return doExecute(context);
}
protected abstract int doExecute(EncryptContext context) throws Exception;
}

View File

@ -274,7 +274,7 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
} }
SecDispatcher secDispatcher = new DefaultSecDispatcher(dispatchers, getSecuritySettings(request.getSession())); SecDispatcher secDispatcher = new DefaultSecDispatcher(dispatchers, getSecuritySettings(request.getSession()));
Function<String, String> decryptFunction = str -> { Function<String, String> decryptFunction = str -> {
if (secDispatcher.isAnyEncryptedString(str)) { if (str != null && !str.isEmpty() && !str.contains("${") && secDispatcher.isAnyEncryptedString(str)) {
if (secDispatcher.isLegacyEncryptedString(str)) { if (secDispatcher.isLegacyEncryptedString(str)) {
// add a problem // add a problem
problems.add(new DefaultBuilderProblem( problems.add(new DefaultBuilderProblem(

View File

@ -163,7 +163,7 @@ under the License.
<plexusTestingVersion>1.4.0</plexusTestingVersion> <plexusTestingVersion>1.4.0</plexusTestingVersion>
<plexusXmlVersion>4.0.4</plexusXmlVersion> <plexusXmlVersion>4.0.4</plexusXmlVersion>
<resolverVersion>2.0.4</resolverVersion> <resolverVersion>2.0.4</resolverVersion>
<securityDispatcherVersion>4.0.2</securityDispatcherVersion> <securityDispatcherVersion>4.0.3</securityDispatcherVersion>
<sisuVersion>0.9.0.M3</sisuVersion> <sisuVersion>0.9.0.M3</sisuVersion>
<slf4jVersion>2.0.16</slf4jVersion> <slf4jVersion>2.0.16</slf4jVersion>
<stax2ApiVersion>4.2.2</stax2ApiVersion> <stax2ApiVersion>4.2.2</stax2ApiVersion>