(13) App_key and secret stored in database or Redis __ Database

Source: Internet
Author: User
Tags redis

Here is a redis example

Create a new Redisappsecretmanager class to implement the Appsecretmanager interface

/** * How to use: * * <pre> @Autowired private Appsecretmanager Appsecretmanager; 
    @Override protected void Initapiconfig (Apiconfig apiconfig) {... apiconfig.setappsecretmanager (appsecretmanager);   

 ...
}

    * </pre> * * @author TANGHC * */@Component public class Redisappsecretmanager implements Appsecretmanager {

    public static String App_key_prefix = "Easyopen_app_key:";


    @Autowired private Stringredistemplate stringredistemplate; @Override public void Addappsecret (map<string, string> appsecretstore) {Stringredistemplate.opsforhash (
    ). Putall (App_key_prefix, Appsecretstore); @Override public string Getsecret (string AppKey) {return (string) Stringredistemplate.opsforhash (). Get (
    App_key_prefix, AppKey); 
        @Override public boolean Isvalidappkey (String appKey) {if (AppKey = = null) {return false;
    } return Getsecret (appKey)! = NULL; }

}

Storing App_key and secret in the form of hash set, so the view in Redis is more convenient, at a glance.

Then in the Indexcontroller:

@Autowired
private Appsecretmanager Appsecretmanager;

@Override
protected void Initapiconfig (Apiconfig apiconfig) {
    ...
    Apiconfig.setappsecretmanager (Appsecretmanager);
    ...
}   
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.