use of io.vertx.ext.auth.AuthProvider in project vertx-auth by vert-x3.
the class AuthJWTExamples method example8.
public void example8(Vertx vertx) {
JWTAuthOptions config = new JWTAuthOptions().addPubSecKey(new PubSecKeyOptions().setAlgorithm("RS256").setPublicKey("BASE64-ENCODED-PUBLIC_KEY"));
AuthProvider provider = JWTAuth.create(vertx, config);
}
use of io.vertx.ext.auth.AuthProvider in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// quick load of test data, this is a *sync* helper not intended for
// real deployments...
setUpInitialData("jdbc:hsqldb:mem:test?shutdown=true");
// Create a JDBC client with a test database
JDBCClient client = JDBCClient.createShared(vertx, new JsonObject().put("url", "jdbc:hsqldb:mem:test?shutdown=true").put("driver_class", "org.hsqldb.jdbcDriver"));
// If you are planning NOT to build a fat jar, then use the BoneCP pool since it
// can handle loading the jdbc driver classes from outside vert.x lib directory
// JDBCClient client = JDBCClient.createShared(vertx, new JsonObject()
// .put("provider_class", "io.vertx.ext.jdbc.spi.impl.BoneCPDataSourceProvider")
// .put("jdbcUrl", "jdbc:hsqldb:mem:test?shutdown=true")
// .put("username", "sa")
// .put("password", ""));
Router router = Router.router(vertx);
// We need cookies, sessions and request bodies
router.route().handler(CookieHandler.create());
router.route().handler(BodyHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
// Simple auth service which uses a JDBC data source
AuthProvider authProvider = JDBCAuth.create(vertx, client);
// We need a user session handler too to make sure the user is stored in the session between requests
router.route().handler(UserSessionHandler.create(authProvider));
// Any requests to URI starting '/private/' require login
router.route("/private/*").handler(RedirectAuthHandler.create(authProvider, "/loginpage.html"));
// Serve the static private pages from directory 'private'
router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"));
// Handles the actual login
router.route("/loginhandler").handler(FormLoginHandler.create(authProvider));
// Implement logout
router.route("/logout").handler(context -> {
context.clearUser();
// Redirect back to the index page
context.response().putHeader("location", "/").setStatusCode(302).end();
});
// Serve the non private static pages
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router).listen(8080);
}
use of io.vertx.ext.auth.AuthProvider in project vertx-web by vert-x3.
the class ChainAuthHandlerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, authConfig);
// create a chain
chain = ChainAuthHandler.create();
chain.append(JWTAuthHandler.create(null)).append(BasicAuthHandler.create(authProvider)).append(RedirectAuthHandler.create(authProvider));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(chain);
router.route().handler(ctx -> ctx.response().end());
}
use of io.vertx.ext.auth.AuthProvider in project vertx-web by vert-x3.
the class EventbusBridgeTest method testSendRequiresAuthorityHasAuthority.
@Test
public void testSendRequiresAuthorityHasAuthority() throws Exception {
sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")));
router.clear();
router.route().handler(CookieHandler.create());
SessionStore store = LocalSessionStore.create(vertx);
router.route().handler(SessionHandler.create(store));
JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, authConfig);
addLoginHandler(router, authProvider);
router.route("/eventbus/*").handler(sockJSHandler);
testSend("foo");
}
use of io.vertx.ext.auth.AuthProvider in project vertx-web by vert-x3.
the class EventbusBridgeTest method testSendRequiresAuthorityHasnotAuthority.
@Test
public void testSendRequiresAuthorityHasnotAuthority() throws Exception {
sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose")));
router.clear();
router.route().handler(CookieHandler.create());
SessionStore store = LocalSessionStore.create(vertx);
router.route().handler(SessionHandler.create(store));
JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, authConfig);
addLoginHandler(router, authProvider);
router.route("/eventbus/*").handler(sockJSHandler);
testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied");
}
Aggregations