private boolean isUrlFromAuthenticationResources( final String url ) { return authenticationEndpoints.getErrorPage().equals( url ) || authenticationEndpoints.getLoginPage().equals( url ); } }
@Override public boolean sendAuthenticationChallenge(HttpServerExchange exchange, Session session) { final String newLocation = isCurrentRequestTryingToAuthenticate(exchange) ? authenticationEndpoints.getErrorPage() : authenticationEndpoints.getLoginPage(); Redirect.to(exchange, newLocation); return true; }
@Override public void handleRequest( HttpServerExchange exchange ) throws Exception { final SecurityContext securityContext = (SecurityContext)exchange.getSecurityContext(); if ( securityContext == null ) { exchange.setStatusCode( StatusCodes.INTERNAL_SERVER_ERROR ); exchange.getResponseSender().send( NOT_LOGGED_IN ); } else { securityContext.logout(); if ( Methods.GET.equals( exchange.getRequestMethod() ) ) Redirect.to( exchange, authenticationEndpoints.getLoginPage() ); else exchange.endExchange(); } } }
@Override public void load( Builder server, DeploymentContext context ) throws IOException { final boolean defaultEnabledState = config.getBoolean( "server.smart-routes.auth.enabled" ); if ( !isEmpty( authenticationEndpoints.getLoginPage() ) && config.getBoolean( "server.smart-routes.auth.login-form-enabled", defaultEnabledState ) ) context.register( authenticationEndpoints.getLoginPage(), "GET", loginHttpHandler ); if ( !isEmpty( authenticationEndpoints.getLogoutUrl() ) && config.getBoolean( "server.smart-routes.auth.logout-url-enabled", defaultEnabledState ) ) { context.register( authenticationEndpoints.getLogoutUrl(), authenticationEndpoints.getLogoutUrlMethod(), logoutHttpHandler ); } if ( !isEmpty( authenticationEndpoints.getCallbackUrl() ) && config.getBoolean( "server.smart-routes.auth.callback-url-enabled", defaultEnabledState )) { context.register( authenticationEndpoints.getCallbackUrl(), authenticationEndpoints.getCallbackUrlMethod(), authCallbackVerificationHttpHandler ); } }