com.github.achatain:java-webapp-authentication

Authentication framework leveraging Google sign-in for servlet based Java webapps

Лицензия

Лицензия

Категории

Категории

Java Языки программирования
Группа

Группа

com.github.achatain
Идентификатор

Идентификатор

java-webapp-authentication
Последняя версия

Последняя версия

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

com.github.achatain:java-webapp-authentication
Authentication framework leveraging Google sign-in for servlet based Java webapps
Ссылка на сайт

Ссылка на сайт

https://github.com/achatain/java-webapp-authentication
Система контроля версий

Система контроля версий

http://github.com/achatain/java-webapp-authentication/tree/master

Скачать java-webapp-authentication

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.achatain/java-webapp-authentication/ -->
<dependency>
    <groupId>com.github.achatain</groupId>
    <artifactId>java-webapp-authentication</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.achatain/java-webapp-authentication/
implementation 'com.github.achatain:java-webapp-authentication:1.1.0'
// https://jarcasting.com/artifacts/com.github.achatain/java-webapp-authentication/
implementation ("com.github.achatain:java-webapp-authentication:1.1.0")
'com.github.achatain:java-webapp-authentication:jar:1.1.0'
<dependency org="com.github.achatain" name="java-webapp-authentication" rev="1.1.0">
  <artifact name="java-webapp-authentication" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.achatain', module='java-webapp-authentication', version='1.1.0')
)
libraryDependencies += "com.github.achatain" % "java-webapp-authentication" % "1.1.0"
[com.github.achatain/java-webapp-authentication "1.1.0"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
javax.servlet : javax.servlet-api jar 3.1.0
com.google.inject : guice jar 4.1.0
com.google.inject.extensions : guice-servlet jar 4.1.0
com.google.code.gson : gson jar 2.8.0
com.google.api-client : google-api-client jar 1.22.0

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.mockito : mockito-core jar 2.2.21
org.hamcrest : hamcrest-junit jar 2.0.0.0

Модули Проекта

Данный проект не имеет модулей.

java-webapp-authentication

Build Status Coverage Status Maven Central

https://github.com/achatain/java-webapp-authentication

#What is it? JWA (Java Webapp Authentication) assists in leveraging Google Sign-In for backend server applications built with Java. Despite being in its early days, JWA provides you with a bunch of robust and easy to use features:

  • authentication filter
  • sign-in and sign-out servlets
  • session management service
  • etc.

#How do I integrate it in my backend app?

  1. Add the dependency in your pom file
<dependency>
 <groupId>com.github.achatain</groupId>
 <artifactId>java-webapp-authentication</artifactId>
 <version>1.1.0</version>
</dependency>
  1. Install the AuthenticationModule to enable the dependency injection (suggested to use Google Guice)
 class AppConfig extends GuiceServletContextListener {
   @Override
   protected Injector getInjector() {
     return Guice.createInjector(
       new AuthenticationModule()
     );
   }
 }
  1. Filter your restricted API through the SessionFilter and serve the sign-in and sign-out servlets
 class AppServletModule extends ServletModule {
   @Override
   protected void configureServlets() {
     Map<String, String> initParams = new HashMap<>();
     initParams.put(SessionFilter.LOGIN_URL_REDIRECT, "https://myapp.com/google-sign-in/");
     filter("/api/*").through(SessionFilter.class, initParams);
     serve("/google-auth").with(GoogleSigninServlet.class);
     serve("/signout").with(SignOutServlet.class);
   }
 }

#How do I know who is logged-in? From any servlet filtered through the SessionFilter, you can get the current user thanks to the SessionService

public class MyServlet extends HttpServlet {

   private final transient SessionService sessionService;

   @Inject
   private MyServlet(final SessionService sessionService) {
       this.sessionService = sessionService;
   }

   @Override
   protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
       AuthenticatedUser user = sessionService.getUserFromSession(req.getSession());
       System.out.println("The logged-in user is " + user);
   }
}

Версии библиотеки

Версия
1.1.0
1.0.1
1.0.0