@Before public void setup() throws Exception { JsonObject authConfig = new JsonObject().put("keyStore", new JsonObject() .put("type", "jceks") .put("path", "keystore.jceks") .put("password", "secret")); authProvider = JWTAuth.create(vertx, new JWTAuthOptions(authConfig)); }
static String generate(final JsonObject claims, final JWTOptions options, final Function<String, Buffer> funcBuffer) { final JsonObject opts = readOptions(); final JWTAuthOptions meta = Fn.getNull(new JWTAuthOptions(), () -> new JWTAuthOptions(opts), opts); return Fn.getNull(() -> { final JsonObject _claims = claims.copy(); if (options.getPermissions() != null && !_claims.containsKey(meta.getPermissionsClaimKey())) { _claims.put(meta.getPermissionsClaimKey(), new JsonArray(options.getPermissions())); } final JWT reference = create(meta, funcBuffer); return reference.sign(_claims, options); }, meta, claims); }
@Test public void testValidateTokenWithInvalidMacSecret() { String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MDE3ODUyMDZ9.08K_rROcCmKTF1cKfPCli2GQFYIOP8dePxeS1SE4dc8"; authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("a bad secret")) ); JsonObject authInfo = new JsonObject().put("jwt", token); authProvider.authenticate(authInfo, onFailure(res -> { assertNotNull(res); testComplete(); })); await(); }
private JWTAuthOptions getConfig() { return new JWTAuthOptions() .setKeyStore(new KeyStoreOptions() .setPath("keystore.jceks") .setType("jceks") .setPassword("secret")); }
@Test public void testJWKShouldNotCrash() { authProvider = JWTAuth.create(vertx, new JWTAuthOptions().addJwk( new JsonObject() .put("kty", "RSA") .put("n", "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw") .put("e", "AQAB") .put("alg", "RS256") .put("kid", "2011-04-29"))); } }
private static JWT createDirect(final JWTAuthOptions config, final Function<String, Buffer> funcBuffer) { final JWT reference; final KeyStoreOptions keyStore = config.getKeyStore(); } else { reference = new JWT(); final List<PubSecKeyOptions> keys = config.getPubSecKeys(); if (keys != null) { final Iterator var25 = config.getPubSecKeys().iterator(); final List<SecretOptions> secrets = config.getSecrets(); if (secrets != null) { final Iterator var28 = secrets.iterator();
public JwtAuthProvider(final Vertx vertx, final JWTAuthOptions config, final Function<JsonObject, Future<Boolean>> executor) { this.executor = executor; this.permissionsClaimKey = config.getPermissionsClaimKey(); this.jwtOptions = config.getJWTOptions(); // File reading here. this.jwt = Ux.Jwt.create(config, vertx.fileSystem()::readFileBlocking); vertx.sharedData().<String, Boolean>getAsyncMap(AUTH_POOL, res -> { if (res.succeeded()) { LOGGER.debug(Info.MAP_INITED, AUTH_POOL); this.authorizeMap = res.result(); } }); }
@Test public void testValidateTokenWithValidMacSecret() { String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MDE3ODUyMDZ9.08K_rROcCmKTF1cKfPCli2GQFYIOP8dePxeS1SE4dc8"; authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret")) ); JsonObject authInfo = new JsonObject().put("jwt", token); authProvider.authenticate(authInfo, onSuccess(res -> { assertNotNull(res); testComplete(); })); await(); }
@Test public void testGenerateNewTokenES256() { authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .setKeyStore(new KeyStoreOptions() .setPath("es256-keystore.jceks") .setPassword("secret"))); String token = authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions().setAlgorithm("ES256")); assertNotNull(token); JsonObject authInfo = new JsonObject() .put("jwt", token); authProvider.authenticate(authInfo, res -> { if (res.failed()) { res.cause().printStackTrace(); fail(); } assertNotNull(res.result()); testComplete(); }); await(); }
static String generate(final JsonObject claims, final JWTOptions options, final Function<String, Buffer> funcBuffer) { final JsonObject opts = readOptions(); final JWTAuthOptions meta = Fn.getNull(new JWTAuthOptions(), () -> new JWTAuthOptions(opts), opts); return Fn.getNull(() -> { final JsonObject _claims = claims.copy(); if (options.getPermissions() != null && !_claims.containsKey(meta.getPermissionsClaimKey())) { _claims.put(meta.getPermissionsClaimKey(), new JsonArray(options.getPermissions())); } final JWT reference = create(meta, funcBuffer); return reference.sign(_claims, options); }, meta, claims); }
private static JWT createDirect(final JWTAuthOptions config, final Function<String, Buffer> funcBuffer) { final JWT reference; final KeyStoreOptions keyStore = config.getKeyStore(); } else { reference = new JWT(); final List<PubSecKeyOptions> keys = config.getPubSecKeys(); if (keys != null) { final Iterator var25 = config.getPubSecKeys().iterator(); final List<SecretOptions> secrets = config.getSecrets(); if (secrets != null) { final Iterator var28 = secrets.iterator();
public JwtAuthProvider(final Vertx vertx, final JWTAuthOptions config, final Function<JsonObject, Future<Boolean>> executor) { this.executor = executor; this.permissionsClaimKey = config.getPermissionsClaimKey(); this.jwtOptions = config.getJWTOptions(); // File reading here. this.jwt = Ux.Jwt.create(config, vertx.fileSystem()::readFileBlocking); vertx.sharedData().<String, Boolean>getAsyncMap(AUTH_POOL, res -> { if (res.succeeded()) { LOGGER.debug(Info.MAP_INITED, AUTH_POOL); this.authorizeMap = res.result(); } }); }
public static JWT create(final JsonObject config, final Function<String, Buffer> funcBuffer) { return UxJwt.create(new JWTAuthOptions(config), funcBuffer); } }
@Test public void testGenerateNewTokenWithMacSecret() { authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret")) ); String token = authProvider.generateToken(new JsonObject(), new JWTOptions().setAlgorithm("HS256")); assertNotNull(token); // reverse JsonObject authInfo = new JsonObject().put("jwt", token); authProvider.authenticate(authInfo, onSuccess(res -> { assertNotNull(res); testComplete(); })); await(); }
@Test public void testGenerateNewTokenForceAlgorithm() { authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .setKeyStore(new KeyStoreOptions() .setPath("gce.jks") .setType("jks") .setPassword("notasecret"))); String token = authProvider.generateToken(new JsonObject(), new JWTOptions().setAlgorithm("RS256")); assertNotNull(token); // reverse JsonObject authInfo = new JsonObject().put("jwt", token); authProvider.authenticate(authInfo, onSuccess(res -> { assertNotNull(res); testComplete(); })); await(); }
public static JWT create(final JsonObject config) { return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer); }
@Override public void setUp() throws Exception { super.setUp(); OKService service = new OKServiceImpl(); ServiceBinder serviceBinder = new ServiceBinder(vertx) .setAddress(SERVICE_ADDRESS) .addInterceptor(new ServiceJWTInterceptor().setJwtAuth(JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret"))))); ServiceBinder localServiceBinder = new ServiceBinder(vertx) .setAddress(SERVICE_LOCAL_ADDRESS) .addInterceptor(new ServiceJWTInterceptor().setJwtAuth(JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret"))))); consumer = serviceBinder.register(OKService.class, service); localConsumer = localServiceBinder.registerLocal(OKService.class, service); serviceProxyBuilder = new ServiceProxyBuilder(vertx) .setAddress(SERVICE_ADDRESS); localServiceProxyBuilder = new ServiceProxyBuilder(vertx) .setAddress(SERVICE_LOCAL_ADDRESS); }
public static JWT create(final JsonObject config, final Function<String, Buffer> funcBuffer) { return UxJwt.create(new JWTAuthOptions(config), funcBuffer); } }
public static JWT create(final JWTAuthOptions config) { return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer); }
public static JWT create(final JWTAuthOptions config) { return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer); }