Skip to content

Commit

Permalink
[MNG-8411][MNG-8412][MNG-8416] mvnenc fixes (#1959)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cstamas authored Dec 11, 2024
1 parent 8706dd7 commit 6cb4482
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ protected void lookup(EncryptContext context) {

protected int doExecute(EncryptContext context) throws Exception {
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.style = new AttributedStyle();
context.addInHeader(
Expand All @@ -89,12 +77,7 @@ protected int doExecute(EncryptContext context) throws Exception {
Thread executeThread = Thread.currentThread();
context.terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt());
ConsolePrompt.UiConfig config;
if (context.terminal.getType().equals(Terminal.TYPE_DUMB)
|| 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) {
if (OSUtils.IS_WINDOWS) {
config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )");
} else {
config = new ConsolePrompt.UiConfig("❯", "◯ ", "◉ ", "◯ ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
@Singleton
@Named("init")
public class Init extends GoalSupport {
public class Init extends InteractiveGoalSupport {
private static final String NONE = "__none__";

@Inject
Expand All @@ -63,7 +63,7 @@ public Init(MessageBuilderFactory messageBuilderFactory, SecDispatcher secDispat
}

@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("");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private Settings decrypt(
}
SecDispatcher secDispatcher = new DefaultSecDispatcher(dispatchers, getSecuritySettings(request.getSession()));
Function<String, String> decryptFunction = str -> {
if (secDispatcher.isAnyEncryptedString(str)) {
if (str != null && !str.isEmpty() && !str.contains("${") && secDispatcher.isAnyEncryptedString(str)) {
if (secDispatcher.isLegacyEncryptedString(str)) {
// add a problem
problems.add(new DefaultBuilderProblem(
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ under the License.
<plexusTestingVersion>1.4.0</plexusTestingVersion>
<plexusXmlVersion>4.0.4</plexusXmlVersion>
<resolverVersion>2.0.4</resolverVersion>
<securityDispatcherVersion>4.0.2</securityDispatcherVersion>
<securityDispatcherVersion>4.0.3</securityDispatcherVersion>
<sisuVersion>0.9.0.M3</sisuVersion>
<slf4jVersion>2.0.16</slf4jVersion>
<stax2ApiVersion>4.2.2</stax2ApiVersion>
Expand Down

0 comments on commit 6cb4482

Please sign in to comment.