move auth chack to top of route handler
This commit is contained in:
parent
c60c4978df
commit
9fe298a899
1 changed files with 30 additions and 31 deletions
|
|
@ -49,21 +49,24 @@ public class SSHKeyResourceProvider implements RealmResourceProvider {
|
||||||
@Path("export/{group_id}")
|
@Path("export/{group_id}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response exportKeys(@PathParam("group_id") String groupId) {
|
public Response exportKeys(@PathParam("group_id") String groupId) {
|
||||||
|
try {
|
||||||
|
AuthHelper.getAuth(
|
||||||
|
session,
|
||||||
|
authResult -> authResult.getToken().getIssuedFor().equals("admin-cli"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println(e);
|
||||||
|
return Response.status(401, e.getMessage()).build();
|
||||||
|
}
|
||||||
|
|
||||||
UserProvider userProvider = session.users();
|
UserProvider userProvider = session.users();
|
||||||
UserProfileProvider profileProvider = session.getProvider(UserProfileProvider.class);
|
UserProfileProvider profileProvider = session.getProvider(UserProfileProvider.class);
|
||||||
UPConfig upconfig = profileProvider.getConfiguration();
|
UPConfig upconfig = profileProvider.getConfiguration();
|
||||||
|
|
||||||
List<String> attributeNames = upconfig.getAttributes()
|
List<String> attributeNames = upconfig.getAttributes()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(a -> a.getGroup() != null && a.getGroup().equals("de.ccc.hamburg.keycloak.ssh_key.keys"))
|
.filter(a -> a.getGroup() != null && a.getGroup().equals("de.ccc.hamburg.keycloak.ssh_key.keys"))
|
||||||
.map(a -> a.getName())
|
.map(a -> a.getName())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
try {
|
|
||||||
AuthHelper.getAuth(
|
|
||||||
session,
|
|
||||||
authResult -> authResult.getToken().getIssuedFor().equals("admin-cli"));
|
|
||||||
|
|
||||||
RealmModel realm = session.getContext().getRealm();
|
RealmModel realm = session.getContext().getRealm();
|
||||||
|
|
||||||
// TODO: add allowlist check
|
// TODO: add allowlist check
|
||||||
|
|
@ -89,10 +92,6 @@ public class SSHKeyResourceProvider implements RealmResourceProvider {
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return Response.ok(Map.of("keys", keys)).build();
|
return Response.ok(Map.of("keys", keys)).build();
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println(e);
|
|
||||||
return Response.status(401, e.getMessage()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue