|
@@ -1,31 +1,46 @@
|
|
|
package cn.com.qmth.markingaudit.service.impl;
|
|
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
|
|
|
|
+import cn.com.qmth.markingaudit.bean.AkInfo;
|
|
|
+import cn.com.qmth.markingaudit.service.MonitorService;
|
|
|
import cn.com.qmth.markingaudit.support.AccessInfo;
|
|
|
import cn.com.qmth.markingaudit.support.CustConstants;
|
|
|
-import cn.com.qmth.markingaudit.utils.MD5Util;
|
|
|
+import cn.com.qmth.markingaudit.utils.AuthorizationCreateUtil;
|
|
|
|
|
|
@Service
|
|
|
@AuthorizationComponent(prefix = { CustConstants.URI_PREFIX }, type = SignatureType.SECRET)
|
|
|
public class AuthServiceImpl implements AuthorizationService<AccessInfo> {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CaffeineCacheService caffeineCacheService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MonitorService monitorService;
|
|
|
+
|
|
|
@Override
|
|
|
public AccessInfo findByIdentity(String identity, SignatureType signatureType, String path) {
|
|
|
- try {
|
|
|
- StringBuilder temp = new StringBuilder(identity);
|
|
|
- temp.reverse();
|
|
|
- temp.append(CustConstants.QMTH);
|
|
|
- String secret = MD5Util.encoder(temp.toString());
|
|
|
- return new AccessInfo(identity, secret, identity);
|
|
|
- } catch (NoSuchAlgorithmException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ String secret = caffeineCacheService.get(identity);
|
|
|
+ if (secret == null) {
|
|
|
+ AkInfo ak = getAk(identity);
|
|
|
+ if (ak == null) {
|
|
|
+ throw new StatusException("未找到学校信息,code 错误");
|
|
|
+ }
|
|
|
+ secret = AuthorizationCreateUtil.buildApiSecret(ak.getAccessKey(), ak.getAccessSecret());
|
|
|
+ caffeineCacheService.set(identity, secret, 5, TimeUnit.MINUTES);
|
|
|
}
|
|
|
+ return new AccessInfo(identity, secret);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AkInfo getAk(String schoolCode) {
|
|
|
+ return monitorService.getAk(schoolCode);
|
|
|
}
|
|
|
}
|