• webservice统一认证


    service

    package cn.edu.hbcf.privilege.ws;
    
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    @WebService
    public interface CxfSecuityService {
        
        
        String registerUser(@WebParam(name="userName")String userName,@WebParam(name="password") String password);  
    
    }

    serviceImpl

    package cn.edu.hbcf.privilege.ws.impl;
    
    
    import java.util.List;
    
    import javax.annotation.Resource;
    import javax.jws.WebService;
    import javax.servlet.http.HttpSession;
    import javax.xml.ws.WebServiceContext;
    import javax.xml.ws.handler.MessageContext;
    
    import org.apache.commons.codec.digest.DigestUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import cn.edu.hbcf.common.vo.Criteria;
    import cn.edu.hbcf.framework.dao.FrameworkMapper;
    import cn.edu.hbcf.framework.pojo.APIKeyWebservice;
    import cn.edu.hbcf.privilege.dao.BaseAPIKeysMapper;
    import cn.edu.hbcf.privilege.pojo.BaseAPIKeys;
    import cn.edu.hbcf.privilege.ws.CxfSecuityService;
    
    @Service
    @WebService(serviceName = "cxfSecuityService", portName = "cxfSecuityServicePort", endpointInterface = "cn.edu.hbcf.privilege.ws.CxfSecuityService")
    public class CxfSecuityServiceImpl implements CxfSecuityService{
    
        
          @Resource    
          private WebServiceContext wsContext;     
          private MessageContext mc;     
          private HttpSession session;     
          
          @Autowired
            private BaseAPIKeysMapper keyMapper;
            @Autowired
            private FrameworkMapper frameWorkMapper;
            
    
        @Override
        public String registerUser(String userName, String password) {
            Criteria criteria = new Criteria();
            criteria.put("keyName", userName);
            List<BaseAPIKeys> keysList = keyMapper.selectByExample(criteria);
            if (!keysList.isEmpty()) {
                BaseAPIKeys userKey = keysList.get(0);
                password = DigestUtils.md5Hex(password);
                if (password.equals(userKey.getKeyPassword())) {
                     mc = wsContext.getMessageContext();     
                    
                    session = ((javax.servlet.http.HttpServletRequest) mc
                            .get(MessageContext.SERVLET_REQUEST)).getSession();
    
                    ((javax.servlet.ServletContext) mc
                            .get(MessageContext.SERVLET_CONTEXT)) .setAttribute(
                            "session", session);
                    session.setAttribute("msg", "ok");
                    criteria.clear();
                    criteria.put("key_id", userKey.getKeyId());
                    List<APIKeyWebservice> list = frameWorkMapper.queryListByAPIKeyId(criteria);
                    session.setAttribute("perm", list);
                    return "认证成功!";
                }
            }
            return "认证失败!";
        }
    
    
    }
    <sql id="Example_Where_Clause">
            <trim prefix="where" prefixOverrides="and|or">
                <if test="condition.keyNameLike != null">
                    <![CDATA[ and KEY_NAME LIKE '%'||#{condition.keyNameLike}||'%' ]]>
                </if>
                <if test="condition.keyName != null">
                    and KEY_NAME = #{condition.keyName}
                </if>
                <if test="condition.keyDesc != null">
                    and KEY_DESC = #{condition.keyDesc}
                </if>
            </trim>
        </sql>
        <sql id="Base_Column_List">KEY_ID,KEY_NAME,KEY_PASSWORD,KEY_IP,KEY_DESC</sql>
        <select id="selectByExample" resultMap="BaseResultMap"
            parameterType="Criteria">
            <include refid="common.Oracle_Pagination_Head" />
            select
            <if test="distinct">distinct</if>
            <include refid="Base_Column_List" />
            from BASE_APIKEYS
            <if test="_parameter != null">
                <include refid="Example_Where_Clause" />
            </if>
            <if test="orderByClause != null">order by ${orderByClause}</if>
            <include refid="common.Oracle_Pagination_Tail" />
        </select>
  • 相关阅读:
    js获取网页屏幕可视区域高度
    vue 一键复制文本内容 clipboard
    uniapp 微信小程序分包优化
    通过vuecli命令行安装uniapp
    微信小程序跳转
    .net session丢失
    验证码识别技术研究(2)
    window环境下安装和卸载服务【转】
    formValidator onshowhtml is not define
    Ajax 跨域请求
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/4942926.html
Copyright © 2020-2023  润新知