MaxKey 3 years ago
parent
commit
b6d30a8730

+ 27 - 0
maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/UniqueTextCreator.java

@@ -0,0 +1,27 @@
+package com.google.code.kaptcha.impl;
+
+import java.util.Random;
+
+import com.google.code.kaptcha.text.TextProducer;
+import com.google.code.kaptcha.util.Configurable;
+
+public class UniqueTextCreator  extends Configurable implements TextProducer{
+
+	@Override
+	public String getText() {
+		int length = getConfig().getTextProducerCharLength();
+		char[] chars = getConfig().getTextProducerCharString();
+		Random rand = new Random();
+		StringBuffer text = new StringBuffer();
+		int i = 0;
+		while ( i < length){
+			char word= chars[rand.nextInt(chars.length)];
+			if(text.indexOf(word + "") <= -1 ) {
+				text.append(word);
+				i++;
+			}
+		}
+		return text.toString();
+	}
+
+}

+ 5 - 4
maxkey-authentications/maxkey-authentication-captcha/src/main/resources/kaptcha.properties

@@ -1,13 +1,14 @@
-kaptcha.image.width=80
+kaptcha.image.width=120
 kaptcha.image.height=40
 kaptcha.border=no
 #kaptcha.obscurificator.impl=com.google.code.kaptcha.impl.ShadowGimpy
 kaptcha.obscurificator.impl=com.google.code.kaptcha.impl.Ripple
-kaptcha.textproducer.font.size=23
+kaptcha.textproducer.font.size=30
 kaptcha.textproducer.char.string=0123456789
 kaptcha.textproducer.char.length=4
-kaptcha.textproducer.char.space=3
+kaptcha.textproducer.char.space=6
 #kaptcha.noise.impl=com.google.code.kaptcha.impl.DefaultNoise
 kaptcha.noise.impl=com.google.code.kaptcha.impl.LightNoise
 #kaptcha.noise.color=white
-kaptcha.word.impl=com.google.code.kaptcha.text.impl.RandomColorWordRenderer
+kaptcha.word.impl=com.google.code.kaptcha.text.impl.RandomColorWordRenderer
+kaptcha.textproducer.impl=com.google.code.kaptcha.impl.UniqueTextCreator

+ 4 - 1
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/jwt/AuthJwtService.java

@@ -65,7 +65,10 @@ public class AuthJwtService {
 	 * @return AuthJwt
 	 */
 	public AuthJwt genAuthJwt(Authentication authentication) {
-		return new AuthJwt(genJwt(authentication), authentication);
+		if(authentication != null) {
+			return new AuthJwt(genJwt(authentication), authentication);
+		}
+		return null;
 	}
 	
 	/**

+ 14 - 2
maxkey-core/src/main/java/org/maxkey/entity/apps/Apps.java

@@ -141,6 +141,9 @@ public class Apps extends JpaBaseEntity implements Serializable {
     @Column
     private String adapter;
 
+	@Column
+	private String frequently;
+	
     @Column
     protected int sortIndex;
     @Column
@@ -157,7 +160,7 @@ public class Apps extends JpaBaseEntity implements Serializable {
     protected String description;
 	@Column
 	private String instId;
-
+	
 	private String instName;
     
     protected String loginDateTime;
@@ -248,7 +251,16 @@ public class Apps extends JpaBaseEntity implements Serializable {
         this.secret = secret;
     }
 
-    /**
+    
+    public String getFrequently() {
+		return frequently;
+	}
+
+	public void setFrequently(String frequently) {
+		this.frequently = frequently;
+	}
+
+	/**
      * @return the icon
      */
     public byte[] getIcon() {

+ 1 - 0
maxkey-core/src/main/java/org/maxkey/entity/apps/AppsOAuth20Details.java

@@ -106,6 +106,7 @@ public class AppsOAuth20Details extends Apps {
         this.setAdapter(application.getAdapter());
         this.setAdapterId(application.getAdapterId());
         this.setAdapterName(application.getAdapterName());
+        this.setFrequently(application.getFrequently());
         
         this.clientSecret = baseClientDetails.getClientSecret();
         this.scope = StringUtils

+ 17 - 3
maxkey-core/src/main/java/org/maxkey/persistence/repository/InstitutionsRepository.java

@@ -37,6 +37,8 @@ public class InstitutionsRepository {
     
     private static final String SELECT_STATEMENT = 
     						"select * from  mxk_institutions where id = ? or domain = ? " ;
+    
+    private static final String DEFAULT_INSTID = "1";
 
     protected static final Cache<String, Institutions> institutionsStore = 
             Caffeine.newBuilder()
@@ -54,7 +56,17 @@ public class InstitutionsRepository {
     
     public Institutions get(String instIdOrDomain) {
         _logger.trace(" instId {}" , instIdOrDomain);
-        Institutions inst = institutionsStore.getIfPresent(mapper.get(instIdOrDomain)==null ? "1" : mapper.get(instIdOrDomain) );
+        Institutions inst = getByInstIdOrDomain(instIdOrDomain);
+        if(inst == null) {//use default inst
+        	inst = getByInstIdOrDomain(DEFAULT_INSTID);
+        	institutionsStore.put(instIdOrDomain, inst);
+        }
+        return inst;
+    }
+    
+    private Institutions getByInstIdOrDomain(String instIdOrDomain) {
+        _logger.trace(" instId {}" , instIdOrDomain);
+        Institutions inst = institutionsStore.getIfPresent(mapper.get(instIdOrDomain)==null ? DEFAULT_INSTID : mapper.get(instIdOrDomain) );
         if(inst == null) {
 	        List<Institutions> institutions = 
 	        		jdbcTemplate.query(SELECT_STATEMENT,new InstitutionsRowMapper(),instIdOrDomain,instIdOrDomain);
@@ -62,8 +74,10 @@ public class InstitutionsRepository {
 	        if (institutions != null && institutions.size() > 0) {
 	        	inst = institutions.get(0);
 	        }
-	        institutionsStore.put(inst.getDomain(), inst);
-	        mapper.put(inst.getId(), inst.getDomain());
+	        if(inst != null ) {
+		        institutionsStore.put(inst.getDomain(), inst);
+		        mapper.put(inst.getId(), inst.getDomain());
+	        }
         }
         
         return inst;

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

@@ -155,7 +155,7 @@ public class LoginEntryPoint {
  			String authType =  loginCredential.getAuthType();
  			 _logger.debug("Login AuthN Type  " + authType);
  	        if (StringUtils.isNotBlank(authType)){
-		 		Authentication  authentication = authenticationProvider.doAuthenticate(loginCredential);	 				
+		 		Authentication  authentication = authenticationProvider.authenticate(loginCredential);	 				
 		 		if(authentication != null) {
 		 			authJwtMessage = new Message<AuthJwt>(authJwtService.genAuthJwt(authentication));
 		 		}

+ 1 - 0
maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java

@@ -45,6 +45,7 @@ import org.springframework.http.MediaType;
  *
  */
 @Controller
+@RequestMapping(value = "/login")
 public class LoginEntryPoint {
 	private static Logger _logger = LoggerFactory.getLogger(LoginEntryPoint.class);