Skip to content

Commit

Permalink
Merge pull request #480 from shimono/hotfix
Browse files Browse the repository at this point in the history
Hotfix for #479
  • Loading branch information
shimono authored Sep 5, 2019
2 parents 7826af3 + bf2156f commit fe050f1
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.7.18b
BUG FIXES:
* Cell Owner URL being persisted without #fragment info. ([#479](https://github.com/personium/personium-core/issues/479))

## 1.7.18a
BUG FIXES:
* 500 Error when Non-Cell URL (incl. Unit URL) is given in p_target param at TokenEndpoint. ([#475](https://github.com/personium/personium-core/issues/475))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>io.personium</groupId>
<artifactId>personium-core</artifactId>
<packaging>war</packaging>
<version>1.7.18a</version>
<version>1.7.18b</version>
<name>personium-core Maven Webapp</name>
<url>http://maven.apache.org</url>
<licenses>
Expand Down
49 changes: 48 additions & 1 deletion src/main/java/io/personium/core/utils/HttpClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package io.personium.core.utils;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -25,6 +27,7 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
Expand All @@ -34,6 +37,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
import org.apache.http.ssl.SSLContextBuilder;

/**
Expand All @@ -44,6 +48,8 @@ public class HttpClientFactory {
public static final String TYPE_DEFAULT = "default";
/** Type of HTTP communication.*/
public static final String TYPE_INSECURE = "insecure";
/** Type name of HTTP client that always connect to .*/
public static final String TYPE_ALWAYS_LOCAL = "alwayslocal";

/** Connection timeout value.*/
private static final int TIMEOUT = 60000; // 20000;
Expand All @@ -69,10 +75,50 @@ public static CloseableHttpClient create(final String type) {
.setDefaultRequestConfig(config)
.useSystemProperties()
.build();
} else if (!TYPE_INSECURE.equalsIgnoreCase(type)) {
} else if (TYPE_INSECURE.equalsIgnoreCase(type)) {
return createInsecure(config);
} else if (TYPE_ALWAYS_LOCAL.equalsIgnoreCase(type)) {
return createAlwaysLocal(config);
}
return null;

}
private static CloseableHttpClient createAlwaysLocal(RequestConfig config) {
SSLConnectionSocketFactory sf = null;
try {
sf = createInsecureSSLConnectionSocketFactory();
} catch (Exception e) {
return null;
}

Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sf)
.register("http", PlainConnectionSocketFactory.INSTANCE)
.build();
/* Custom DNS resolver */
DnsResolver dnsResolver = new SystemDefaultDnsResolver() {
@Override
public InetAddress[] resolve(final String host) throws UnknownHostException {
// Always 127.0.0.1
return new InetAddress[] { InetAddress.getByName("127.0.0.1") };
}
};
HttpClientConnectionManager cm = new BasicHttpClientConnectionManager(registry,
null, /* Default ConnectionFactory */
null, /* Default SchemePortResolver */
dnsResolver /* Our DnsResolver */
);


return HttpClientBuilder.create()
.setDefaultRequestConfig(config)
.setConnectionManager(cm)
.useSystemProperties()
.build();


}
private static CloseableHttpClient createInsecure(RequestConfig config) {
SSLConnectionSocketFactory sf = null;
try {
sf = createInsecureSSLConnectionSocketFactory();
Expand All @@ -91,6 +137,7 @@ public static CloseableHttpClient create(final String type) {
.setConnectionManager(cm)
.useSystemProperties()
.build();

}

private static SSLConnectionSocketFactory createInsecureSSLConnectionSocketFactory()
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/personium/core/utils/UriUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ public static String convertSchemeFromHttpToLocalUnit(String url) {
StringBuilder sb = new StringBuilder(SCHEME_LOCALUNIT);
sb.append(":").append(cellName).append(":");
sb.append(uri.getPath());
if (uri.getQuery() != null) {
sb.append("?").append(uri.getQuery());
}
if (uri.getFragment() != null) {
sb.append("#").append(uri.getFragment());
}
return sb.toString();
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/personium/core/utils/UriUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public void convertSchemeFromHttpToLocalUnit_Normal_url_starts_with_uniturl() th
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("https://unit.example/cell/"),
is("personium-localunit:/cell/"));
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("https://unit.example/cell/#acct"),
is("personium-localunit:/cell/#acct"));
}

/**
Expand All @@ -161,6 +164,18 @@ public void convertSchemeFromHttpToLocalUnit_Normal_url_is_fqdn_base() throws Ex
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("http://cell.unit.example/"),
is("personium-localunit:cell:/"));
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("http://cell.unit.example/#account"),
is("personium-localunit:cell:/#account"));
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("http://cell.unit.example/ab/?query=23"),
is("personium-localunit:cell:/ab/?query=23"));
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("http://cell.unit.example/ab/?query=23#frag"),
is("personium-localunit:cell:/ab/?query=23#frag"));
assertThat(
UriUtils.convertSchemeFromHttpToLocalUnit("http://cell.unit.example/ab/#frag?query"),
is("personium-localunit:cell:/ab/#frag?query"));
}
/**
* Test convertSchemeFromHttpToLocalUnit().
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/io/personium/test/jersey/PersoniumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ public void start() {
}
}

@SuppressWarnings("deprecation")
@Override
public void stop() {
this.server.stop();
this.server.shutdownNow();;
}

};
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/io/personium/test/jersey/cell/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import io.personium.test.jersey.unit.UnitUserCellTest;

/**
* パッケージ配下のテストケースを全て実行するためのテストスイート.
*/
Expand Down
Loading

0 comments on commit fe050f1

Please sign in to comment.