Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Mall | 66,590 | 3 days ago | 35 | apache-2.0 | Java | |||||
mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。 | ||||||||||
Next Auth | 16,955 | 21 | 73 | 4 hours ago | 567 | August 01, 2022 | 241 | isc | TypeScript | |
Authentication for the Web. | ||||||||||
Auth Boss | 2,843 | 6 years ago | ||||||||
🔒 Become an Auth Boss. Learn about different authentication methodologies on the web. | ||||||||||
Vouch Proxy | 2,289 | a month ago | 157 | August 12, 2022 | 57 | mit | Go | |||
an SSO and OAuth / OIDC login solution for Nginx using the auth_request module | ||||||||||
Todoapi | 1,962 | 7 days ago | 5 | mit | C# | |||||
Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication | ||||||||||
Auth Module | 1,864 | 139 | 32 | 3 days ago | 51 | April 16, 2020 | 198 | mit | TypeScript | |
Zero-boilerplate authentication support for Nuxt.js! | ||||||||||
Loginsrv | 1,750 | 2 | 2 years ago | 7 | February 11, 2021 | 27 | mit | Go | ||
JWT login microservice with plugable backends such as OAuth2, Google, Github, htpasswd, osiam, .. | ||||||||||
His | 817 | a month ago | 29 | apache-2.0 | Java | |||||
HIS英文全称 hospital information system(医疗信息就诊系统),系统主要功能按照数据流量、流向及处理过程分为临床诊疗、药品管理、财务管理、患者管理。诊疗活动由各工作站配合完成,并将临床信息进行整理、处理、汇总、统计、分析等。本系统包括以下工作站:门诊医生工作站、药房医生工作站、医技医生工作站、收费员工作站、对帐员工作站、管理员工作站。需求为东软提供的云医院。 | ||||||||||
Fastify Jwt | 380 | 45 | 58 | 12 days ago | 47 | April 27, 2022 | 4 | mit | JavaScript | |
JWT utils for Fastify | ||||||||||
Supra Api Nodejs | 294 | 4 months ago | 7 | mit | JavaScript | |||||
❤️ Node.js REST API boilerplate |
Please note version 4 requires Dropwizard 2.
Statelessness is not only an architectural constaint of RESTful applications, it also comes with a lot of advantages regarding scalability and memory usage.
A common pattern is to provide the client with a signed JWT containing all necessary authorization and/or session state information. This JWT must then be passed along subsequent requests, usually in bearer Authorization HTTP headers.
However, in the particular case where clients of the RESTful application are web applications, it is much more interesting to use cookies. The browser will automatically read, store, send and expire the tokens, saving front-end developers the hassle of doing it themselves.
This dropwizard bundle makes things simple for back-end developpers too. It automatically serializes/deserializes session information into/from JWT cookies.
Add the dropwizard-jwt-cookie-authentication library as a dependency to your pom.xml
file:
<dependency>
<groupId>org.dhatim</groupId>
<artifactId>dropwizard-jwt-cookie-authentication</artifactId>
<version>4.5.0</version>
</dependency>
The default values are shown below. If they suit you, this step is optional.
jwtCookieAuth:
secretSeed: null
secure: false
httpOnly: true
domain: null
sameSite: null
sessionExpiryVolatile: PT30m
sessionExpiryPersistent: P7d
This step is also optional if you skipped the previous one.
@Valid
@NotNull
private JwtCookieAuthConfiguration jwtCookieAuth = new JwtCookieAuthConfiguration();
public JwtCookieAuthConfiguration getJwtCookieAuth() {
return jwtCookieAuth;
}
public void initialize(Bootstrap<MyApplicationConfiguration> bootstrap) {
bootstrap.addBundle(JwtCookieAuthBundle.getDefault());
}
If you have a custom configuration fot the bundle, specify it like so:
bootstrap.addBundle(JwtCookieAuthBundle.getDefault().withConfigurationSupplier(MyAppConfiguration::getJwtCookieAuth));
By default, the JWT cookie is serialized from / deserialized in an instance of DefaultJwtCookiePrincipal
.
When the user authenticate, you must put an instance of DefaultJwtCookiePrincipal
in the security context (which you can inject in your resources using the @Context
annotation) using JwtCookiePrincipal.addInContext
JwtCookiePrincipal principal = new DefaultJwtCookiePrincipal(name);
principal.addInContext(context);
Once a principal has been set, it can be retrieved using the @Auth
annotation in method signatures. You can also use CurrentPrincipal.get()
within the request thread.
Each time an API endpoint is called, a fresh cookie JWT is issued to reset the session TTL. You can use the @DontRefreshSession
on methods where this behavior is unwanted.
To specify a max age in the cookie (aka "remember me"), use DefaultJwtCookiePrincipal.setPersistent(true)
.
It is a stateless auhtentication method, so there is no real way to invalidate a session other than waiting for the JWT to expire. However calling JwtCookiePrincipal.removeFromContext(context)
will make browsers discard the cookie by setting the cookie expiration to a past date.
Principal roles can be specified via the DefaultJwtCookiePrincipal.setRoles(...)
method. You can then define fine grained access control using annotations such as @RolesAllowed
or @PermitAll
.
Additional custom data can be stored in the Principal using DefaultJwtCookiePrincipal.getClaims().put(key, value)
.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public DefaultJwtCookiePrincipal login(@Context ContainerRequestContext requestContext, String name){
DefaultJwtCookiePrincipal principal = new DefaultJwtCookiePrincipal(name);
principal.addInContext(requestContext);
return principal;
}
@GET
@Path("logout")
public void logout(@Context ContainerRequestContext requestContext){
JwtCookiePrincipal.removeFromContext(requestContext);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public DefaultJwtCookiePrincipal getPrincipal(@Auth DefaultJwtCookiePrincipal principal){
return principal;
}
@GET
@Path("idempotent")
@Produces(MediaType.APPLICATION_JSON)
@DontRefreshSession
public DefaultJwtCookiePrincipal getSubjectWithoutRefreshingSession(@Auth DefaultJwtCookiePrincipal principal){
return principal;
}
@GET
@Path("restricted")
@RolesAllowed("admin")
public String getRestrictedResource(){
return "SuperSecretStuff";
}
If you want to use your own Principal class instead of the DefaultJwtCookiePrincipal
, simply implement the interface JwtCookiePrincipal
and pass it to the bundle constructor along with functions to serialize it into / deserialize it from JWT claims.
e.g:
bootstrap.addBundle(new JwtCookieAuthBundle<>(MyCustomPrincipal.class, MyCustomPrincipal::toClaims, MyCustomPrincipal::new));
By default, the signing key is randomly generated on application startup. It means that users will have to re-authenticate after each server reboot.
To avoid this, you can specify a secretSeed
in the configuration. This seed will be used to generate the signing key, which will therefore be the same at each application startup.
Alternatively you can specify your own key factory:
bootstrap.addBundle(JwtCookieAuthBundle.getDefault().withKeyProvider((configuration, environment) -> {/*return your own key*/}));
If you need Chained Factories or Multiple Principals and Authenticators, don't register directly the bundle. Use instead its getAuthRequestFilter
and getAuthResponseFilter
methods to manually setup authentication.
You will also be responsible for generating the signing key and registering RolesAllowedDynamicFeature
or DontRefreshSessionFilter
if they are needed.
Example:
JwtCookieAuthBundle jwtCookieAuthBundle = new JwtCookieAuthBundle<>(
MyJwtCookiePrincipal.class,
MyJwtCookiePrincipal::toClaims,
MyJwtCookiePrincipal::new);
Key key = JwtCookieAuthBundle.generateKey(configuration.getJwtCookieAuth().getSecretSeed());
environment.jersey().register(
new PolymorphicAuthDynamicFeature<>(
ImmutableMap.of(
MyJwtCookiePrincipal.class, jwtCookieAuthBundle.getAuthRequestFilter(key),
MyBasicPrincipal.class, new BasicCredentialAuthFilter.Builder<MyBasicPrincipal>()
.setAuthenticator(new MyBasicAuthenticator())
.setRealm("SUPER SECRET STUFF")
.buildAuthFilter()
)
)
);
environment.jersey().register(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(MyJwtCookiePrincipal.class, MyBasicPrincipal.class)));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(DontRefreshSessionFilter.class);
environment.jersey().register(jwtCookieAuthBundle.getAuthResponseFilter(key, configuration.getJwtCookieAuth()));
It's here.