Java tutorial
/* * Copyright 2013 Jwsz.net All right reserved. This software is the * confidential and proprietary information of Jwsz.net ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Jwsz.net. */ package com.codestudio.dorm.web.util; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import com.codestudio.dorm.common.cookie.UserCookieManager; import com.codestudio.dorm.domain.Party; /** * PartyAuthUtil.java??? * * @author J 2014-6-7 ?11:20:12 */ public class PartyAuthUtil { /** * ???null * * @param request * @param response * @return */ public static Party getPartyInfo(HttpServletRequest request, HttpServletResponse response) { Party party = null; UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); String partyId = userCookieManager.getTempCookie(UserCookieManager.PARTY_ID, null); if (StringUtils.isNotBlank(partyId)) { party = new Party(); party.setId(Long.valueOf(partyId)); party.setPartyNum(userCookieManager.getTempCookie(UserCookieManager.PARTY_NUM, null)); } return party; } /** * ??null * * @param request * @param response * @return */ public static Long getPartyId(HttpServletRequest request, HttpServletResponse response) { UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); String partyId = userCookieManager.getTempCookie(UserCookieManager.PARTY_ID, null); if (StringUtils.isNotBlank(partyId)) { return Long.valueOf(partyId); } return null; } /** * ??? * * @param request * @param response * @return */ public static boolean isSignIn(HttpServletRequest request, HttpServletResponse response) { UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); String partyId = userCookieManager.getTempCookie(UserCookieManager.PARTY_ID, null); return StringUtils.isNotBlank(partyId); } /** * cookie * * @param userInfo * @param request * @param response */ public static void signIn(Party party, HttpServletRequest request, HttpServletResponse response) { if (party != null) { UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); userCookieManager.setTempCookie(UserCookieManager.PARTY_ID, "" + party.getId()); userCookieManager.setTempCookie(UserCookieManager.PARTY_NUM, party.getPartyNum()); userCookieManager.saveTempCookie(); } } /** * * * @param request * @param response */ public static void signOut(HttpServletRequest request, HttpServletResponse response) { UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); userCookieManager.setTempCookie(UserCookieManager.PARTY_ID, null); userCookieManager.removeTempCookie(UserCookieManager.PARTY_ID); userCookieManager.setTempCookie(UserCookieManager.PARTY_NUM, null); userCookieManager.removeTempCookie(UserCookieManager.PARTY_NUM); userCookieManager.saveTempCookie(); } }