MaxKey 3 years ago
parent
commit
742b660453

+ 1 - 1
gradle.properties

@@ -15,7 +15,7 @@
 # */
 #maxkey properties 
 group                           =maxkey.top
-version                         =3.4.0
+version                         =3.5.0
 vendor                          =https://www.maxkey.top
 author                          =MaxKeyTop
 

+ 20 - 0
maxkey-core/src/main/java/org/maxkey/entity/SocialsAssociate.java

@@ -44,6 +44,9 @@ public class SocialsAssociate extends JpaBaseEntity {
 	private String id;
 	@Column
 	private String provider;
+	private String providerName;
+	private String icon;
+	
 	@Column
 	private String userId;
 	@Column
@@ -157,6 +160,23 @@ public class SocialsAssociate extends JpaBaseEntity {
 		this.instId = instId;
 	}
 
+	
+	public String getProviderName() {
+		return providerName;
+	}
+
+	public void setProviderName(String providerName) {
+		this.providerName = providerName;
+	}
+
+	public String getIcon() {
+		return icon;
+	}
+
+	public void setIcon(String icon) {
+		this.icon = icon;
+	}
+
 	@Override
     public String toString() {
         StringBuilder builder = new StringBuilder();

+ 1 - 1
maxkey-gataway/src/main/resources/application.yml

@@ -1,7 +1,7 @@
 #端口号
 application:
   name: maxkey-gateway-server
-  formatted-version: v3.4.0 GA
+  formatted-version: v3.5.0 GA
 server:
   port: 9000
 spring:

+ 1 - 1
maxkey-monitor/src/main/resources/application.properties

@@ -18,7 +18,7 @@
 application.title                               =MaxKey
 #for dynamic service discovery
 spring.application.name                         =maxkey-monitor
-application.formatted-version                   =v3.4.0 GA
+application.formatted-version                   =v3.5.0 GA
 #nacos discovery
 spring.cloud.nacos.discovery.enabled            =${NACOS_DISCOVERY_ENABLED:false}
 spring.cloud.nacos.discovery.instance-enabled   =false

+ 4 - 0
maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/SocialsAssociateMapper.java

@@ -16,9 +16,13 @@
  
 
 package org.maxkey.persistence.mapper;
+import java.util.List;
+
 import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
 import org.maxkey.entity.SocialsAssociate;
+import org.maxkey.entity.UserInfo;
 
 public interface SocialsAssociateMapper extends IJpaBaseMapper<SocialsAssociate> {
 
+	public List<SocialsAssociate> queryByUser(UserInfo user);
 }

+ 7 - 0
maxkey-persistence/src/main/java/org/maxkey/persistence/service/SocialsAssociatesService.java

@@ -17,8 +17,11 @@
 
 package org.maxkey.persistence.service;
 
+import java.util.List;
+
 import org.apache.mybatis.jpa.persistence.JpaBaseService;
 import org.maxkey.entity.SocialsAssociate;
+import org.maxkey.entity.UserInfo;
 import org.maxkey.persistence.mapper.SocialsAssociateMapper;
 import org.springframework.stereotype.Repository;
 
@@ -38,5 +41,9 @@ public class SocialsAssociatesService  extends JpaBaseService<SocialsAssociate>{
 		return (SocialsAssociateMapper)super.getMapper();
 	}
  
+	
+	public List<SocialsAssociate>  queryByUser(UserInfo user) {
+		return getMapper().queryByUser(user);
+	}
 	 
 }

+ 31 - 0
maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/SocialsAssociateMapper.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.maxkey.persistence.mapper.SocialsAssociateMapper">
+
+		
+	<select id="queryByUser" parameterType="UserInfo" resultType="SocialsAssociate">
+		select
+            p.provider,
+            p.providerName,
+            p.icon,
+            a.id,
+			a.userid,
+			a.username,
+			a.createdDate,
+			a.updatedDate
+		from
+            mxk_socials_provider p
+		left join
+            mxk_socials_associate a 
+            
+		on  a.provider = p.provider and a.userid = #{id}   
+		
+		where
+            a.instid   =   p.instid
+			and  a.instid   =   #{instId} 	
+			and  p.status =1
+		order by  p.sortindex
+	</select>
+
+	
+</mapper>

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyMvcConfig.java

@@ -146,7 +146,7 @@ public class MaxKeyMvcConfig implements WebMvcConfigurer {
                 .addPathPatterns("/logs/**")
                 .addPathPatterns("/userinfo/**")
                 .addPathPatterns("/profile/**")
-                .addPathPatterns("/safe/**")
+                .addPathPatterns("/config/**")
                 .addPathPatterns("/historys/**")
                 .addPathPatterns("/access/session/**")
                 .addPathPatterns("/access/session/**/**")

+ 40 - 104
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/OneTimePasswordController.java

@@ -18,26 +18,29 @@
 package org.maxkey.web.contorller;
 
 import java.awt.image.BufferedImage;
-import java.util.UUID;
+import java.util.Base64;
+import java.util.HashMap;
 import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.lang3.StringUtils;
+import org.maxkey.authn.annotation.CurrentUser;
 import org.maxkey.crypto.Base32Utils;
 import org.maxkey.crypto.password.PasswordReciprocal;
+import org.maxkey.entity.Message;
 import org.maxkey.entity.UserInfo;
 import org.maxkey.password.onetimepwd.algorithm.OtpKeyUriFormat;
 import org.maxkey.password.onetimepwd.algorithm.OtpSecret;
 import org.maxkey.persistence.service.UserInfoService;
 import org.maxkey.util.RQCodeUtils;
-import org.maxkey.web.WebContext;
 import org.maxkey.web.image.ImageEndpoint;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.servlet.ModelAndView;
-
-import com.xkcoding.http.util.StringUtil;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 
 
 /**
@@ -46,7 +49,7 @@ import com.xkcoding.http.util.StringUtil;
  *
  */
 @Controller
-@RequestMapping(value  =  { "/safe/otp" })
+@RequestMapping(value  =  { "/config" })
 public class OneTimePasswordController {
     static final  Logger _logger  =  LoggerFactory.getLogger(OneTimePasswordController.class);
 
@@ -58,115 +61,48 @@ public class OneTimePasswordController {
     @Qualifier("otpKeyUriFormat")
     OtpKeyUriFormat otpKeyUriFormat;
 
-    @Autowired
-    @Qualifier("passwordReciprocal")
-    PasswordReciprocal passwordReciprocal;
-
     @RequestMapping(value = {"/timebased"})
-    public ModelAndView timebased() {
-        ModelAndView modelAndView = new ModelAndView("safe/timeBased");
-        UserInfo userInfo = WebContext.getUserInfo();
+    @ResponseBody
+    public ResponseEntity<?> timebased(@RequestParam String generate,@CurrentUser UserInfo currentUser) {
+        HashMap<String,Object >timebased =new HashMap<String,Object >();
+        
+        generate(generate,currentUser);
+        
+        String sharedSecret = 
+        		PasswordReciprocal.getInstance().decoder(currentUser.getSharedSecret());
         
-        String sharedSecret = userInfo.getId();
-        if(StringUtil.isNotEmpty(userInfo.getSharedSecret())) {
-        	passwordReciprocal.decoder(userInfo.getSharedSecret());
-        }
-        otpKeyUriFormat.setSecret(sharedSecret);
-        String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
-        byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
-        String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
-        modelAndView.addObject("id", genRqCode(otpauth));
-        modelAndView.addObject("userInfo", userInfo);
-        modelAndView.addObject("format", otpKeyUriFormat);
-        modelAndView.addObject("sharedSecret", sharedSecret);
-        modelAndView.addObject("hexSharedSecret", hexSharedSecret);
-        return modelAndView;
-    }
-
-    @RequestMapping(value = {"gen/timebased"})
-    public ModelAndView gentimebased() {
-        UserInfo userInfo = WebContext.getUserInfo();
-        byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
-        String sharedSecret = Base32Utils.encode(byteSharedSecret);
-        sharedSecret = passwordReciprocal.encode(sharedSecret);
-        userInfo.setSharedSecret(sharedSecret);
-        userInfoService.updateSharedSecret(userInfo);
-        WebContext.setUserInfo(userInfo);
-        return WebContext.redirect("/safe/otp/timebased");
-    }
-
-
-    @RequestMapping(value = {"/counterbased"})
-    public ModelAndView counterbased() {
-        ModelAndView modelAndView = new ModelAndView("safe/counterBased");
-        UserInfo userInfo = WebContext.getUserInfo();
-        String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
-        otpKeyUriFormat.setSecret(sharedSecret);
-        otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
-        String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
-
-        byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
-        String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
-        modelAndView.addObject("id", genRqCode(otpauth));
-        modelAndView.addObject("userInfo", userInfo);
-        modelAndView.addObject("format", otpKeyUriFormat);
-        modelAndView.addObject("sharedSecret", sharedSecret);
-        modelAndView.addObject("hexSharedSecret", hexSharedSecret);
-        return modelAndView;
-
-    }
-
-    @RequestMapping(value = {"gen/counterbased"})
-    public ModelAndView gencounterbased() {
-        UserInfo userInfo = WebContext.getUserInfo();
-        byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
-        String sharedSecret = Base32Utils.encode(byteSharedSecret);
-        sharedSecret = passwordReciprocal.encode(sharedSecret);
-        userInfo.setSharedSecret(sharedSecret);
-        userInfo.setSharedCounter("0");
-        userInfoService.updateSharedSecret(userInfo);
-        WebContext.setUserInfo(userInfo);
-        return WebContext.redirect("/safe/otp/counterbased");
-    }
-
-    @RequestMapping(value = {"/hotp"})
-    public ModelAndView hotp() {
-        ModelAndView modelAndView = new ModelAndView("safe/hotp");
-        UserInfo userInfo = WebContext.getUserInfo();
-        String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
         otpKeyUriFormat.setSecret(sharedSecret);
-        otpKeyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
-        String otpauth = otpKeyUriFormat.format(userInfo.getUsername());
+        String otpauth = otpKeyUriFormat.format(currentUser.getUsername());
         byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
         String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
-        modelAndView.addObject("id", genRqCode(otpauth));
-        modelAndView.addObject("userInfo", userInfo);
-        modelAndView.addObject("format", otpKeyUriFormat);
-        modelAndView.addObject("sharedSecret", sharedSecret);
-        modelAndView.addObject("hexSharedSecret", hexSharedSecret);
-        return modelAndView;
-
+        
+        timebased.put("displayName", currentUser.getDisplayName());
+        timebased.put("username", currentUser.getUsername());
+        timebased.put("digits", otpKeyUriFormat.getDigits());
+        timebased.put("period", otpKeyUriFormat.getPeriod());
+        timebased.put("sharedSecret", sharedSecret);
+        timebased.put("hexSharedSecret", hexSharedSecret);
+        timebased.put("rqCode", genRqCode(otpauth));
+        return new Message<HashMap<String,Object >>(timebased).buildResponse();
     }
 
-    @RequestMapping(value = {"gen/hotp"})
-    public ModelAndView genhotp() {
-        UserInfo userInfo = WebContext.getUserInfo();
-        byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
-        String sharedSecret = Base32Utils.encode(byteSharedSecret);
-        sharedSecret = passwordReciprocal.encode(sharedSecret);
-        userInfo.setSharedSecret(sharedSecret);
-        userInfo.setSharedCounter("0");
-        userInfoService.updateSharedSecret(userInfo);
-        WebContext.setUserInfo(userInfo);
-        return WebContext.redirect("/safe/otp/hotp");
+    public void generate(String generate,@CurrentUser UserInfo currentUser) {
+    	if((StringUtils.isNotBlank(generate)
+        		&& generate.equalsIgnoreCase("YES"))
+        		||StringUtils.isBlank(currentUser.getSharedSecret())) {
+    		
+        	byte[] byteSharedSecret = OtpSecret.generate(otpKeyUriFormat.getCrypto());
+            String sharedSecret = Base32Utils.encode(byteSharedSecret);
+            sharedSecret = PasswordReciprocal.getInstance().encode(sharedSecret);
+            currentUser.setSharedSecret(sharedSecret);
+            userInfoService.updateSharedSecret(currentUser);
+            
+        }
     }
 
-
     public  String genRqCode(String otpauth) {
         BufferedImage bufferedImage  =  RQCodeUtils.write2BufferedImage(otpauth, "gif", 300, 300);
         byte[] imageByte = ImageEndpoint.bufferedImage2Byte(bufferedImage);
-        String uuid = UUID.randomUUID().toString().toLowerCase();
-        WebContext.getSession().setAttribute(uuid, imageByte);
-        return uuid;
+        return "data:image/png;base64," + Base64.getEncoder().encodeToString(imageByte);
     }
 }

+ 14 - 51
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SocialSignOnListController.java

@@ -17,76 +17,39 @@
 
 package org.maxkey.web.contorller;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
-import org.maxkey.authn.support.socialsignon.service.SocialsAssociateService;
-import org.maxkey.configuration.ApplicationConfig;
-import org.maxkey.entity.Institutions;
+import org.maxkey.authn.annotation.CurrentUser;
+import org.maxkey.entity.Message;
 import org.maxkey.entity.SocialsAssociate;
-import org.maxkey.entity.SocialsProvider;
-import org.maxkey.web.WebConstants;
-import org.maxkey.web.WebContext;
+import org.maxkey.entity.UserInfo;
+import org.maxkey.persistence.service.SocialsAssociatesService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.bind.annotation.ResponseBody;
 
 
 @Controller
-@RequestMapping(value={"/socialsignon"})
+@RequestMapping(value={"/config/socialsignon"})
 public class SocialSignOnListController {
 	final static Logger _logger = LoggerFactory.getLogger(SocialSignOnListController.class);
 	
 	@Autowired
-	SocialSignOnProviderService socialSignOnProviderService;
+	protected SocialsAssociatesService socialsAssociatesService;
 	
-	@Autowired
-	protected SocialsAssociateService socialSignOnUserService;
-	
-	@Autowired
-  	@Qualifier("applicationConfig")
-  	protected ApplicationConfig applicationConfig;
 	
-	@RequestMapping(value = { "/list" })
-	public ModelAndView forwardUpdate() {
-		
-		ModelAndView modelAndView=new ModelAndView("social/socialSignOnProvider");
-
-		Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
-		List<SocialsProvider>  listSocialSignOnProvider = 
-								socialSignOnProviderService.loadSocialsProviders(inst.getId()).getSocialSignOnProviders();
-		
-		SocialsAssociate socialSignOnUser=new SocialsAssociate();
-		socialSignOnUser.setUserId(WebContext.getUserInfo().getId());
-		List<SocialsAssociate>  listSocialSignOnUserToken= socialSignOnUserService.query(socialSignOnUser);
-		List<SocialsProvider>  listBindSocialSignOnProvider=new ArrayList<SocialsProvider>();
-		_logger.debug("list SocialSignOnProvider : "+listSocialSignOnProvider);
-		_logger.debug("list SocialSignOnUserToken : "+listSocialSignOnUserToken);
-		for (SocialsProvider ssop : listSocialSignOnProvider){
-			SocialsProvider socialSignOnProvider=new SocialsProvider();
-			socialSignOnProvider.setProvider(ssop.getProvider());
-			socialSignOnProvider.setProviderName(ssop.getProviderName());
-			socialSignOnProvider.setIcon(ssop.getIcon());
-			socialSignOnProvider.setSortOrder(ssop.getSortOrder());
-			for(SocialsAssociate ssout :listSocialSignOnUserToken){
-				if(ssout.getProvider().equals(ssop.getProvider())){
-					socialSignOnProvider.setUserBind(true);
-					socialSignOnProvider.setBindTime(ssout.getCreatedDate());
-					socialSignOnProvider.setLastLoginTime(ssout.getUpdatedDate());
-					_logger.debug("binded provider : "+ssout.getProvider());
-				}
-			}
-			listBindSocialSignOnProvider.add(socialSignOnProvider);
-		}
+	@RequestMapping(value={"/fetch"})
+	@ResponseBody
+	public ResponseEntity<?> fetch(@CurrentUser UserInfo currentUser){
 		
-		modelAndView.addObject("listSocialSignOnProvider", listBindSocialSignOnProvider);
+		List<SocialsAssociate>  listSocialsAssociate= 
+				socialsAssociatesService.queryByUser(currentUser);
 		
-		return modelAndView;
+		return new Message<List<SocialsAssociate>>(listSocialsAssociate).buildResponse();
 	}
 	
 }

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/application.properties

@@ -16,7 +16,7 @@
 #MaxKey Title and Version                                                  #
 ############################################################################
 application.title                           =MaxKey
-application.formatted-version               =v3.4.0 GA
+application.formatted-version               =v3.5.0 GA
 #for dynamic service discovery
 spring.application.name                     =maxkey
 ############################################################################

+ 1 - 1
maxkey-webs/maxkey-web-mgt/src/main/resources/application.properties

@@ -16,7 +16,7 @@
 #MaxKey Title and Version                                                  #
 ############################################################################
 application.title                               =MaxKey-Mgt
-application.formatted-version                   =v3.4.0 GA
+application.formatted-version                   =v3.5.0 GA
 #for dynamic service discovery
 spring.application.name                         =maxkey-mgt
 ############################################################################