mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 20:50:14 +08:00
maxkey-authentications
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
|
||||
description = "maxkey-authentication-captcha"
|
||||
|
||||
|
||||
dependencies {
|
||||
//local jars
|
||||
compile fileTree(dir: '../maxkey-lib/', include: '*/*.jar')
|
||||
|
||||
compile project(":maxkey-core")
|
||||
compile project(":maxkey-persistence")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import com.google.code.kaptcha.util.Config;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import org.maxkey.constants.ConstantsProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class KaptchaAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(KaptchaAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* Captcha Producer Config .
|
||||
* @return Producer
|
||||
* @throws IOException kaptcha.properties is null
|
||||
*/
|
||||
@Bean (name = "captchaProducer")
|
||||
public Producer captchaProducer() throws IOException {
|
||||
Resource resource = new ClassPathResource(
|
||||
ConstantsProperties.classPathResource(ConstantsProperties.kaptchaPropertySource));
|
||||
_logger.debug("Kaptcha config file " + resource.getURL());
|
||||
DefaultKaptcha kaptcha = new DefaultKaptcha();
|
||||
Properties properties = new Properties();
|
||||
properties.load(resource.getInputStream());
|
||||
Config config = new Config(properties);
|
||||
kaptcha.setConfig(config);
|
||||
return kaptcha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.maxkey.web.contorller;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.maxkey.web.image.AbstractImageEndpoint;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
/**
|
||||
* ImageCaptchaEndpoint Producer captcha.
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class ImageCaptchaEndpoint extends AbstractImageEndpoint {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(ImageCaptchaEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
private Producer captchaProducer;
|
||||
|
||||
/**
|
||||
* captcha image Producer.
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
@RequestMapping(value = "/captcha")
|
||||
public void captchaHandleRequest(HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
String kaptchaText = captchaProducer.createText();
|
||||
if (applicationConfig.getLoginConfig().getCaptchaType()
|
||||
.equalsIgnoreCase("Arithmetic")) {
|
||||
Integer intParamA = Integer.valueOf(kaptchaText.substring(0, 1));
|
||||
Integer intParamB = Integer.valueOf(kaptchaText.substring(1, 2));
|
||||
Integer calculateValue = 0;
|
||||
if ((intParamA > intParamB) && ((intParamA + intParamB) % 5 > 3)) {
|
||||
calculateValue = intParamA - intParamB;
|
||||
kaptchaText = intParamA + "-" + intParamB + "=?";
|
||||
} else {
|
||||
calculateValue = intParamA + intParamB;
|
||||
kaptchaText = intParamA + "+" + intParamB + "=?";
|
||||
}
|
||||
_logger.trace("Sesssion id " + request.getSession().getId()
|
||||
+ " , Arithmetic calculate Value is " + calculateValue);
|
||||
request.getSession().setAttribute(
|
||||
WebConstants.KAPTCHA_SESSION_KEY, calculateValue + "");
|
||||
} else {
|
||||
// store the text in the session
|
||||
request.getSession().setAttribute(WebConstants.KAPTCHA_SESSION_KEY, kaptchaText);
|
||||
}
|
||||
_logger.trace("Sesssion id " + request.getSession().getId()
|
||||
+ " , Captcha Text is " + kaptchaText);
|
||||
|
||||
// create the image with the text
|
||||
BufferedImage bufferedImage = captchaProducer.createImage(kaptchaText);
|
||||
producerImage(request,response,bufferedImage);
|
||||
} catch (Exception e) {
|
||||
_logger.error("captcha Producer Error " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setCaptchaProducer(Producer captchaProducer) {
|
||||
this.captchaProducer = captchaProducer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
kaptcha.image.width=80
|
||||
kaptcha.image.height=25
|
||||
kaptcha.border=no
|
||||
kaptcha.obscurificator.impl=com.google.code.kaptcha.impl.ShadowGimpy
|
||||
kaptcha.textproducer.font.size=23
|
||||
kaptcha.textproducer.char.string=0123456789
|
||||
kaptcha.textproducer.char.length=4
|
||||
kaptcha.noise.impl=com.google.code.kaptcha.impl.NoNoise
|
||||
#kaptcha.noise.color=white
|
||||
@@ -1,13 +1,11 @@
|
||||
|
||||
description = "maxkey-authentications"
|
||||
description = "maxkey-authentication-core"
|
||||
|
||||
|
||||
dependencies {
|
||||
//local jars
|
||||
compile fileTree(dir: '../maxkey-lib/', include: '*/*.jar')
|
||||
|
||||
|
||||
|
||||
compile project(":maxkey-core")
|
||||
compile project(":maxkey-persistence")
|
||||
compile project(":maxkey-protocols:maxkey-protocol-oauth-2.0")
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
description = "maxkey-authentication-social"
|
||||
|
||||
|
||||
dependencies {
|
||||
//local jars
|
||||
compile fileTree(dir: '../maxkey-lib/', include: '*/*.jar')
|
||||
|
||||
compile project(":maxkey-core")
|
||||
compile project(":maxkey-persistence")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.maxkey.authn.support.socialsignon.service.JdbcSocialsAssociateService;
|
||||
import org.maxkey.authn.support.socialsignon.service.SocialSignOnProvider;
|
||||
import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
|
||||
import org.maxkey.constants.ConstantsProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {
|
||||
"org.maxkey.authn.support.socialsignon"
|
||||
})
|
||||
@PropertySource(ConstantsProperties.maxKeyPropertySource)
|
||||
public class SocialSignOnAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(SocialSignOnAutoConfiguration.class);
|
||||
|
||||
@Bean(name = "socialSignOnProviderService")
|
||||
@ConditionalOnClass(SocialSignOnProvider.class)
|
||||
public SocialSignOnProviderService socialSignOnProviderService() throws IOException {
|
||||
SocialSignOnProviderService socialSignOnProviderService = new SocialSignOnProviderService();
|
||||
|
||||
Resource resource = new ClassPathResource(
|
||||
ConstantsProperties.classPathResource(ConstantsProperties.classPathResource(ConstantsProperties.maxKeyPropertySource)));
|
||||
Properties properties = new Properties();
|
||||
properties.load(resource.getInputStream());
|
||||
String [] providerList =properties.get("config.login.socialsignon.providers").toString().split(",");
|
||||
List<SocialSignOnProvider> socialSignOnProviderList = new ArrayList<SocialSignOnProvider>();
|
||||
for(String provider : providerList) {
|
||||
String providerName = properties.getProperty("config.socialsignon."+provider+".provider.name");
|
||||
String icon=properties.getProperty("config.socialsignon."+provider+".icon");
|
||||
String clientId=properties.getProperty("config.socialsignon."+provider+".client.id");
|
||||
String clientSecret=properties.getProperty("config.socialsignon."+provider+".client.secret");
|
||||
String sortOrder = properties.getProperty("config.socialsignon."+provider+".sortorder");
|
||||
SocialSignOnProvider socialSignOnProvider = new SocialSignOnProvider();
|
||||
socialSignOnProvider.setProvider(provider);
|
||||
socialSignOnProvider.setProviderName(providerName);
|
||||
socialSignOnProvider.setIcon(icon);
|
||||
socialSignOnProvider.setClientId(clientId);
|
||||
socialSignOnProvider.setClientSecret(clientSecret);
|
||||
socialSignOnProvider.setSortOrder(Integer.valueOf(sortOrder));
|
||||
_logger.debug("socialSignOnProvider " + socialSignOnProvider.getProvider()
|
||||
+ "(" + socialSignOnProvider.getProviderName()+")");
|
||||
_logger.trace("socialSignOnProvider " + socialSignOnProvider);
|
||||
socialSignOnProviderList.add(socialSignOnProvider);
|
||||
}
|
||||
socialSignOnProviderService.setSocialSignOnProviders(socialSignOnProviderList);
|
||||
_logger.debug("SocialSignOnProviderService inited.");
|
||||
return socialSignOnProviderService;
|
||||
}
|
||||
|
||||
@Bean(name = "socialsAssociateService")
|
||||
public JdbcSocialsAssociateService socialsAssociateService(
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
JdbcSocialsAssociateService socialsAssociateService = new JdbcSocialsAssociateService(jdbcTemplate);
|
||||
_logger.debug("JdbcSocialsAssociateService inited.");
|
||||
return socialsAssociateService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user