Spring jasypt暗号化

7158 ワード

jasypt-1.9.2.jarのダウンロード
 
 

		
			
				classpath:config.properties
			
		
		
		
			
				orcl.password
				sql.password
			
		

 
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	private Set encryptedProps = Collections.emptySet();

	public void setEncryptedProps(Set encryptedProps) {
		this.encryptedProps = encryptedProps;
	}
	
	@Override
	protected String convertProperty(String propertyName, String propertyValue) {
		if (encryptedProps.contains(propertyName)) {
			return EncryptUtil.decode(propertyValue);
		}
		return super.convertProperty(propertyName, propertyValue);
	}

}

 



	
	
	
    
    
    
    
    
    
    
      
	      
	      
	    
	      
	      
	  
    
      
          
        
          
      


 
public class ExceptionHandler implements HandlerExceptionResolver {
	
	private static Logger LOGGER = LoggerFactory.getLogger(ExceptionHandler.class); 

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception e) {
		LOGGER.error("  :" + e.getMessage(), e);
		ModelAndView mav = new ModelAndView("exception");
		boolean ajaxRequest = isAjaxRequest(request);
		
		//         
		if (e instanceof MaxUploadSizeExceededException) {
			if (ajaxRequest) {
				JSONObject json = new JSONObject();
				json.put(ExceptionConstants.SYS_EXCEPTION_FLAG, true);
				json.put(ExceptionConstants.SYS_EXCEPTION_REASON, "    !");
				
				write(response, json.toString());
				return null;
			} else {
				mav.addObject(ExceptionConstants.SYS_EXCEPTION_REASON, "    !");
				return mav;
			}
		}
		
		//        
		if (e instanceof AppException) {
			if (ajaxRequest) {
				JSONObject json = new JSONObject();
				json.put(ExceptionConstants.SYS_EXCEPTION_FLAG, true);
				json.put(ExceptionConstants.SYS_EXCEPTION_REASON, e.getMessage());
				
				write(response, json.toString());
				return null;
			} else {
				mav.addObject(ExceptionConstants.SYS_EXCEPTION_REASON, e.getMessage());
				return mav;
			}
		}
		
		if (ajaxRequest) {
			JSONObject json = new JSONObject();
			json.put(ExceptionConstants.SYS_EXCEPTION_FLAG, true);
			json.put(ExceptionConstants.SYS_EXCEPTION_REASON, "   ,      !");
			
			write(response, json.toString());
			return null;
		}
		mav.addObject(ExceptionConstants.SYS_EXCEPTION_REASON, "   ,      !");
		return mav;  
	}
	
	/**
	 *      ajax  
	 * @param request
	 * @return
	 */
	private boolean isAjaxRequest(HttpServletRequest request) {
		// jquery 1.7+(       )    XMLHttpRequest   Header    X-Requested-With
		//     jquery   ajax      url  
		String xhr = request.getHeader("X-Requested-With");
		boolean jQueryAjax = "XMLHttpRequest".equals(xhr);
		
		//   url  ajax  
		boolean urlAjax = request.getRequestURI().matches(".*_Ajax$");
		return jQueryAjax || urlAjax;
	}
	
	private void write(HttpServletResponse response, String message)  {
		try {
			response.setContentType("text/json;charset=utf-8");   
			PrintWriter writer = response.getWriter();
			writer.write(message);   
			writer.flush();   
		} catch (IOException e) {
			e.printStackTrace();
		}   
	}
	
}

 
(function($){   
   //  jquery ajax     
   var _ajax=$.ajax;   
      
   //  jquery ajax     
   $.ajax=function(opt){   
       //  opt error success     
       var fn = {   
           error:function(XMLHttpRequest, textStatus, errorThrown){},   
            success:function(data, textStatus){}   
        }   
        if(opt.error){   
            fn.error=opt.error;   
        }   
        if(opt.success){   
            fn.success=opt.success;   
        }   
           
        //         
        var _opt = $.extend(opt,{   
            error:function(XMLHttpRequest, textStatus, errorThrown){   
                //           
            	if (layer) {
            		layer.msg("   ,      !", 2, 3, null, true);
            	} else {
            		alert("   ,      !");
            	}
                fn.error(XMLHttpRequest, textStatus, errorThrown);   
            },   
            success:function(data, textStatus){   
                //             
                var error = data.error;
            	if (error != undefined && error == true) {
            		if (layer) {
            			layer.msg(data.reason, 2, 3, null, true);
            		} else {
            			alert(data.reason);
            		}
					return;
				}
                fn.success(data, textStatus);   
            }   
        });   
        _ajax(_opt);   
    };   
})(jQuery);  

 
@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public void upload(
			@RequestParam("files") CommonsMultipartFile[] files,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
	
		if (files != null || files.length > 0) {
			String fileName = files[0].getOriginalFilename();
			files[0].getInputStream();
			
			// do ...
		}
	}