SocialSignOnListController.java 3.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
init  
MaxKey单点登录官方 已提交
18 19 20 21 22 23
package org.maxkey.web.contorller;

import java.util.ArrayList;
import java.util.List;

import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
MaxKey单点登录官方's avatar
fix  
MaxKey单点登录官方 已提交
24 25
import org.maxkey.authn.support.socialsignon.service.SocialsAssociate;
import org.maxkey.authn.support.socialsignon.service.SocialsAssociateService;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
26
import org.maxkey.configuration.ApplicationConfig;
M
v3.2.1  
MaxKey 已提交
27
import org.maxkey.entity.Institutions;
28
import org.maxkey.entity.SocialsProvider;
M
v3.2.1  
MaxKey 已提交
29
import org.maxkey.web.WebConstants;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import org.maxkey.web.WebContext;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping(value={"/socialsignon"})
public class SocialSignOnListController {
	final static Logger _logger = LoggerFactory.getLogger(SocialSignOnListController.class);
	
	@Autowired
	SocialSignOnProviderService socialSignOnProviderService;
	
	@Autowired
MaxKey单点登录官方's avatar
fix  
MaxKey单点登录官方 已提交
49
	protected SocialsAssociateService socialSignOnUserService;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
50 51 52 53 54 55 56 57 58
	
	@Autowired
  	@Qualifier("applicationConfig")
  	protected ApplicationConfig applicationConfig;
	
	@RequestMapping(value = { "/list" })
	public ModelAndView forwardUpdate() {
		
		ModelAndView modelAndView=new ModelAndView("social/socialSignOnProvider");
M
MaxKey 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

		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());
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
82 83
				}
			}
M
MaxKey 已提交
84
			listBindSocialSignOnProvider.add(socialSignOnProvider);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
85
		}
M
MaxKey 已提交
86 87 88
		
		modelAndView.addObject("listSocialSignOnProvider", listBindSocialSignOnProvider);
		
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
89 90 91 92
		return modelAndView;
	}
	
}