Skip to content

Commit

Permalink
Java Auth Callout Example - working the compile 4
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf committed Jan 9, 2024
1 parent a49207d commit 8fa5c4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
28 changes: 28 additions & 0 deletions examples/auth/callout/java/AuthCalloutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@
import static io.nats.jwt.Utils.getClaimBody;

public class AuthCalloutHandler implements ServiceMessageHandler {
static String ISSUER_NSEED = "SAANDLKMXL6CUS3CP52WIXBEDN6YJ545GDKC65U5JZPPV6WH6ESWUA6YAI";

static final Map<String, AuthCalloutUser> NATS_USERS;

static final NKey USER_SIGNING_KEY;
static final String PUB_USER_SIGNING_KEY;

static {
try {
USER_SIGNING_KEY = NKey.fromSeed(ISSUER_NSEED.toCharArray());
PUB_USER_SIGNING_KEY = new String(USER_SIGNING_KEY.getPublicKey());
}
catch (Exception e) {
throw new RuntimeException(e);
}

// This sets up a map of users to simulate a back end auth system
// sys/sys, SYS
// alice/alice, APP
// bob/bob, APP, pub allow "bob.>", sub allow "bob.>", response max 1
NATS_USERS = new HashMap<>();
NATS_USERS.put("sys", new AuthCalloutUser().userPass("sys").account("SYS"));
NATS_USERS.put("alice", new AuthCalloutUser().userPass("alice").account("APP"));
Permission p = new Permission().allow("bob.>");
ResponsePermission r = new ResponsePermission().max(1);
NATS_USERS.put("bob", new AuthCalloutUser().userPass("bob").account("APP").pub(p).sub(p).resp(r));
}

Connection nc;

public AuthCalloutHandler(Connection nc) {
Expand Down
27 changes: 0 additions & 27 deletions examples/auth/callout/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@
import static io.nats.jwt.Utils.getClaimBody;

public class Main {
static String ISSUER_NSEED = "SAANDLKMXL6CUS3CP52WIXBEDN6YJ545GDKC65U5JZPPV6WH6ESWUA6YAI";

static final Map<String, AuthCalloutUser> NATS_USERS;

static final NKey USER_SIGNING_KEY;
static final String PUB_USER_SIGNING_KEY;

static {
try {
USER_SIGNING_KEY = NKey.fromSeed(ISSUER_NSEED.toCharArray());
PUB_USER_SIGNING_KEY = new String(USER_SIGNING_KEY.getPublicKey());
}
catch (Exception e) {
throw new RuntimeException(e);
}

// This sets up a map of users to simulate a back end auth system
// sys/sys, SYS
// alice/alice, APP
// bob/bob, APP, pub allow "bob.>", sub allow "bob.>", response max 1
NATS_USERS = new HashMap<>();
NATS_USERS.put("sys", new AuthCalloutUser().userPass("sys").account("SYS"));
NATS_USERS.put("alice", new AuthCalloutUser().userPass("alice").account("APP"));
Permission p = new Permission().allow("bob.>");
ResponsePermission r = new ResponsePermission().max(1);
NATS_USERS.put("bob", new AuthCalloutUser().userPass("bob").account("APP").pub(p).sub(p).resp(r));
}

public static void main(String[] args) throws Exception {
Options options = new Options.Builder()
Expand Down

0 comments on commit 8fa5c4b

Please sign in to comment.