MaxKeyMgtConfig.java 2.6 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */
 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
18 19
package org.maxkey;

M
MaxKey 已提交
20
import org.maxkey.password.onetimepwd.AbstractOtpAuthn;
M
MaxKey 已提交
21
import org.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
M
MaxKey 已提交
22 23 24
import org.maxkey.persistence.repository.LoginHistoryRepository;
import org.maxkey.persistence.repository.LoginRepository;
import org.maxkey.persistence.repository.PasswordPolicyValidator;
M
MaxKey 已提交
25
import org.maxkey.persistence.service.UserInfoService;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
26
import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
MaxKey单点登录官方's avatar
kaptcha  
MaxKey单点登录官方 已提交
27 28
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
29 30
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Bean;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
31
import org.springframework.context.annotation.Configuration;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
32
import org.springframework.jdbc.core.JdbcTemplate;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
33
import org.springframework.security.crypto.password.PasswordEncoder;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
34 35

@Configuration
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
36
public class MaxKeyMgtConfig  implements InitializingBean {
MaxKey单点登录官方's avatar
kaptcha  
MaxKey单点登录官方 已提交
37
    private static final  Logger _logger = LoggerFactory.getLogger(MaxKeyMgtConfig.class);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
38
    
M
MaxKey 已提交
39
	//authenticationRealm for MaxKeyMgtApplication
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
40
	@Bean(name = "authenticationRealm")
M
MaxKey 已提交
41 42 43
	public JdbcAuthenticationRealm authenticationRealm(
 			PasswordEncoder passwordEncoder,
	    		PasswordPolicyValidator passwordPolicyValidator,
M
MaxKey 已提交
44 45
	    		LoginRepository loginRepository,
	    		LoginHistoryRepository loginHistoryRepository,
M
MaxKey 已提交
46
	    		UserInfoService userInfoService,
M
MaxKey 已提交
47 48 49 50 51
             JdbcTemplate jdbcTemplate) {
		
        JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm(
        		passwordEncoder,
        		passwordPolicyValidator,
M
MaxKey 已提交
52 53
        		loginRepository,
        		loginHistoryRepository,
M
MaxKey 已提交
54
        		userInfoService,
M
MaxKey 已提交
55 56
        		jdbcTemplate);
        
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
57 58 59
        _logger.debug("JdbcAuthenticationRealm inited.");
        return authenticationRealm;
    }
M
MaxKey 已提交
60

M
MaxKey 已提交
61 62 63
	@Bean(name = "timeBasedOtpAuthn")
    public AbstractOtpAuthn timeBasedOtpAuthn() {
		AbstractOtpAuthn tfaOtpAuthn = new TimeBasedOtpAuthn();
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
64
	    _logger.debug("TimeBasedOtpAuthn inited.");
M
MaxKey 已提交
65
        return tfaOtpAuthn;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
66
    }
M
MaxKey 已提交
67

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
68 69 70 71
    @Override
    public void afterPropertiesSet() throws Exception {
        
    }
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
72

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
73
}