Skip to content

Commit

Permalink
http://jeesite.net/forum.php?mod=viewthread&tid=402&extra=page%3D1
Browse files Browse the repository at this point in the history
  • Loading branch information
think-gem committed Dec 31, 2016
1 parent 82b9ecc commit cfb80fd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/com/thinkgem/jeesite/common/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
Expand Down Expand Up @@ -45,6 +46,17 @@ public static byte[] getBytes(String str){
}
}

/**
* 转换为Boolean类型
* 'true', 'on', 'y', 't', 'yes' or '1' (case insensitive) will return true. Otherwise, false is returned.
*/
public static Boolean toBoolean(final Object val){
if (val == null){
return false;
}
return BooleanUtils.toBoolean(val.toString()) || "1".equals(val.toString());
}

/**
* 转换为字节数组
* @param str
Expand All @@ -58,6 +70,17 @@ public static String toString(byte[] bytes){
}
}

/**
* 如果对象为空,则使用defaultVal值
* see: ObjectUtils.toString(obj, defaultVal)
* @param obj
* @param defaultVal
* @return
*/
public static String toString(final Object obj, final String defaultVal) {
return obj == null ? defaultVal : obj.toString();
}

/**
* 是否包含字符串
* @param str 验证字符串
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ protected AuthenticationToken createToken(ServletRequest request, ServletRespons
boolean mobile = isMobileLogin(request);
return new UsernamePasswordToken(username, password.toCharArray(), rememberMe, host, captcha, mobile);
}

/**
* 获取登录用户名
*/
protected String getUsername(ServletRequest request, ServletResponse response) {
String username = super.getUsername(request);
if (StringUtils.isBlank(username)){
username = StringUtils.toString(request.getAttribute(getUsernameParam()), StringUtils.EMPTY);
}
return username;
}

/**
* 获取登录密码
*/
@Override
protected String getPassword(ServletRequest request) {
String password = super.getPassword(request);
if (StringUtils.isBlank(password)){
password = StringUtils.toString(request.getAttribute(getPasswordParam()), StringUtils.EMPTY);
}
return password;
}

/**
* 获取记住我
*/
@Override
protected boolean isRememberMe(ServletRequest request) {
String isRememberMe = WebUtils.getCleanParam(request, getRememberMeParam());
if (StringUtils.isBlank(isRememberMe)){
isRememberMe = StringUtils.toString(request.getAttribute(getRememberMeParam()), StringUtils.EMPTY);
}
return StringUtils.toBoolean(isRememberMe);
}

public String getCaptchaParam() {
return captchaParam;
Expand Down

0 comments on commit cfb80fd

Please sign in to comment.