Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
ea48fb8
fix: Update code
larshelge Oct 17, 2025
74eb2fe
merge: Merge from master branch
larshelge Oct 17, 2025
2a38950
fix: Update code
larshelge Oct 17, 2025
578e56c
merge: Merge from master branch
larshelge Oct 17, 2025
421f230
fix: Update code
larshelge Oct 17, 2025
161675d
fix: Update code
larshelge Oct 17, 2025
5c81045
merge: Merge from master branch
larshelge Oct 17, 2025
37fb947
fix: Update code
larshelge Oct 17, 2025
13aa55d
fix: Update code
larshelge Oct 17, 2025
e6285b4
merge: Merge from master branch
larshelge Oct 17, 2025
38a631b
fix: Update code
larshelge Oct 18, 2025
e8ec7f0
merge: Merge from master branch
larshelge Oct 18, 2025
781f863
fix: Update code
larshelge Oct 20, 2025
db38736
merge: Merge from master branch
larshelge Oct 20, 2025
6c58b97
fix: Update code
larshelge Oct 20, 2025
3683c8a
merge: Merge from master branch
larshelge Oct 20, 2025
f80713f
fix: Update code
larshelge Oct 20, 2025
99430a6
merge: Merge from master branch
larshelge Oct 20, 2025
8ad0cb3
fix: Update code
larshelge Oct 20, 2025
162c1d8
fix: Update code
larshelge Oct 21, 2025
a0def00
fix: Update code
larshelge Oct 21, 2025
ee2959f
fix: Update code
larshelge Oct 21, 2025
df4fc10
merge: Merge from master branch
larshelge Oct 21, 2025
537bc79
fix: Update code
larshelge Oct 21, 2025
9456c80
fix: Update code
larshelge Oct 26, 2025
2e5a444
merge: Merge from master branch
larshelge Oct 26, 2025
5c51ad8
fix: Update code
larshelge Oct 26, 2025
4e7a231
fix: Update code
larshelge Oct 26, 2025
f8e92e1
fix: Update code
larshelge Oct 26, 2025
f62cd0e
fix: Update code
larshelge Oct 26, 2025
ec8d1ba
fix: Update code
larshelge Oct 26, 2025
434ac63
fix: Update code
larshelge Oct 26, 2025
6640662
fix: Update code
larshelge Oct 26, 2025
65091f9
merge: Merge from master branch
larshelge Oct 26, 2025
6581d1d
fix: Update code
larshelge Oct 26, 2025
da05a87
merge: Merge from master branch
larshelge Oct 26, 2025
3a179e3
fix: Update code
larshelge Oct 26, 2025
d4c8e71
fix: Update code
larshelge Oct 26, 2025
4a1562f
fix: Update code
larshelge Oct 26, 2025
59c0f29
merge: Merge from master branch
larshelge Oct 26, 2025
3cb3f54
fix: Update code
larshelge Oct 27, 2025
b3ee7c3
fix: Update code
larshelge Oct 27, 2025
129d743
fix: Update code
larshelge Oct 27, 2025
85bd992
fix: Update code
larshelge Oct 27, 2025
d7c0ab8
merge: Merge from master branch
larshelge Oct 27, 2025
8443b1a
fix: Update code
larshelge Oct 27, 2025
9771774
fix: Update code
larshelge Oct 27, 2025
bf48f73
fix: Update code
larshelge Oct 27, 2025
a761386
merge: Merge from master branch
larshelge Oct 27, 2025
eb82d7d
fix: Update code
larshelge Oct 27, 2025
6e02053
fix: Update code
larshelge Oct 27, 2025
8e18635
fix: Update code
larshelge Oct 27, 2025
566d008
fix: Update code
larshelge Oct 27, 2025
4166363
fix: Update code
larshelge Oct 27, 2025
1cc7986
merge: Merge from master branch
larshelge Oct 27, 2025
20e0086
fix: Update code
larshelge Oct 27, 2025
14455e1
fix: Update code
larshelge Oct 27, 2025
0f6037b
fix: Update code
larshelge Oct 27, 2025
4dbe4f2
fix: Update code
larshelge Oct 27, 2025
a85f897
fix: Update code
larshelge Oct 27, 2025
5beba5d
fix: Update code
larshelge Oct 27, 2025
3b18c15
fix: Update code
larshelge Oct 27, 2025
71199ce
fix: Update code
larshelge Oct 27, 2025
4dfe22e
fix: Update code
larshelge Oct 27, 2025
11de293
fix: Update code
larshelge Oct 27, 2025
69ee04b
fix: Update code
larshelge Oct 27, 2025
5859738
merge: Merge from master branch
larshelge Oct 27, 2025
99a23b4
fix: Update code
larshelge Oct 28, 2025
0c02dd3
fix: Update code
larshelge Oct 28, 2025
604b794
merge: Merge from master branch
larshelge Oct 28, 2025
b1cba59
fix: Update code
larshelge Oct 28, 2025
fafe8d8
fix: Update code
larshelge Oct 29, 2025
1e81ba8
fix: Update code
larshelge Oct 29, 2025
c433bd9
fix: Update code
larshelge Oct 29, 2025
82d5481
fix: Update code
larshelge Oct 29, 2025
3b1f92c
fix: Update code
larshelge Oct 29, 2025
b7c3742
fix: Update code
larshelge Oct 29, 2025
de9917b
fix: Update code
larshelge Oct 29, 2025
8b264a8
fix: Update code
larshelge Oct 29, 2025
0b7db98
fix: Update code
larshelge Oct 29, 2025
5b7b44d
merge: Merge from master branch
larshelge Oct 29, 2025
99fda61
fix: Update code
larshelge Oct 29, 2025
1432a7f
merge: Merge from master branch
larshelge Oct 29, 2025
53dbb3f
fix: Update code
larshelge Oct 29, 2025
c41659f
merge: Merge from master branch
larshelge Oct 29, 2025
a72fac5
fix: Update code
larshelge Oct 29, 2025
2bfc598
fix: Update code
larshelge Oct 29, 2025
4c08b1e
merge: Merge from master branch
larshelge Oct 29, 2025
3e4a803
fix: Update code
larshelge Oct 29, 2025
38bfafb
merge: Merge from master branch
larshelge Oct 29, 2025
0a99f45
fix: Update code
larshelge Oct 30, 2025
79b940c
fix: Update code
larshelge Oct 30, 2025
3b87282
fix: Update code
larshelge Oct 30, 2025
b0c57b3
fix: Update code
larshelge Oct 30, 2025
42f44af
merge: Merge from master branch
larshelge Oct 30, 2025
84afab9
fix: Update code
larshelge Oct 31, 2025
04afcfc
merge: Merge from master branch
larshelge Oct 31, 2025
26fc5b2
fix: Update code
larshelge Oct 31, 2025
57aee9c
fix: Update code
larshelge Oct 31, 2025
8a4f2eb
merge: Merge from master branch
larshelge Oct 31, 2025
0484cc2
fix: Update code
larshelge Oct 31, 2025
4490414
merge: Merge from master branch
larshelge Oct 31, 2025
c5c6fc4
fix: Update code
larshelge Nov 1, 2025
0e51060
merge: Merge from master branch
larshelge Nov 1, 2025
ac7b76a
fix: Update code
larshelge Nov 2, 2025
da2233a
fix: Update code
larshelge Nov 2, 2025
7011be7
fix: Update code
larshelge Nov 2, 2025
e822975
merge: Merge from master branch
larshelge Nov 2, 2025
6acdb6d
fix: Update code
larshelge Nov 2, 2025
fbfb3f9
fix: Update code
larshelge Nov 4, 2025
dedad48
fix: Update code
larshelge Nov 4, 2025
7409fc6
fix: Update code
larshelge Nov 4, 2025
196438d
fix: Update code
larshelge Nov 4, 2025
070de64
merge: Merge from master branch
larshelge Nov 4, 2025
029c8e7
fix: Update code
larshelge Nov 4, 2025
a7e7789
merge: Merge from master branch
larshelge Nov 4, 2025
e516989
fix: Update code
larshelge Nov 4, 2025
e085b15
merge: Merge from master branch
larshelge Nov 4, 2025
ceb9e17
fix: Update code
larshelge Nov 4, 2025
88ef10b
merge: Merge from master branch
larshelge Nov 4, 2025
3f286a7
fix: Update code
larshelge Nov 4, 2025
fdcd1ca
fix: Update code
larshelge Nov 4, 2025
87bb7a3
fix: Update code
larshelge Nov 4, 2025
edfeef6
merge: Merge from master branch
larshelge Nov 4, 2025
129e21d
fix: Update code
larshelge Nov 4, 2025
b9b55e3
fix: Update code
larshelge Nov 4, 2025
d8f6502
merge: Merge from master branch
larshelge Nov 4, 2025
fa76d6f
fix: Update code
larshelge Nov 4, 2025
5203e87
merge: Merge from master branch
larshelge Nov 4, 2025
e3d4f2b
fix: Update code
larshelge Nov 5, 2025
998bbf3
merge: Merge from master branch
larshelge Nov 5, 2025
9a51d02
fix: Update code
larshelge Nov 5, 2025
7320ab9
merge: Merge from master branch
larshelge Nov 5, 2025
1558a8b
Merge branch 'master' into lars-dev
larshelge Nov 5, 2025
b2895c8
fix: Update code
larshelge Nov 5, 2025
c9e87a0
merge: Merge from master branch
larshelge Nov 5, 2025
b6af00c
Merge branch 'master' into lars-dev
larshelge Nov 7, 2025
df10196
fix: Update code
larshelge Nov 7, 2025
6562434
fix: Update code
larshelge Nov 8, 2025
d2ed9ac
merge: Merge from master branch
larshelge Nov 8, 2025
6494cf6
merge: Merge from master branch
larshelge Nov 8, 2025
6a9a86a
fix: Update code
larshelge Nov 8, 2025
be978cc
merge: Merge from master branch
larshelge Nov 8, 2025
20977db
fix: Update code
larshelge Nov 8, 2025
eb47777
fix: Update code
larshelge Nov 8, 2025
c3a8e7d
merge: Merge from master branch
larshelge Nov 8, 2025
34d99fc
fix: Update code
larshelge Nov 8, 2025
693b45f
fix: Update code
larshelge Nov 8, 2025
9474aac
merge: Merge from master branch
larshelge Nov 8, 2025
73026e0
fix: Update code
larshelge Nov 10, 2025
ba78ebf
fix: Update code
larshelge Nov 10, 2025
0a3ac54
fix: Update code
larshelge Nov 10, 2025
f7d22c7
merge: Merge from master branch
larshelge Nov 10, 2025
2a1665d
fix: Update code
larshelge Nov 10, 2025
dfb0c6c
merge: Merge from master branch
larshelge Nov 10, 2025
95106ae
Merge branch 'master' into lars-dev
larshelge Nov 11, 2025
5ef967c
fix: Update code
larshelge Nov 16, 2025
10dd994
merge: Merge from master branch
larshelge Nov 16, 2025
bbd89c1
fix: Update code
larshelge Nov 18, 2025
e9d5a97
fix: Update code
larshelge Nov 18, 2025
712feb6
fix: Update code
larshelge Nov 18, 2025
b215873
merge: Merge from master branch
larshelge Nov 18, 2025
83c1f92
fix: Update code
larshelge Nov 18, 2025
fba3848
merge: Merge from master branch
larshelge Nov 18, 2025
2ee2ea0
fix: Update code
larshelge Nov 18, 2025
9399b0f
fix: Update code
larshelge Nov 18, 2025
f8a58e6
merge: Merge from master branch
larshelge Nov 18, 2025
fd3606e
Merge branch 'master' into lars-dev
larshelge Nov 19, 2025
978feca
merge: Merge from master branch
larshelge Dec 3, 2025
44bcdbf
fix: Update code
larshelge Dec 3, 2025
817b89c
fix: Update code
larshelge Dec 3, 2025
dc2d7bf
merge: Merge from master branch
larshelge Dec 4, 2025
28fb193
merge: Merge from master branch
larshelge Dec 4, 2025
b7ec014
fix: Update code
larshelge Dec 21, 2025
31f4b4f
Merge branch 'master' into lars-dev
larshelge Dec 21, 2025
f4f4379
fix: Update code
larshelge Dec 25, 2025
7268041
Merge branch 'master' into lars-dev
larshelge Dec 25, 2025
c746e81
fix: Update code
larshelge Dec 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/hisp/dhis/BaseDhis2.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public class BaseDhis2 {

protected final CloseableHttpClient httpClient;

/**
* Constructor.
*
* @param config the {@link Dhis2Config}.
*/
public BaseDhis2(Dhis2Config config) {
Objects.requireNonNull(config, "Config must be specified");
this.config = config;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/hisp/dhis/Dhis2.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.hisp.dhis.auth.AccessTokenAuthentication;
import org.hisp.dhis.auth.BasicAuthentication;
import org.hisp.dhis.auth.CookieAuthentication;
import org.hisp.dhis.auth.NoAuthentication;
import org.hisp.dhis.model.AnalyticsTableHook;
import org.hisp.dhis.model.Attribute;
import org.hisp.dhis.model.Category;
Expand Down Expand Up @@ -240,6 +241,17 @@ public static Dhis2 withCookieAuth(String url, String sessionId) {
return new Dhis2(new Dhis2Config(url, new CookieAuthentication(sessionId)));
}

/**
* Creates a {@link Dhis2} instance with no authentication.
*
* @param url the URL to the DHIS2 instance, do not include the {@code /api} part or a trailing
* {@code /}.
* @return a {@link Dhis2} instance.
*/
public static Dhis2 withoutAuth(String url) {
return new Dhis2(new Dhis2Config(url, new NoAuthentication()));
}

// -------------------------------------------------------------------------
// Log level
// -------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/hisp/dhis/auth/Authentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.hisp.dhis.auth;

import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;

/** Authentication interface. */
public interface Authentication extends Serializable {
Expand All @@ -44,4 +45,13 @@ public interface Authentication extends Serializable {
* @return the value of the HTTP header to use for authentication.
*/
String getHttpHeaderAuthValue();

/**
* Indicates whether authentication details are present.
*
* @return true if authentication details are present, false otherwise.
*/
default boolean hasAuth() {
return StringUtils.isNotEmpty(getHttpHeaderAuthName());
}
}
47 changes: 47 additions & 0 deletions src/main/java/org/hisp/dhis/auth/NoAuthentication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2004-2025, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.auth;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/** Class representing no authentication. */
@Getter
@RequiredArgsConstructor
public class NoAuthentication implements Authentication {
@Override
public String getHttpHeaderAuthName() {
return StringUtils.EMPTY;
}

@Override
public String getHttpHeaderAuthValue() {
return StringUtils.EMPTY;
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/hisp/dhis/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public static Date toDate(LocalDateTime dateTime) {
return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
}

/**
* Returns a {@link java.util.Date} from a {@link java.time.Instant}.
*
* @param instant the {@link java.time.Instant}.
* @return the {@link java.util.Date}.
*/
public static Date toDate(Instant instant) {
return Date.from(instant);
}

/**
* Returns a {@link java.util.Date} based on the given string. The string must be on the format
* <code>yyyy-MM-dd'T'HH:mm:ss.SSS</code>.
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/hisp/dhis/util/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public class HttpUtils {
*/
public static <T extends HttpUriRequestBase> T withAuth(T request, Dhis2Config config) {
Authentication auth = config.getAuthentication();
request.setHeader(auth.getHttpHeaderAuthName(), auth.getHttpHeaderAuthValue());

if (auth.hasAuth()) {
request.setHeader(auth.getHttpHeaderAuthName(), auth.getHttpHeaderAuthValue());
}

return request;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/hisp/dhis/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ void testWithCookieAuth() {
assertNotNull(dhis2);
}

@Test
void testWithAccessTokenAuth() {
Dhis2 dhis2 =
Dhis2.withAccessTokenAuth(
"https://play.dhis2.org/demo", "d2pat_2bBQecgNcxrS4EPhBJuRlQkwiLr2ATnC2557514242");
assertNotNull(dhis2);
}

@Test
void testWithoutAuth() {
Dhis2 dhis2 = Dhis2.withoutAuth("https://play.dhis2.org/demo");
assertNotNull(dhis2);
}
}
12 changes: 12 additions & 0 deletions src/test/java/org/hisp/dhis/util/HttpUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.hisp.dhis.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.net.URI;
import java.util.ArrayList;
Expand All @@ -39,6 +40,7 @@
import org.hisp.dhis.auth.AccessTokenAuthentication;
import org.hisp.dhis.auth.BasicAuthentication;
import org.hisp.dhis.auth.CookieAuthentication;
import org.hisp.dhis.auth.NoAuthentication;
import org.hisp.dhis.support.TestTags;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -102,6 +104,16 @@ void testWithCookieAuth() throws Exception {
assertEquals("JSESSIONID=KJH8KJ24fRD3FK491", post.getHeader(HttpHeaders.COOKIE).getValue());
}

@Test
void testWithoutAuth() throws Exception {
HttpPost post = new HttpPost(DEV_URL);

HttpUtils.withAuth(post, new Dhis2Config(DEV_URL, new NoAuthentication()));

assertNull(post.getHeader(HttpHeaders.AUTHORIZATION));
assertNull(post.getHeader(HttpHeaders.COOKIE));
}

@Test
void testGetBasicAuthString() {
assertEquals("Basic YWRtaW46ZGlzdHJpY3Q=", HttpUtils.getBasicAuthString("admin", "district"));
Expand Down
Loading