Search in sources :

Example 1 with WebSecurity

use of io.helidon.security.integration.webserver.WebSecurity in project helidon by oracle.

the class GoogleBuilderMain method start.

static int start(int port) {
    Security security = Security.builder().addProvider(GoogleTokenProvider.builder().clientId("your-client-id.apps.googleusercontent.com")).build();
    WebSecurity ws = WebSecurity.create(security);
    Routing.Builder routing = Routing.builder().register(ws).get("/rest/profile", WebSecurity.authenticate(), (req, res) -> {
        Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
        res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
        res.send("Response from builder based service, you are: \n" + securityContext.flatMap(SecurityContext::user).map(Subject::toString).orElse("Security context is null"));
        req.next();
    }).register(StaticContentSupport.create("/WEB"));
    theServer = GoogleUtil.startIt(port, routing);
    return theServer.port();
}
Also used : Security(io.helidon.security.Security) StaticContentSupport(io.helidon.webserver.staticcontent.StaticContentSupport) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) SecurityContext(io.helidon.security.SecurityContext) Subject(io.helidon.security.Subject) GoogleTokenProvider(io.helidon.security.providers.google.login.GoogleTokenProvider) Routing(io.helidon.webserver.Routing) MediaType(io.helidon.common.http.MediaType) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing) Security(io.helidon.security.Security) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) Subject(io.helidon.security.Subject)

Aggregations

MediaType (io.helidon.common.http.MediaType)1 Security (io.helidon.security.Security)1 SecurityContext (io.helidon.security.SecurityContext)1 Subject (io.helidon.security.Subject)1 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)1 GoogleTokenProvider (io.helidon.security.providers.google.login.GoogleTokenProvider)1 Routing (io.helidon.webserver.Routing)1 WebServer (io.helidon.webserver.WebServer)1 StaticContentSupport (io.helidon.webserver.staticcontent.StaticContentSupport)1 Optional (java.util.Optional)1