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>