diff --git a/examples/auth/callout/java/AuthCalloutHandler.java b/examples/auth/callout/java/AuthCalloutHandler.java index 4b82d713..bccc5e4c 100644 --- a/examples/auth/callout/java/AuthCalloutHandler.java +++ b/examples/auth/callout/java/AuthCalloutHandler.java @@ -15,6 +15,34 @@ import static io.nats.jwt.Utils.getClaimBody; public class AuthCalloutHandler implements ServiceMessageHandler { + static String ISSUER_NSEED = "SAANDLKMXL6CUS3CP52WIXBEDN6YJ545GDKC65U5JZPPV6WH6ESWUA6YAI"; + + static final Map 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) { diff --git a/examples/auth/callout/java/Main.java b/examples/auth/callout/java/Main.java index 40ebc460..d5391f92 100644 --- a/examples/auth/callout/java/Main.java +++ b/examples/auth/callout/java/Main.java @@ -15,33 +15,6 @@ import static io.nats.jwt.Utils.getClaimBody; public class Main { - static String ISSUER_NSEED = "SAANDLKMXL6CUS3CP52WIXBEDN6YJ545GDKC65U5JZPPV6WH6ESWUA6YAI"; - - static final Map 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()