Skip to content

Commit 9dbaafe

Browse files
author
Olivier Chédru
authored
Upgrade to Dropwizard 4 (#91)
1 parent be62fbb commit 9dbaafe

File tree

14 files changed

+114
-76
lines changed

14 files changed

+114
-76
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/setup-java@v3
1414
with:
1515
distribution: 'zulu'
16-
java-version: '8'
16+
java-version: '11'
1717
- name: maven build
1818
env:
1919
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Javadoc](https://www.javadoc.io/badge/org.dhatim/dropwizard-jwt-cookie-authentication.svg)](http://www.javadoc.io/doc/org.dhatim/dropwizard-jwt-cookie-authentication)
55
[![Mentioned in Awesome Dropwizard](https://awesome.re/mentioned-badge.svg)](https://github.com/stve/awesome-dropwizard)
66

7-
**Please note version 4 requires Dropwizard 2.**
7+
**Please note version 5 requires Java 11 and Dropwizard 4.**
88

99
# dropwizard-jwt-cookie-authentication
1010

@@ -26,7 +26,7 @@ Add the dropwizard-jwt-cookie-authentication library as a dependency to your `po
2626
<dependency>
2727
<groupId>org.dhatim</groupId>
2828
<artifactId>dropwizard-jwt-cookie-authentication</artifactId>
29-
<version>4.5.0</version>
29+
<version>5.0.0</version>
3030
</dependency>
3131
```
3232

pom.xml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>org.dhatim</groupId>
@@ -25,15 +26,15 @@
2526
</developers>
2627
<scm>
2728
<connection>scm:git:[email protected]:dhatim/dropwizard-jwt-cookie-authentication.git</connection>
28-
<developerConnection>scm:git:[email protected]:dhatim/dropwizard-jwt-cookie-authentication.git</developerConnection>
29+
<developerConnection>scm:git:[email protected]:dhatim/dropwizard-jwt-cookie-authentication.git
30+
</developerConnection>
2931
<url>[email protected]:dhatim/dropwizard-jwt-cookie-authentication.git</url>
3032
</scm>
3133
<properties>
3234
<java.source>1.8</java.source>
3335
<maven.compiler.source>1.8</maven.compiler.source>
3436
<maven.compiler.target>1.8</maven.compiler.target>
3537
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36-
<dropwizard.version>2.1.6</dropwizard.version>
3738
<jjwt.version>0.11.5</jjwt.version>
3839
<enforcer.fail>false</enforcer.fail>
3940
</properties>
@@ -56,16 +57,30 @@
5657
</snapshots>
5758
</repository>
5859
</repositories>
60+
<dependencyManagement>
61+
<dependencies>
62+
<dependency>
63+
<groupId>io.dropwizard</groupId>
64+
<artifactId>dropwizard-bom</artifactId>
65+
<version>4.0.0</version>
66+
<type>pom</type>
67+
<scope>import</scope>
68+
</dependency>
69+
</dependencies>
70+
</dependencyManagement>
5971
<dependencies>
72+
<dependency>
73+
<groupId>jakarta.annotation</groupId>
74+
<artifactId>jakarta.annotation-api</artifactId>
75+
<version>2.1.1</version>
76+
</dependency>
6077
<dependency>
6178
<groupId>io.dropwizard</groupId>
6279
<artifactId>dropwizard-core</artifactId>
63-
<version>${dropwizard.version}</version>
6480
</dependency>
6581
<dependency>
6682
<groupId>io.dropwizard</groupId>
6783
<artifactId>dropwizard-auth</artifactId>
68-
<version>${dropwizard.version}</version>
6984
</dependency>
7085
<dependency>
7186
<groupId>io.jsonwebtoken</groupId>
@@ -84,17 +99,21 @@
8499
</dependency>
85100
<dependency>
86101
<groupId>org.junit.jupiter</groupId>
87-
<artifactId>junit-jupiter-engine</artifactId>
102+
<artifactId>junit-jupiter-api</artifactId>
88103
<version>5.9.3</version>
89104
<scope>test</scope>
90105
</dependency>
91106
<dependency>
92107
<groupId>io.dropwizard</groupId>
93108
<artifactId>dropwizard-testing</artifactId>
94-
<version>${dropwizard.version}</version>
95109
<scope>test</scope>
96110
</dependency>
97-
</dependencies>
111+
<dependency>
112+
<groupId>io.dropwizard</groupId>
113+
<artifactId>dropwizard-client</artifactId>
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
98117
<build>
99118
<plugins>
100119
<plugin>

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/DontRefreshSession.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2023 Dhatim
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
66
* the License at
7-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1212
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -15,11 +15,12 @@
1515
*/
1616
package org.dhatim.dropwizard.jwt.cookie.authentication;
1717

18-
import java.lang.annotation.Retention;
18+
import jakarta.ws.rs.NameBinding;
19+
1920
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
2022
import java.lang.annotation.RetentionPolicy;
2123
import java.lang.annotation.Target;
22-
import javax.ws.rs.NameBinding;
2324

2425
/**
2526
* An annotation that can be used to avoid reseting the session TTL when an API is called

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/DontRefreshSessionFilter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2023 Dhatim
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
66
* the License at
7-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1212
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -15,12 +15,13 @@
1515
*/
1616
package org.dhatim.dropwizard.jwt.cookie.authentication;
1717

18+
import jakarta.ws.rs.container.ContainerRequestContext;
19+
import jakarta.ws.rs.container.ContainerRequestFilter;
20+
1821
import java.io.IOException;
19-
import javax.ws.rs.container.ContainerRequestContext;
20-
import javax.ws.rs.container.ContainerRequestFilter;
2122

2223
@DontRefreshSession
23-
public class DontRefreshSessionFilter implements ContainerRequestFilter{
24+
public class DontRefreshSessionFilter implements ContainerRequestFilter {
2425

2526
public static String DONT_REFRESH_SESSION_PROPERTY = "dontRefreshSession";
2627

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/JwtCookieAuthBundle.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@
1818
import com.fasterxml.jackson.databind.module.SimpleModule;
1919
import com.google.common.hash.Hashing;
2020
import com.google.common.primitives.Ints;
21-
import io.dropwizard.Configuration;
22-
import io.dropwizard.ConfiguredBundle;
23-
import io.dropwizard.auth.AuthDynamicFeature;
24-
import io.dropwizard.auth.AuthFilter;
25-
import io.dropwizard.auth.AuthValueFactoryProvider;
26-
import io.dropwizard.auth.Authorizer;
27-
import io.dropwizard.auth.DefaultUnauthorizedHandler;
28-
import io.dropwizard.auth.UnauthorizedHandler;
21+
import io.dropwizard.auth.*;
22+
import io.dropwizard.core.Configuration;
23+
import io.dropwizard.core.ConfiguredBundle;
24+
import io.dropwizard.core.setup.Bootstrap;
25+
import io.dropwizard.core.setup.Environment;
2926
import io.dropwizard.jersey.setup.JerseyEnvironment;
30-
import io.dropwizard.setup.Bootstrap;
31-
import io.dropwizard.setup.Environment;
3227
import io.jsonwebtoken.Claims;
3328
import io.jsonwebtoken.SignatureAlgorithm;
3429
import io.jsonwebtoken.impl.DefaultClaims;
30+
import jakarta.ws.rs.container.ContainerResponseFilter;
3531
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
3632

3733
import javax.crypto.KeyGenerator;
3834
import javax.crypto.spec.SecretKeySpec;
39-
import javax.ws.rs.container.ContainerResponseFilter;
4035
import java.nio.charset.StandardCharsets;
4136
import java.security.Key;
4237
import java.security.NoSuchAlgorithmException;
@@ -161,7 +156,7 @@ public AuthFilter<String, P> getAuthRequestFilter(Key key, String cookieName) {
161156
.setCookieName(cookieName)
162157
.setAuthenticator(new JwtCookiePrincipalAuthenticator(key, deserializer))
163158
.setPrefix(JWT_COOKIE_PREFIX)
164-
.setAuthorizer((Authorizer<P>) (P::isInRole))
159+
.setAuthorizer((Authorizer<P>) (principal, role, requestContext) -> principal.isInRole(role))
165160
.setUnauthorizedHandler(unauthorizedHandler)
166161
.buildAuthFilter();
167162
}

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/JwtCookieAuthConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package org.dhatim.dropwizard.jwt.cookie.authentication;
1717

18-
import javax.annotation.Nullable;
19-
import javax.validation.constraints.NotEmpty;
18+
import jakarta.annotation.Nullable;
19+
import jakarta.validation.constraints.NotEmpty;
2020

2121
import static org.dhatim.dropwizard.jwt.cookie.authentication.JwtCookieAuthBundle.JWT_COOKIE_DEFAULT_NAME;
2222

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/JwtCookieAuthRequestFilter.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2023 Dhatim
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
66
* the License at
7-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1212
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,14 +17,15 @@
1717

1818
import io.dropwizard.auth.AuthFilter;
1919
import io.dropwizard.auth.AuthenticationException;
20+
import jakarta.annotation.Priority;
21+
import jakarta.ws.rs.InternalServerErrorException;
22+
import jakarta.ws.rs.Priorities;
23+
import jakarta.ws.rs.container.ContainerRequestContext;
24+
import jakarta.ws.rs.core.Cookie;
25+
2026
import java.io.IOException;
2127
import java.util.Objects;
2228
import java.util.Optional;
23-
import javax.annotation.Priority;
24-
import javax.ws.rs.InternalServerErrorException;
25-
import javax.ws.rs.Priorities;
26-
import javax.ws.rs.container.ContainerRequestContext;
27-
import javax.ws.rs.core.Cookie;
2829

2930
@Priority(Priorities.AUTHENTICATION)
3031
class JwtCookieAuthRequestFilter<P extends JwtCookiePrincipal> extends AuthFilter<String, P> {
@@ -66,7 +67,7 @@ public Builder setCookieName(String cookieName) {
6667
}
6768

6869
@Override
69-
protected JwtCookieAuthRequestFilter<P> newInstance() {
70+
protected JwtCookieAuthRequestFilter<P> newInstance() {
7071
return new JwtCookieAuthRequestFilter(Objects.requireNonNull(cookieName, "cookieName is not set"));
7172
}
7273
}

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/JwtCookieAuthResponseFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import io.jsonwebtoken.Claims;
1919
import io.jsonwebtoken.Jwts;
2020
import io.jsonwebtoken.SignatureAlgorithm;
21+
import jakarta.ws.rs.container.ContainerRequestContext;
22+
import jakarta.ws.rs.container.ContainerResponseContext;
23+
import jakarta.ws.rs.container.ContainerResponseFilter;
2124

22-
import javax.ws.rs.container.ContainerRequestContext;
23-
import javax.ws.rs.container.ContainerResponseContext;
24-
import javax.ws.rs.container.ContainerResponseFilter;
2525
import java.io.IOException;
2626
import java.security.Key;
2727
import java.security.Principal;

src/main/java/org/dhatim/dropwizard/jwt/cookie/authentication/JwtCookiePrincipal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package org.dhatim.dropwizard.jwt.cookie.authentication;
1717

18+
import jakarta.ws.rs.container.ContainerRequestContext;
19+
import org.checkerframework.checker.nullness.qual.Nullable;
20+
1821
import java.security.Principal;
19-
import javax.ws.rs.container.ContainerRequestContext;
2022

2123
/**
2224
* A principal persisted in JWT cookies

0 commit comments

Comments
 (0)