Skip to content

Commit 5fe09e4

Browse files
author
Jérôme LELEU
committed
Upgrade to pac4j v1.9.1
1 parent fcfa124 commit 5fe09e4

22 files changed

Lines changed: 163 additions & 134 deletions

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/AuthCallback.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import org.pac4j.core.context.Pac4jConstants;
3838
import org.pac4j.core.context.WebContext;
3939
import org.pac4j.core.credentials.Credentials;
40-
import org.pac4j.core.exception.RequiresHttpAction;
41-
import org.pac4j.core.profile.UserProfile;
40+
import org.pac4j.core.exception.HttpAction;
41+
import org.pac4j.core.profile.CommonProfile;
4242
import org.slf4j.Logger;
4343
import org.slf4j.LoggerFactory;
4444

@@ -79,7 +79,7 @@ public void handle(final Request req, final Response rsp, final Chain chain) thr
7979
log.debug("credentials : {}", credentials);
8080

8181
// get user profile
82-
final UserProfile profile = client.getUserProfile(credentials, ctx);
82+
final CommonProfile profile = client.getUserProfile(credentials, ctx);
8383
log.debug("profile : {}", profile);
8484

8585
Session session = req.session();
@@ -99,7 +99,7 @@ public void handle(final Request req, final Response rsp, final Chain chain) thr
9999
});
100100
log.info("redirecting to: {}", requestedUrl);
101101
rsp.redirect(requestedUrl);
102-
} catch (final RequiresHttpAction ex) {
102+
} catch (final HttpAction ex) {
103103
new AuthResponse(rsp).handle(client, ex);
104104
}
105105
}

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/AuthFilter.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
import org.jooby.pac4j.Auth;
3232
import org.jooby.pac4j.AuthStore;
3333
import org.pac4j.core.client.Client;
34-
import org.pac4j.core.client.ClientFinder;
3534
import org.pac4j.core.client.Clients;
3635
import org.pac4j.core.client.DirectClient;
3736
import org.pac4j.core.client.IndirectClient;
37+
import org.pac4j.core.client.finder.ClientFinder;
3838
import org.pac4j.core.context.Pac4jConstants;
3939
import org.pac4j.core.context.WebContext;
4040
import org.pac4j.core.credentials.Credentials;
41-
import org.pac4j.core.exception.RequiresHttpAction;
41+
import org.pac4j.core.exception.HttpAction;
4242
import org.pac4j.core.exception.TechnicalException;
43-
import org.pac4j.core.profile.UserProfile;
43+
import org.pac4j.core.profile.CommonProfile;
4444
import org.slf4j.Logger;
4545
import org.slf4j.LoggerFactory;
4646

@@ -56,10 +56,10 @@ public class AuthFilter implements Route.Handler {
5656

5757
private String clientName;
5858

59-
private Class<? extends UserProfile> profileType;
59+
private Class<? extends CommonProfile> profileType;
6060

6161
public AuthFilter(final Class<? extends Client<?, ?>> clientType,
62-
final Class<? extends UserProfile> profileType) {
62+
final Class<? extends CommonProfile> profileType) {
6363
this.clientName = clientType.getSimpleName();
6464
this.profileType = requireNonNull(profileType, "ProfileType is required.");
6565
}
@@ -81,12 +81,12 @@ public void handle(final Request req, final Response rsp) throws Throwable {
8181

8282
WebContext ctx = req.require(WebContext.class);
8383
ClientFinder finder = req.require(ClientFinder.class);
84-
AuthStore<UserProfile> store = req.require(AuthStore.class);
84+
AuthStore<CommonProfile> store = req.require(AuthStore.class);
8585

8686
// stateless or previously authenticated stateful
87-
UserProfile profile = find(finder, clients, ctx, null, clientName, client -> {
87+
CommonProfile profile = find(finder, clients, ctx, null, clientName, client -> {
8888
String profileId = profileID(useSession.test(client), req);
89-
UserProfile identity = profileId == null ? null : store.get(profileId).orElse(null);
89+
CommonProfile identity = profileId == null ? null : store.get(profileId).orElse(null);
9090

9191
if (identity == null) {
9292
if (client instanceof DirectClient) {
@@ -101,7 +101,7 @@ public void handle(final Request req, final Response rsp) throws Throwable {
101101
req.set(Auth.CNAME, client.getName());
102102
store.set(identity);
103103
}
104-
} catch (RequiresHttpAction e) {
104+
} catch (HttpAction e) {
105105
throw new TechnicalException("Unexpected HTTP action", e);
106106
}
107107
}
@@ -118,9 +118,9 @@ public void handle(final Request req, final Response rsp) throws Throwable {
118118
final String requestedUrl = ctx.getFullRequestURL();
119119
log.debug("requestedUrl: {}", requestedUrl);
120120
ctx.setSessionAttribute(Pac4jConstants.REQUESTED_URL, requestedUrl);
121-
client.redirect(ctx, true);
121+
client.redirect(ctx);
122122
rsp.end();
123-
} catch (RequiresHttpAction ex) {
123+
} catch (HttpAction ex) {
124124
new AuthResponse(rsp).handle(client, ex);
125125
}
126126
return Boolean.TRUE;

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/AuthLogout.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.jooby.Session;
2929
import org.jooby.pac4j.Auth;
3030
import org.jooby.pac4j.AuthStore;
31-
import org.pac4j.core.profile.UserProfile;
31+
import org.pac4j.core.profile.CommonProfile;
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

@@ -51,7 +51,7 @@ public void handle(final Request req, final Response rsp) throws Throwable {
5151
if (ifSession.isPresent()) {
5252
Optional<String> profileId = ifSession.get().unset(Auth.ID).toOptional();
5353
if (profileId.isPresent()) {
54-
Optional<UserProfile> profile = req.require(AuthStore.class).unset(profileId.get());
54+
Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get());
5555
log.debug("logout {}", profile);
5656
}
5757
} else {

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/AuthResponse.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.jooby.Err;
2222
import org.jooby.Response;
2323
import org.pac4j.core.client.Client;
24-
import org.pac4j.core.exception.RequiresHttpAction;
24+
import org.pac4j.core.exception.HttpAction;
2525
import org.pac4j.http.client.indirect.IndirectBasicAuthClient;
2626

2727
public class AuthResponse {
@@ -32,7 +32,7 @@ public AuthResponse(final Response rsp) {
3232
this.rsp = rsp;
3333
}
3434

35-
public void handle(final Client<?, ?> client, final RequiresHttpAction action) {
35+
public void handle(final Client<?, ?> client, final HttpAction action) {
3636
if (!rsp.committed()) {
3737
int statusCode = action.getCode();
3838
// on error, let jooby handle it

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/AuthorizerFilter.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020

2121
import static java.util.Objects.requireNonNull;
2222

23+
import java.util.Arrays;
2324
import java.util.Map;
2425

2526
import org.jooby.Err;
2627
import org.jooby.Request;
2728
import org.jooby.Response;
2829
import org.jooby.Route;
2930
import org.jooby.Status;
30-
import org.pac4j.core.authorization.AuthorizationChecker;
31-
import org.pac4j.core.authorization.Authorizer;
31+
import org.pac4j.core.authorization.authorizer.Authorizer;
32+
import org.pac4j.core.authorization.checker.AuthorizationChecker;
3233
import org.pac4j.core.config.Config;
3334
import org.pac4j.core.context.WebContext;
34-
import org.pac4j.core.profile.UserProfile;
35+
import org.pac4j.core.profile.CommonProfile;
3536
import org.slf4j.Logger;
3637
import org.slf4j.LoggerFactory;
3738

@@ -49,13 +50,13 @@ public AuthorizerFilter(final String authorizer) {
4950
@SuppressWarnings("rawtypes")
5051
@Override
5152
public void handle(final Request req, final Response rsp) throws Exception {
52-
UserProfile user = req.require(UserProfile.class);
53+
CommonProfile user = req.require(CommonProfile.class);
5354
Config config = req.require(Config.class);
5455
WebContext ctx = req.require(WebContext.class);
5556
AuthorizationChecker authorizationChecker = req.require(AuthorizationChecker.class);
5657
Map<String, Authorizer> authorizers = config.getAuthorizers();
5758
log.debug("checking access for: {}", user);
58-
if (!authorizationChecker.isAuthorized(ctx, user, this.authorizer, authorizers)) {
59+
if (!authorizationChecker.isAuthorized(ctx, Arrays.asList(user), this.authorizer, authorizers)) {
5960
log.debug("forbidden: {}", user);
6061
throw new Err(Status.FORBIDDEN);
6162
}

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/BasicAuth.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import javax.inject.Inject;
2222

23+
import org.pac4j.core.credentials.authenticator.UsernamePasswordAuthenticator;
2324
import org.pac4j.http.client.indirect.IndirectBasicAuthClient;
24-
import org.pac4j.http.credentials.authenticator.UsernamePasswordAuthenticator;
2525

2626
public class BasicAuth extends ClientProvider<IndirectBasicAuthClient> {
2727

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/ClientType.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
import java.lang.reflect.ParameterizedType;
2222
import java.lang.reflect.Type;
2323

24-
import org.pac4j.core.profile.UserProfile;
24+
import org.pac4j.core.profile.CommonProfile;
2525

2626
public class ClientType {
2727

2828
@SuppressWarnings("unchecked")
29-
public static Class<? extends UserProfile> typeOf(final Class<?> client) {
29+
public static Class<? extends CommonProfile> typeOf(final Class<?> client) {
3030
Type genericType = client.getGenericSuperclass();
3131
if (genericType instanceof ParameterizedType) {
3232
Type[] types = ((ParameterizedType) genericType).getActualTypeArguments();
3333
for (Type type : types) {
34-
if (UserProfile.class.isAssignableFrom((Class<?>) type)) {
35-
return (Class<? extends UserProfile>) type;
34+
if (CommonProfile.class.isAssignableFrom((Class<?>) type)) {
35+
return (Class<? extends CommonProfile>) type;
3636
}
3737
}
3838
}
39-
return UserProfile.class;
39+
return CommonProfile.class;
4040
}
4141

4242
}

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/ConfigProvider.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import javax.inject.Inject;
2525
import javax.inject.Provider;
2626

27-
import org.pac4j.core.authorization.Authorizer;
27+
import org.pac4j.core.authorization.authorizer.Authorizer;
2828
import org.pac4j.core.client.Clients;
2929
import org.pac4j.core.config.Config;
3030

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/FormAuth.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import javax.inject.Inject;
2222
import javax.inject.Named;
2323

24+
import org.pac4j.core.credentials.authenticator.UsernamePasswordAuthenticator;
2425
import org.pac4j.http.client.indirect.FormClient;
25-
import org.pac4j.http.credentials.authenticator.UsernamePasswordAuthenticator;
2626

2727
public class FormAuth extends ClientProvider<FormClient> {
2828

‎jooby-pac4j/src/main/java/org/jooby/internal/pac4j/FormFilter.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.jooby.Request;
2525
import org.jooby.Response;
2626
import org.jooby.Route.Chain;
27+
import org.pac4j.core.profile.CommonProfile;
2728
import org.pac4j.http.client.indirect.FormClient;
28-
import org.pac4j.http.profile.HttpProfile;
2929

3030
public class FormFilter extends AuthFilter {
3131

@@ -74,7 +74,7 @@ public class FormFilter extends AuthFilter {
7474
private String callback;
7575

7676
public FormFilter(final String loginUrl, final String callback) {
77-
super(FormClient.class, HttpProfile.class);
77+
super(FormClient.class, CommonProfile.class);
7878
this.loginUrl = loginUrl;
7979
this.callback = URI.create(callback).getPath() + "?client_name=FormClient";
8080
}

0 commit comments

Comments
 (0)