1 19 package org.netbeans.modules.exceptions.web; 20 21 import java.security.NoSuchAlgorithmException ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionMapping; 26 import org.apache.struts.action.ActionForward; 27 import org.netbeans.modules.exceptions.entity.Issue; 28 33 34 public class MapIssueAction extends MyAction { 35 36 37 private final static String SUCCESS = "success"; 38 private final static String ERROR = "error"; 39 40 49 public ActionForward execute(ActionMapping mapping, ActionForm form, 50 HttpServletRequest request, HttpServletResponse response) 51 throws Exception { 52 Integer id = null; 53 Integer issuezillaId = null; 54 String sum = request.getParameter("sum"); 55 try { 56 id = new Integer (request.getParameter("id")); 57 issuezillaId = new Integer (request.getParameter("issue")); 58 } catch (NumberFormatException e) { 59 return mapping.findForward(ERROR); 60 } 61 if (!md5sum(id + "=" + issuezillaId).equals(sum)) return mapping.findForward(ERROR); 62 Issue issue = (Issue) getEntity(Issue.class, id); 63 issue.setIssuezillaid(issuezillaId); 64 merge(issue); 65 request.setAttribute("issue", issue); 66 return mapping.findForward(SUCCESS); 67 } 68 69 private String md5sum(String str) { 70 StringBuffer sum = new StringBuffer (); 71 try { 72 java.security.MessageDigest md5 = java.security.MessageDigest.getInstance("MD5"); 73 md5.update(str.getBytes()); 74 byte[] sign = md5.digest(); 75 for (byte b : sign) { 76 sum.append(byteToHex(b)); 77 } 78 } catch (NoSuchAlgorithmException ex) { 79 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, 80 ex.getMessage(), ex); 81 } 82 return sum.toString(); 83 } 84 85 private String byteToHex(byte data) { 86 StringBuffer buf = new StringBuffer (); 87 buf.append(Character.forDigit((data >>> 4) & 0x0F, 16)); 88 buf.append(Character.forDigit((data & 0x0F), 16)); 89 return buf.toString(); 90 } 91 } 92 | Popular Tags |