Commit 44cb7b19 authored by 马超's avatar 马超

doc: 修改filter文档

parent 2d53d093
# LDP 框架filter添加前端标识说明
表:ldp_uaa_app_client添加字段front_app_id
在LDP框架中,前端应用在访问后端接口时都需要经过网关应用,通过网关应用进行路由转发,网关拦截器中会校验前端token,如果token过期需要跳转到对应领域的登录地址,而不同的前端应用的`认证编码``应用Id`都不同。
添加脚本:V1.1.7__alter_ldp_uaa_app_client.sql
LDP 1.2.50版本前,我们需要在NACOS上的网关配置文件中添加或修改相应的参数,而应用越多维护就越困难,于是在LDP 1.2.50版本后,开发了直接在mcs中的认证应用中进行配置的功能,能够更加方便快捷的管理应用,同时也保留了配置文件的逻辑。
## 一、前端应用ID说明
## front_app_id说明:
前端应用ID是配置在前端脚手架中的ID值,在`.env.development ``.env.production`文件中,`VUE_APP_ID`所配置的值。在前端发起请求的时候会根据这个值获取到应用ID,也就是登录界面地址中的`clientid`
首先会根据yaml文件配置获取应用信息,如果取值为空则读取MCS配置的应用信息
当配置文件和mcs中都有相同前端应用的配置,会优先读取配置文件
应用ID可以根据以下两个配置获取:
## 二、配置方式
网关拦截器首先会根据yml文件配置获取应用信息,在nacos上打开` gateway-service-dev.yml`或者`gateway-service-prod.yml`文件,在route-apps中下添加一份配置,或者修改原有配置即可。
**配置文件样例**
1、service-geteway yaml 配置:
```yaml
uaa:
id: uaa-service
......@@ -42,88 +46,13 @@
```
2、mcs页面操作:
应用认证管理->应用列表->新增或修改,如图:
![image-20210318153920800](./images/frontAppId/frontAppId.png))
## 前端使用:
文件:.env.development 修改:VUE_APP_ID 就是对应的应用ID(front_app_id)
添加依赖包:
```xml
<dependency>
<groupId>com.sinra.ldp</groupId>
<artifactId>base-api</artifactId>
<version>${ldp.version}</version>
</dependency>
```
代码样例:
```java
/**
* service-uaa 添加接口 ,类:AppClientRest.java 根据frontAppId 获取信息
*
* @param frontAppId
* @return
*/
@GetMapping("/getByFrontAppId")
public List<LdpUaaAppClient> getByFrontAppId(String frontAppId) {
List<LdpUaaAppClient> ldpUaaAppClient = appClientService.getByFrontAppId(StringUtils.EMPTY,frontAppId);
return ldpUaaAppClient;
}
// Sql 脚本:
<query id="select_app_client_list_by_frontappid" author="machao" remark="通过frontappid获取UAA客户端信息" >
<sql>
<![CDATA[
SELECT
c.app_id,
c.front_app_id,
c.auth_realm
FROM
ldp_uaa_app_client c
JOIN ldp_uaa_auth_realm r ON c.auth_realm = r.id
WHERE
c.status=1
AND c.del_flag=0
AND c.front_app_id = :frontAppId #
]]>
</sql>
</query>
```
```java
/**
* 使用地方 LoginForwordFilter.java line 191 ~ 205
* @param tokenStr token字符
* @return
*/
RouteApp getRouteApp(String frontappId) {
RouteApp routeApp = ldpUaaProperties.getRouteApps().
stream().filter(appinfo -> (appinfo.getId() != null && frontappId.indexOf(appinfo.getId()) >= 0)).findFirst().get();
if (null == routeApp) {
ResponseEntity<Map> responseEntity = restTemplate.getForEntity("http://mcs-service/uaa/backend/client/getByFrontAppId?frontAppId=" + frontappId, Map.class);
System.out.println(responseEntity.getBody());
if (responseEntity.getStatusCode() == HttpStatus.OK
&& CommonConstants.SUCCESS.equals(responseEntity.getBody().get("code"))) {
if (null != responseEntity.getBody().get("data")) {
List list = (ArrayList) responseEntity.getBody().get("data");
LinkedHashMap<String, String> map = (LinkedHashMap) list.get(0);
routeApp.setId(map.get("frontAppId"));
routeApp.setRealmcode(map.get("authRealm"));
routeApp.setClientid(map.get("appId"));
}
}
}
return routeApp;
}
```
\ No newline at end of file
如果配置文件中不存在前端ID对应的配置信息,则会通过DB查询获取数据库中的配置,在mcs中,打开菜单`应用认证管理` -> `应用列表` -> `新增或修改`,将对应的前端应用ID配置到指定的应用上。
**MCS配置样例**
![image-20210318153920800](./images/frontAppId/frontAppId.png)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment