本文整理汇总了Java中com.google.code.kaptcha.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于com.google.code.kaptcha包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
/**
* 生成验证码的逻辑
*/
@RequestMapping("verify")
private ModelAndView verify(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpSession session = request.getSession();
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
String capText = captchaProducer.createText();
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
return null;
}
示例2: testCreateColorFromFieldValueWithInvalidFieldValueThrowsConfigException
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
public void testCreateColorFromFieldValueWithInvalidFieldValueThrowsConfigException()
{
try
{
helper.createColorFromFieldValue(Constants.KAPTCHA_BORDER_COLOR,
"Katie Lloyd");
fail("ConfigException should've been thrown.");
}
catch (ConfigException ce)
{
assertEquals(
"Invalid value 'Katie Lloyd' for config parameter 'kaptcha.border.color'.",
ce.getMessage());
assertTrue(ce.getCause() instanceof NoSuchFieldException);
}
}
示例3: captcha
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
示例4: login
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
/**
* 登录
*/
@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
public Map<String, Object> login(String username, String password, String captcha)throws IOException {
String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
if(!captcha.equalsIgnoreCase(kaptcha)){
return R.error("验证码不正确");
}
//用户信息
SysUserEntity user = sysUserService.queryByUserName(username);
//账号不存在、密码错误
if(user == null || !user.getPassword().equals(new Sha256Hash(password, user.getSalt()).toHex())) {
return R.error("账号或密码不正确");
}
//账号锁定
if(user.getStatus() == 0){
return R.error("账号已被锁定,请联系管理员");
}
//生成token,并保存到数据库
R r = sysUserTokenService.createToken(user.getUserId());
return r;
}
示例5: login
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping(value="/login",method=RequestMethod.POST)
public ModelAndView login(User user, String captcha, HttpSession session,HttpServletRequest request) throws Exception{
ModelAndView mv = new ModelAndView();
String kaptchaExpected = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
System.out.println(kaptchaExpected);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(),user.getPassword());
try{
subject.login(token);
mv.setViewName("redirect:/index.jsp");
} catch (AuthenticationException e){
mv.addObject("message", "login errors");
mv.setViewName("redirect:/backend/login");
}
return mv;
}
示例6: captcha
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
示例7: preChecks
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
private void preChecks(UsernamePasswordAuthenticationToken authentication)throws AuthenticationException{
boolean useCaptcha=Configure.getBoolean("bdf2.useCaptchaForLogin");
if(useCaptcha){
String key=ContextHolder.getRequest().getParameter("captcha_");
if(StringUtils.isNotEmpty(key)){
String sessionkey=(String)ContextHolder.getHttpSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
if(sessionkey==null){
throw new BadCredentialsException("验证码过期");
}else if(!sessionkey.equals(key)){
throw new BadCredentialsException("验证码不正确");
}
}else{
throw new BadCredentialsException("验证码不能为空");
}
}
if (authentication.getPrincipal() == null) {
throw new BadCredentialsException("Username can not be null");
}
if (authentication.getCredentials() == null) {
throw new BadCredentialsException("password can not be null");
}
}
示例8: login
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping(value="/login",method=RequestMethod.POST)
public ModelAndView login(User user, String captcha, HttpSession session,HttpServletRequest request) throws Exception{
ModelAndView mv = new ModelAndView();
String kaptchaExpected = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
//--System.out.println(kaptchaExpected);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(),user.getPassword());
try{
subject.login(token);
System.out.println(subject.getSession().getId());
System.out.println(session.getId());
mv.setViewName("redirect:/hello");
} catch (AuthenticationException e){
mv.addObject("message", "login errors");
mv.setViewName("redirect:/backend/login");
}
return mv;
}
示例9: handleRequest
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping("/captcha/kaptcha-image.do")
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
// Header Preparation for Image creation
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
// Generation of Captcha Text
String capText = captchaProducer.createText();
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
// Generation of the image
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
return null;
}
示例10: generateCapcha
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@ResponseBody
@RequestMapping(value = "/captcha.jpg",method = {RequestMethod.GET})
public byte[] generateCapcha() throws Exception{
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpg");
String capText = captchaProducer.createText();
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
BufferedImage bi = captchaProducer.createImage(capText);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(bi, "jpg", out);
return out.toByteArray();
}
示例11: getKaptchaImage
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
@RequestMapping(value = "kaptcha.jpg")
public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
String capText = captchaProducer.createText();
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
try (ServletOutputStream out = response.getOutputStream()) {
ImageIO.write(captchaProducer.createImage(capText), "jpg", out);
out.flush();
}
return null;
}
示例12: attemptAuthentication
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
String kaptcha = request.getParameter("kaptcha");
String captcha = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
if (!captcha.contentEquals(kaptcha)) {
throw new KaptchaNotMatchException("captcha not matched!");
}
String username = obtainUsername(request);
String password = obtainPassword(request);
UsernamePasswordAuthenticationToken authRequest
= new UsernamePasswordAuthenticationToken(username, password);
setDetails(request, authRequest);
return this.getAuthenticationManager().authenticate(authRequest);
}
示例13: testGetClassInstanceWithNonExistantClassThrowsConfigException
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
public void testGetClassInstanceWithNonExistantClassThrowsConfigException()
{
try
{
helper.getClassInstance(Constants.KAPTCHA_BACKGROUND_IMPL,
"com.google.code.kaptcha.BostonLegal", new Object(),
new Config(new Properties()));
fail("ConfigException should've been thrown.");
}
catch (ConfigException ce)
{
assertEquals(
"Invalid value 'com.google.code.kaptcha.BostonLegal' for config parameter 'kaptcha.background.impl'.",
ce.getMessage());
assertTrue(ce.getCause() instanceof ClassNotFoundException);
}
}
示例14: testGetFontsWithNullValueGivesDefaultFonts
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
public void testGetFontsWithNullValueGivesDefaultFonts()
{
Font[] defaultFonts = new Font[]{
new Font("Arial", Font.BOLD, 11),
new Font("Courier", Font.BOLD, 11)
};
Font[] fonts = helper.getFonts(
Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, null, 12,
defaultFonts);
assertEquals("Arial", fonts[0].getFamily());
assertEquals(Font.BOLD, fonts[0].getStyle());
assertEquals(11, fonts[0].getSize());
assertEquals("Courier", fonts[1].getFamily());
assertEquals(Font.BOLD, fonts[1].getStyle());
assertEquals(11, fonts[1].getSize());
}
示例15: testGetFontsWithEmptyValueGivesDefaultFonts
import com.google.code.kaptcha.Constants; //导入依赖的package包/类
public void testGetFontsWithEmptyValueGivesDefaultFonts()
{
Font[] defaultFonts = new Font[]{
new Font("Arial", Font.BOLD, 11),
new Font("Courier", Font.BOLD, 11)
};
Font[] fonts = helper
.getFonts(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "", 12,
defaultFonts);
assertEquals("Arial", fonts[0].getFamily());
assertEquals(Font.BOLD, fonts[0].getStyle());
assertEquals(11, fonts[0].getSize());
assertEquals("Courier", fonts[1].getFamily());
assertEquals(Font.BOLD, fonts[1].getStyle());
assertEquals(11, fonts[1].getSize());
}