zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Spring——注解代替XML配置文件,Spring与JUnit整合
    Spring——基本概念(IOC,DI思想),Spring配置文件(XML),属性注入,Spring与Web项目结合
    Struts——自定义拦截器
    Struts——OGNL表达式与Struts2结合
    Struts2——结果跳转方式配置(重定向,转发<默认>,重定向到方法,重定向到转发),获取servlet的内些API(request,servletcontext...),获取参数
    Struts2——基本使用与配置文件
    基于中间件的RBAC权限控制
    Django
    Django
    Django 中 admin 的执行流程
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/4942926.html
Copyright © 2011-2022 走看看