微服务认证授权与监控实践
一、用户与角色授权
在理想情况下,认证服务需要一个持久化存储来保存用户、角色和应用的密钥。为了简化示例,我们在 helping-hands.auth.persistence
命名空间中创建一个内存数据库:
(ns helping-hands.auth.persistence
"Persistence Implementation for Auth Service"
(:require [agynamix.roles :as r]
[cheshire.core :as jp])
(:import [java.security MessageDigest]))
(defn get-hash
"Creates a MD5 hash of the password"
[creds]
(.. (MessageDigest/getInstance "MD5")
(digest (.getBytes creds "UTF-8"))))
(def userdb
;; Used ony for demonstration
;; TODO Persist in an external database
(atom
{:secret nil
:roles {"hh/superadmin" "*"
"hh/admin" "hh:*"
"hh/notify" #{"hh:notify" "notify/alert"}
"notify/alert"