/** * Filter the request. * <p> * An implementation may modify the state of the request or * create a new instance. * * @param request the request. * @return the request. */ @Override public ContainerRequest filter(ContainerRequest request) { try { this.authenticateByHttpRequest.authenticate(request); } catch (Exception exception) { LOGGER.error("Authentication Failure. Exception:", exception); throw new AuthenticationException("Authentication failure."); } return request; } }
bind(String.class).annotatedWith(named("authentication.scheme")) .toInstance(getProperty("authentication.scheme", properties)); bind(String.class).annotatedWith(named("authentication.token.scheme")) .toInstance(getProperty("authentication.token.scheme", properties)); bind(String.class).annotatedWith(named("authentication.token.salt")) .toInstance(getProperty("authentication.token.salt", properties)); bind(String.class).annotatedWith(named("authentication.token.version")) .toInstance(getProperty("authentication.token.version", properties)); bind(String.class).annotatedWith(named("authentication.http.proxy.host")) .toInstance(getProperty("http.proxy.host", properties)); bind(Integer.class).annotatedWith(named("authentication.http.proxy.port")) .toInstance(Integer.parseInt(getProperty("http.proxy.port", properties, "80"))); Class<Authentication> authImplClass = (Class<Authentication>) forName(authenticationClassName); bind(Authentication.class).to(authImplClass).in(SINGLETON); bind(AuthenticateByHttpRequest.class).to(NoOpAuthenticateByHttpRequestImpl.class).asEagerSingleton(); } catch (ClassNotFoundException e) { LOGGER.error("unable to find class: {}", authenticationClassName, e);
/** * Log out user * * @param tokenHeader * @return Response object */ @GET @Path("/logout") @Produces(APPLICATION_JSON) @ApiOperation(value = "Log a user out") @Timed public Response logUserOut( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { authentication.logOut(tokenHeader); return httpHeader.headers(NO_CONTENT).build(); } catch (Exception exception) { LOGGER.error("logUserOut failed with error:", exception); throw exception; } }
return httpHeader.headers().entity(authentication.getUserExists(userEmail)).build(); } catch (Exception exception) { LOGGER.error("getUserExists failed for userEmail={} with error:", userEmail, exception);
/** * Verify token * * @param tokenHeader * @return Response object */ @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } }
@Override protected void configure() { LOGGER.debug("installing module: {}", AuthorizationModule.class.getSimpleName()); install(new AuthenticationModule()); install(new EventLogModule()); install(new CassandraRepositoryModule()); Properties properties = create(PROPERTY_NAME, AuthorizationModule.class); String authorizationClassName = getProperty("authorization.class.name", properties, "com.intuit.wasabi.authorization.impl.DefaultAuthorization"); try { @SuppressWarnings("unchecked") Class<Authorization> authorizationClass = (Class<Authorization>) forName(authorizationClassName); bind(Authorization.class).to(authorizationClass).in(SINGLETON); } catch (ClassNotFoundException e) { throw new AuthenticationException("unable to find authorization class: " + authorizationClassName, e); } LOGGER.debug("installed module: {}", AuthorizationModule.class.getSimpleName()); } }
return httpHeader.headers().entity(authentication.logIn(authorizationHeader)).build(); } catch (Exception exception) { LOGGER.error("logUserIn failed for grantType={} with error:", grantType, exception);