We just need to refer to MaJiaSSO's core package, then create a unified authentication center as a user, and call the loginSuccess method provided by TokenHelper. class after the authentication has passed. In addition, users can customize the encrypted salt to ensure security, and can also carry some user-defined information.
我们只需要去引用MaJiaSSO的核心包,然后作为用户去创建一个统一的认证中心,当认证通过过后去调用TokenHelper类提供的loginSuccess方法。另外用户可以自定义加密盐保证安全,也可以携带用户自定义的一些信息。
The second step is simply to integrate MaJiaSSO in the service. There is only one step we need to do: add an interceptor to intercept all requests and set the encryption salt (which must be consistent with the first step). If some requests do not require authentication, the annotation @NoToken can be added to the method. Users can obtain the information after authentication through (SSOUser) request. getparameter ("ssoUser"); so that they can easily get the ID and other information in the program.
第二步就仅仅是在服务中集成MaJiaSSO。我们需要做的只有一步:添加一个拦截器拦截所有请求,并且可以设置加密盐(必须和第一步一致)。某些请求不需要认证那么可以在方法上添加注解@NoToken,用户可以通过(SSOUser)request.getparameter("ssoUser");去获取想要的信息。
The core of MaJiaSSO design is simple, safe, practical and efficient.
作为一个用户,集成到项目中只需要两个步骤,这比其他框架简单。
采用实用的JWT作为令牌生产模式,保证了有效的验证和用户自定义的加密盐,保证了令牌的安全性和不可侵犯性。
在不依赖任何存储的情况下,JWT可以随时随地对信息进行加密和集成。
HOW TO USE MAJIASSO IN YOUR PROJECT!
groupId:com.majiaxueyuan artifactId:sso-core version:latestversion
数据库密码验证成功后,调用以下代码获取令牌。 TokenLoginHelper.loginSuccess(user.getId, user.getUserName, jsonInfo, "mjsso-salt")
普通服务只需要添加一个拦截器拦截所有请求并且设置盐就新。 @Configuration public class MaJiaSsoConfig extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(ssoIntercepter()).addPathPatterns("/**"); } @Bean public MaJiaSSOIntercepter ssoIntercepter() { return new MaJiaSSOIntercepter().setTokenSalt("mjsso-salt"); } }
定用户获取到Token之后,返回给前端,前端携带时需要将Token添加到Header中的Authorization字段。 当前强制使用此请求头字段
当有某个请求不需要认证即可访问时,在此请求方法上添加注解@NoToken
恭喜你,MaJiaSSO框架集成完毕,在你的项目中即将开启使用最轻量级、最简单易用、最安全的SSO系统。 期待更多MaJia系列开源框架诞生!
我们需要你提供更多的在使用中的不方便的地方,对此框架有任何意见或者建议的话。以及你想未来使用MaJia系列的哪些框架。请将这些信息在开源页面以留言或者issue的方式提交给我们,你的每一条建议都是我们前进的动力!
Gitee CodeSource 码家学院官网