use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.
the class TokenProcessor method resetToken.
/**
* Reset the saved transaction token in the user's session. This
* indicates that transactional token checking will not be needed on the
* next request that is submitted.
*
* @param request The servlet request we are processing
*/
public synchronized void resetToken(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session == null) {
return;
}
session.removeAttribute(Globals.TRANSACTION_TOKEN_KEY);
}
use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.
the class TokenProcessor method isTokenValid.
/**
* Return <code>true</code> if there is a transaction token stored in the
* user's current session, and the value submitted as a request parameter
* with this action matches it. Returns <code>false</code>
*
* <ul>
*
* <li>No session associated with this request</li> <li>No transaction
* token saved in the session</li>
*
* <li>No transaction token included as a request parameter</li>
*
* <li>The included transaction token value does not match the transaction
* token in the user's session</li>
*
* </ul>
*
* @param request The servlet request we are processing
* @param reset Should we reset the token after checking it?
*/
public synchronized boolean isTokenValid(HttpServletRequest request, boolean reset) {
// Retrieve the current session for this request
HttpSession session = request.getSession(false);
if (session == null) {
return false;
}
// Retrieve the transaction token from this session, and
// reset it if requested
String saved = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
if (saved == null) {
return false;
}
if (reset) {
this.resetToken(request);
}
// Retrieve the transaction token included in this request
String token = request.getParameter(Globals.TOKEN_KEY);
if (token == null) {
return false;
}
return saved.equals(token);
}
use of javax.servlet.http.HttpSession in project MSEC by Tencent.
the class DownloadDevGO method doStep2.
private JsonRPCResponseBase doStep2(DevPackage request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
Logger logger = Logger.getLogger(DownloadDevGO.class);
HttpSession session = getHttpRequest().getSession();
DevPackage plan = (DevPackage) session.getAttribute("DevPackage");
if (plan == null) {
plan = new DevPackage();
session.setAttribute("DevPackage", plan);
}
//制作tar包,这里还是同步的在当前线程完成,必要的话可以用另外一个
//线程异步的完成。
logger.info("begin making dev package...");
PackDevFile packDevFile = new PackDevFile(plan, getServlet().getServletContext());
packDevFile.run();
if (!packDevFile.getResultString().equals("success")) {
response.setMessage(packDevFile.getResultString());
response.setStatus(100);
return response;
}
String fileName = packDevFile.getOutputFileName();
logger.info("dev package path:" + fileName);
File f = new File(fileName);
String length = String.format("%d", f.length());
//将文件内容直接返回,注意MIME 类型,且exec函数应该返回null
getHttpResponse().setHeader("Content-disposition", "attachment;filename=" + new File(fileName).getName());
// set the MIME type.
getHttpResponse().setContentType("application/x-gzip-compressed");
getHttpResponse().setHeader("Content_Length", length);
try {
ServletOutputStream out = getHttpResponse().getOutputStream();
FileInputStream fileInputStream = new FileInputStream(f);
byte[] buf = new byte[10240];
while (true) {
int len = fileInputStream.read(buf);
if (len <= 0) {
break;
}
out.write(buf, 0, len);
}
out.flush();
out.close();
fileInputStream.close();
f.delete();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of javax.servlet.http.HttpSession in project MSEC by Tencent.
the class DownloadDevGO method doStep1.
private JsonRPCResponseBase doStep1(DevPackage request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
//把计划保存到session里
HttpSession session = getHttpRequest().getSession();
DBUtil util = new DBUtil();
try {
util.getConnection();
String sql = "select dev_lang from t_second_level_service where first_level_service_name=? and second_level_service_name=?";
ArrayList<Object> params = new ArrayList<Object>();
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
Map<String, Object> map = util.findSimpleResult(sql, params);
request.setDev_lang((String) map.get("dev_lang"));
} catch (Exception e) {
request.setDev_lang("c++");
} finally {
util.releaseConn();
}
session.setAttribute("DevPackage", request);
response.setMessage("success");
response.setStatus(0);
return response;
}
use of javax.servlet.http.HttpSession in project MSEC by Tencent.
the class ReleaseOnlySharedobject method doRelease.
private ReleaseStepsGOResponse doRelease(ReleasePlan request) {
ReleaseStepsGOResponse response = new ReleaseStepsGOResponse();
//把计划保存到session里
HttpSession session = getHttpRequest().getSession();
ReleasePlan plan = (ReleasePlan) session.getAttribute("plan");
if (plan == null) {
response.setMessage("can NOT find the session, it maybe timeout.");
response.setStatus(100);
return response;
}
//System.out.println("plan id in session:"+plan.getPlan_id());
if (request.getSharedobject_tag() == null || request.getSharedobject_tag().length() < 1) {
response.setMessage("idl tag is empty!");
response.setStatus(100);
return response;
}
plan.setSharedobject_tag(request.getSharedobject_tag());
plan.setMemo(request.getMemo());
//check if saved
ReleasePlan plan2 = (ReleasePlan) session.getAttribute("plan");
//System.out.println("so tag:"+plan2.getSharedobject_tag());
// Commit Plan
String commitResult = CommitPlan(plan2);
if (commitResult == null || !commitResult.equals("success")) {
response.setMessage("commit failed:" + (commitResult == null ? "" : commitResult));
response.setStatus(100);
return response;
}
response.setPlanDetail(plan2);
response.setMessage("success");
response.setStatus(0);
return response;
}
Aggregations