Get token & verify sign & save log into db


一. Login and get token.
     * parameters: ts, account, password
     * deal steps:
       1. check ts. ts is current time of your device, check time different between ts and current time of server is valid.
       2. check account and password. Can find user by account, then password should equal with account's  password.
       3. Generate token:  MD5.encode("account=christina&password=123456&ts=789327")
       4, return token
使用token的原因:用户可以跨应用.
三方登陆中需要code, 是为了不在url上面传递token的值,防止用户看到token的内容


二. Verify sign:
    验证签名, 是为了验证接入server的接入端的有效性(android/ios..). 与用户没有关系,与用户是否登陆无关.
   * parameters: ts, appKey, sign
   * deal steps:
     1. check ts
     2. get app by appKey
     3. check sign. generate sign , compare it with the parameter, whether they are equals.
     How to generate sign: 
                        String text = createLinkString(sArray) + appKye;
                        return MD5Encrypt.MD5Encode(text);

三. save log:
save log of api before deal it:
1. write a filter intercept all, and config it in web.xml:
    <filter>
<filter-name> logFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>logFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> logFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

2. you can choose some url that don't need to be intercepted:
    public class L ogFilter extends HttpServlet implements Filter {
          private final static List<String> excludePrameters = new ArrayList<String>();
           static {
            excludeURI.add("/abc");
          }
  }

3. What should be saved?
    url, method, parameter, userAgent, userId

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值