Przeglądaj źródła

Merge branch 'dev' of http://192.168.1.220:10080/jiwei/jw2.0 into dev

Conflicts:
	svr/svr-iot/src/main/resources/application.yml
yeshijie 7 lat temu
rodzic
commit
cbfb61160d

+ 10 - 1
app/app-iot-server/src/main/java/com/yihu/ehr/iot/security/config/EhrWebSecurityConfiguration.java

@ -1,6 +1,7 @@
package com.yihu.ehr.iot.security.config;
import com.yihu.ehr.iot.security.core.*;
import com.yihu.ehr.iot.security.entryPoint.LoginEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@ -38,7 +39,8 @@ public class EhrWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    //private EhrWebAccessDecisionManager ehrWebAccessDecisionManager;
    @Autowired
    private SessionRegistry sessionRegistry;
    @Autowired
    private LoginEntryPoint loginEntryPoint;
    @Autowired
    private EhrWebContextLogoutHandler ehrWebContextLogoutHandler;
@ -75,6 +77,7 @@ public class EhrWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
                .antMatchers("/front/views/**").hasRole("USER")
                .antMatchers("/**").hasRole("USER")
                .and().formLogin().loginPage("/login")
                .and().exceptionHandling().authenticationEntryPoint(loginEntryPoint)
                .and().logout().addLogoutHandler(ehrWebContextLogoutHandler).logoutUrl("/logout").logoutSuccessUrl("/login")
                .and().headers().frameOptions().disable()
                .and().csrf().disable();
@ -111,6 +114,12 @@ public class EhrWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    EhrWebContextLogoutHandler ehrWebContextLogoutHandler(){
        return new EhrWebContextLogoutHandler();
    }
    @Bean
    LoginEntryPoint loginEntryPoint(){
        return new LoginEntryPoint("/login");
    }
    /**
    @Bean
    EhrWebAccessDecisionManager ehrWebAccessDecisionManager() {

+ 36 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/security/entryPoint/LoginEntryPoint.java

@ -0,0 +1,36 @@
package com.yihu.ehr.iot.security.entryPoint;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author yeshijie on 2018/3/9.
 */
public class LoginEntryPoint extends LoginUrlAuthenticationEntryPoint {
    public LoginEntryPoint(String loginFormUrl) {
        super(loginFormUrl);
    }
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        JSONObject json = new JSONObject();
        json.put("status",998);
        json.put("errorMsg","未登录或,登录超时");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        response.getWriter().println(json.toString());
        response.getWriter().flush();
//        super.commence(request, response, authException);
    }
}

+ 17 - 2
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/BaseService.java

@ -1,5 +1,6 @@
package com.yihu.ehr.iot.service.common;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.user.UserDetailModel;
@ -65,14 +66,28 @@ public class BaseService {
     * 获取当前登录用户,当前已登录的用户都缓存在session中
     * @return
     */
    public UserDetailModel getCurrentUser(){
    public JSONObject getCurrentUser(){
        JSONObject json = new JSONObject();
        String sessionId = request.getSession().getId();
        UserDetailModel user = null;
        SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId);
        if(null != sessionInformation.getPrincipal()){
            user = (UserDetailModel)sessionInformation.getPrincipal();
            json.put("id",user.getId());
            json.put("code",user.getLoginCode());
            json.put("name",user.getRealName());
        }
        return user;
        return json;
    }
    /**
     * 获取登录信息
     * @return
     */
    public Map<String,Object> getLoginHeader(){
        Map<String, Object> header = new HashMap<>();
        header.put("User-Agent",getCurrentUser());
        return header;
    }
    public String readFile(String filePath, String charSet) {

+ 1 - 1
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/product/ProductService.java

@ -130,7 +130,7 @@ public class ProductService extends BaseService {
    public Envelop<IotProductVO> findByCode(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Product.FindProductById, params);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Product.FindProductById, params,getLoginHeader());
        Envelop<IotProductVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }

+ 7 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java

@ -16,6 +16,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
@ -31,6 +32,8 @@ public class IotProductController extends EnvelopRestController {
    private IotProductBaseInfoService iotProductBaseInfoService;
    @Autowired
    private IotSystemDictService iotSystemDictService;
    @Autowired
    private HttpServletRequest request;
    @GetMapping(value = IotRequestMapping.Product.findProductPage)
@ -145,6 +148,10 @@ public class IotProductController extends EnvelopRestController {
    public Envelop<IotProductVO> findByCode(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            String userAgent = request.getHeader("userAgent");
            if (StringUtils.isEmpty(userAgent)) {
                userAgent = request.getHeader("User-Agent");
            }
            IotProductVO vo = iotProductBaseInfoService.findProductById(id);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find, vo);
        } catch (Exception e) {

+ 1 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/product/IotProductBaseInfoService.java

@ -35,6 +35,7 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
    @Autowired
    private IotSystemDictService iotSystemDictService;
    /**
     * 按id查找产品详情
     * @param id