Skip to content

Commit

Permalink
Merge branch 'snapshot' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 27, 2022
2 parents b8fda01 + a8a5442 commit cba5959
Show file tree
Hide file tree
Showing 36 changed files with 543 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class ClientUtils {

public static final String DELTAS_XML_SUFFIX = "</objectDeltaObjectList>\n";

public static final ItemName O_OBJECT_MODIFICATION = new ItemName("http://midpoint.evolveum.com/xml/ns/public/common/api-types-3", "objectModification");

public static List<MidPointObject> filterObjectTypeOnly(List<MidPointObject> objects) {
return filterObjectTypeOnly(objects, true);
}
Expand Down Expand Up @@ -149,8 +152,8 @@ private static MidPointObject parseElement(Element element) {
String localName = element.getLocalName();

boolean executable = (namespace == null || SchemaConstantsGenerated.NS_SCRIPTING.equals(namespace)) && SCRIPTING_ACTIONS.contains(localName);
boolean delta = (namespace == null || SchemaConstantsGenerated.O_OBJECT_MODIFICATION.getNamespaceURI().equals(namespace))
&& SchemaConstantsGenerated.O_OBJECT_MODIFICATION.getLocalPart().equals(localName);
boolean delta = (namespace == null || O_OBJECT_MODIFICATION.getNamespaceURI().equals(namespace))
&& O_OBJECT_MODIFICATION.getLocalPart().equals(localName);

ObjectTypes type = getObjectType(element);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.evolveum.midpoint.studio.client;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.util.PrismContextFactory;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.util.DOMUtilSettings;
import com.evolveum.midpoint.util.MiscUtil;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -19,6 +19,8 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -74,6 +76,8 @@ public class ServiceFactory {

private int responseTimeout = 60;

private boolean useHttp2 = false;

public ServiceFactory url(final String url) {
this.url = url;
return this;
Expand Down Expand Up @@ -129,27 +133,25 @@ public ServiceFactory responseTimeout(final int responseTimeout) {
return this;
}

public ServiceFactory useHttp2(final boolean useHttp2) {
this.useHttp2 = useHttp2;
return this;
}

public Service create() throws Exception {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.followSslRedirects(false);
builder.followRedirects(false);
if (useHttp2) {
setupHttp2(builder);
}

builder.writeTimeout(responseTimeout, TimeUnit.SECONDS);
builder.readTimeout(responseTimeout, TimeUnit.SECONDS);
builder.connectTimeout(responseTimeout, TimeUnit.SECONDS);

if (username != null || password != null) {
builder.authenticator((route, response) -> {

if (response.request().header("Authorization") != null) {
return null; // Give up, we've already failed to authenticate.
}

String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Authorization", credential)
.build();
});
setupAuthentication(builder);
}

if (ignoreSSLErrors) {
Expand All @@ -163,44 +165,7 @@ public Service create() throws Exception {
}

if (StringUtils.isNotEmpty(proxyServer)) {
URI uri = URI.create(proxyServer);

if (proxyServerPort == null) {
if (uri.getPort() >= 0 && uri.getPort() <= 0xFFFF) {
proxyServerPort = uri.getPort();
} else if (proxyServerType.getType() == Proxy.Type.HTTP) {
if ("http".equalsIgnoreCase(uri.getScheme())) {
proxyServerPort = 80;
} else if ("https".equalsIgnoreCase(uri.getScheme())) {
proxyServerPort = 443;
}
}
}

if (proxyServerType == null) {
throw new IllegalArgumentException("Proxy server type not defined");
}

if (StringUtils.isEmpty(uri.getHost())) {
throw new IllegalArgumentException("Proxy host not defined");
}

if (proxyServerPort == null) {
throw new IllegalArgumentException("Proxy port undefined");
}

Proxy proxy = new Proxy(proxyServerType.getType(), new InetSocketAddress(uri.getHost(), proxyServerPort));
builder.proxy(proxy);

if (proxyUsername != null || proxyPassword != null) {
builder.proxyAuthenticator((route, response) -> {

String credential = Credentials.basic(proxyUsername, proxyPassword);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
});
}
setupProxy(builder);
}

builder.addInterceptor(chain -> {
Expand All @@ -216,19 +181,91 @@ public Service create() throws Exception {
return chain.proceed(newRequest);
});

HttpLoggingInterceptor logging = new HttpLoggingInterceptor(
message -> {
if (messageListener == null) {
return;
}

messageListener.handleMessage(message);
});
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(logging);
setupLogging(builder);

ServiceContext context = new ServiceContext(url, DEFAULT_PRISM_CONTEXT, builder.build());

return new ServiceImpl(context);
}

private void setupHttp2(OkHttpClient.Builder builder) {
URI uri = URI.create(url);
String scheme = uri.getScheme();
if (scheme == null) {
return;
}

scheme = scheme.toLowerCase();
if ("http".equals(scheme)) {
builder.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
} else if ("https".equals(scheme)) {
builder.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
}
}

private void setupAuthentication(OkHttpClient.Builder builder) {
builder.authenticator((route, response) -> {

if (response.request().header("Authorization") != null) {
return null; // Give up, we've already failed to authenticate.
}

String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Authorization", credential)
.build();
});
}

private void setupProxy(OkHttpClient.Builder builder) {
URI uri = URI.create(proxyServer);

if (proxyServerPort == null) {
if (uri.getPort() >= 0 && uri.getPort() <= 0xFFFF) {
proxyServerPort = uri.getPort();
} else if (proxyServerType.getType() == Proxy.Type.HTTP) {
if ("http".equalsIgnoreCase(uri.getScheme())) {
proxyServerPort = 80;
} else if ("https".equalsIgnoreCase(uri.getScheme())) {
proxyServerPort = 443;
}
}
}

if (proxyServerType == null) {
throw new IllegalArgumentException("Proxy server type not defined");
}

if (StringUtils.isEmpty(uri.getHost())) {
throw new IllegalArgumentException("Proxy host not defined");
}

if (proxyServerPort == null) {
throw new IllegalArgumentException("Proxy port undefined");
}

Proxy proxy = new Proxy(proxyServerType.getType(), new InetSocketAddress(uri.getHost(), proxyServerPort));
builder.proxy(proxy);

if (proxyUsername != null || proxyPassword != null) {
builder.proxyAuthenticator((route, response) -> {

String credential = Credentials.basic(proxyUsername, proxyPassword);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
});
}
}

private void setupLogging(OkHttpClient.Builder builder) {
if (messageListener == null) {
messageListener = message -> {
};
}

HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> messageListener.handleMessage(message));
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addNetworkInterceptor(logging);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public <O extends ObjectType> OperationResult recompute(Class<O> type, String oi
ObjectModificationType modification = new ObjectModificationType();
modification.oid(oid);

String xml = context.getSerializer().serialize(new JAXBElement(SchemaConstantsGenerated.O_OBJECT_MODIFICATION, ObjectModificationType.class, modification));
String xml = context.getSerializer().serialize(new JAXBElement(ClientUtils.O_OBJECT_MODIFICATION, ObjectModificationType.class, modification));

Request.Builder builder = context.build("/" + path + "/" + oid, options)
.post(RequestBody.create(xml, ServiceContext.APPLICATION_XML));
Expand Down
8 changes: 3 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ dependencyResolutionManagement {
version("jcommander", "1.81")
version("jupiter", "5.6.0")
version("logback", "1.2.3")
version("midpoint", "4.4.1")
version("midpoint", "4.5")
version("midscribe", "4.4-SNAPSHOT")
version("okhttp", "4.9.0")
version("okhttp", "4.9.3")
version("openkeepass", "0.8.1")
version("slf4j", "1.7.26")
version("spring", "5.2.8.RELEASE")
version("spring", "5.3.8")
version("stax", "1.2.0")
version("testng", "6.14.3")
version("xchart", "3.5.4")
Expand Down Expand Up @@ -52,7 +51,6 @@ dependencyResolutionManagement {
alias("okhttp3").to("com.squareup.okhttp3", "okhttp").versionRef("okhttp")
alias("openkeepass").to("de.slackspace", "openkeepass").versionRef("openkeepass")
alias("security-api").to("com.evolveum.midpoint.repo", "security-api").versionRef("midpoint")
alias("slf4j-log4j12").to("org.slf4j", "slf4j-log4j12").versionRef("slf4j")
alias("spring-core").to("org.springframework", "spring-core").versionRef("spring")
alias("stax").to("stax", "stax").versionRef("stax")
alias("xchart").to("org.knowm.xchart", "xchart").versionRef("xchart")
Expand Down
8 changes: 8 additions & 0 deletions studio-idea-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# MidPoint Studio

## 4.5.0
### Fixed
- MID-7658 task upgrade action fix
- MID-7691 console logging fixes, upload/test resource weren't logged correctly
- MID-7695 namespace variants improvements
- MID-7735 upload/recompute now recomputes all uploaded objects
- MID-7810 encrypted credentials not expanded in diff now

## 4.4.2
### Changed
- Changed format of local/remote diff (internal XML file representation)
Expand Down
3 changes: 1 addition & 2 deletions studio-idea-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.6.10"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.4.0"
id("org.jetbrains.intellij") version "1.5.2"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "1.3.1"
// detekt linter - read more: https://detekt.github.io/detekt/gradle.html
Expand Down Expand Up @@ -84,7 +84,6 @@ dependencies {
implementation(libs.openkeepass)
implementation(libs.commons.lang)
// compile(libs.xchart)
implementation(libs.slf4j.log4j12)
implementation(libs.okhttp3)
implementation(libs.okhttp.logging)

Expand Down
8 changes: 4 additions & 4 deletions studio-idea-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = com.evolveum.midpoint.studio
pluginName = intellij-midpoint-studio
pluginVersion = 4.4.2
pluginVersion = 4.5.0

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html#intellij-platform-based-products-of-recent-ide-versions
# for insight into build numbers and IntelliJ Platform versions.
Expand All @@ -12,14 +12,14 @@ pluginUntilBuild = 221.*

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions = IC-2020.3.4, IC-2021.1.3, IC-2021.2.2, IC-2021.3.2, IC-2022.1
pluginVerifierIdeVersions = IC-2020.3.4, IC-2021.1.3, IC-2021.2.2, IC-2021.3.3, IC-2022.1

platformType = IC
platformVersion = 2021.3.2
platformVersion = 2022.1
platformDownloadSources = true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = PsiViewer:213-SNAPSHOT, com.jetbrains.hackathon.indices.viewer:1.20, java, Groovy, maven
platformPlugins = java, Groovy, maven, PsiViewer:221-SNAPSHOT, com.jetbrains.hackathon.indices.viewer:1.21

# Opt-out flag for bundling Kotlin standard library.
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class MidPointIcons {

public static final Icon ACTION_RANDOM_OID = IconLoader.findIcon("/icons/random_oid.png");
public static final @NotNull Icon RandomOid = load("icons/dice.svg");

public static final @NotNull Icon Midpoint = load("icons/midpoint.svg");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.studio.client.MidPointObject;
import com.evolveum.midpoint.studio.impl.ExpanderOptions;
import com.evolveum.midpoint.studio.impl.xml.DiffObjectType;
import com.evolveum.midpoint.studio.impl.xml.DiffType;
import com.evolveum.midpoint.studio.impl.xml.LocationType;
Expand Down Expand Up @@ -37,10 +38,11 @@ public DiffTask(@NotNull AnActionEvent event, String title, String notificationK

protected String createDiffXml(MidPointObject first, VirtualFile firstFile, LocationType firstLocation,
MidPointObject second, VirtualFile secondFile, LocationType secondLocation) throws SchemaException, IOException {
// todo expand local content before its used for comparing

PrismObject firstObject = client.parseObject(first.getContent());
PrismObject secondObject = client.parseObject(second.getContent());
ExpanderOptions opts = new ExpanderOptions().expandEncrypted(false);

PrismObject firstObject = client.parseObject(first.getContent(), opts);
PrismObject secondObject = client.parseObject(second.getContent(), opts);

DiffType objectsDiff = new DiffType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.evolveum.midpoint.studio.util.MidPointUtils;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionPipelineType;
Expand Down Expand Up @@ -47,7 +48,7 @@ public ProcessObjectResult processObject(MidPointObject obj) throws Exception {
return por;
}

if (!MidPointUtils.isAssignableFrom(ObjectTypes.FOCUS_TYPE, obj.getType())) {
if (obj.getType() == null || !AssignmentHolderType.class.isAssignableFrom(obj.getType().getClassDefinition())) {
return por;
}

Expand Down
Loading

0 comments on commit cba5959

Please sign in to comment.