本文整理汇总了Java中org.apache.shiro.web.filter.authc.FormAuthenticationFilter类的典型用法代码示例。如果您正苦于以下问题:Java FormAuthenticationFilter类的具体用法?Java FormAuthenticationFilter怎么用?Java FormAuthenticationFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FormAuthenticationFilter类属于org.apache.shiro.web.filter.authc包,在下文中一共展示了FormAuthenticationFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(value = ACTION_INDEX, method = RequestMethod.POST)
public String index(
@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String username,
Map<String, Object> map, HttpServletRequest request,
HttpServletResponse response) {
defaultLocale = request.getLocale();
Shiro shiro = Shiro.get();
if (null != shiro && null != username
&& shiro.getEmail().equals(username)) {
return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_REPOS
+ ACTION_LIST;
}
String message = exception(request);
map.put("message", message);
map.put("username", username);
return PAGE_INDEX;
}
示例2: getShiroFilterFactoryBean
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean(
DefaultWebSecurityManager securityManager,
FormAuthenticationFilter formAuthenticationFilter) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// 必须设置 SecurityManager
shiroFilterFactoryBean.setSecurityManager(securityManager);
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
shiroFilterFactoryBean.setLoginUrl("/oss/login");
// 登录成功后要跳转的连接
shiroFilterFactoryBean.setSuccessUrl("/admin/index");
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
Map map=new HashMap<>();
// map.put("authc",formAuthenticationFilter);
shiroFilterFactoryBean.setFilters(map);
loadShiroFilterChain(shiroFilterFactoryBean);
return shiroFilterFactoryBean;
}
示例3: logLoginStatus
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
private void logLoginStatus(ServletRequest request, LoginType loginType) {
Subject subject = SecurityUtils.getSubject();
if (subject == null) {
return;
}
ShiroUser shiroUser = (ShiroUser) subject.getPrincipal();
String userId = null;
if (shiroUser == null && LoginType.登录失败.equals(loginType)) {
userId = request
.getParameter(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
} else {
userId = shiroUser.loginName;
}
if (StringUtils.isBlank(userId)) {
return;
}
LoginIpDto loginIpDto = new LoginIpDto(userId,
AddressUtil.getIpAddr((HttpServletRequest) request), loginType);
loginIpService.addLoginIp(loginIpDto);
}
示例4: exception
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
private String exception(HttpServletRequest request) {
String error = (String) request
.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
String message = Messages.getMessage("com.chamago.iQuartz.Shiro.Logged",
defaultLocale);
if (error != null) {
if ("org.apache.shiro.authc.UnknownAccountException".equals(error)) {
message = Messages.getMessage("org.ukettle.Shiro.Unknown",
defaultLocale);
} else if ("org.apache.shiro.authc.IncorrectCredentialsException"
.equals(error)) {
message = Messages.getMessage("org.ukettle.Shiro.Pass.Error",
defaultLocale);
} else if ("org.ukettle.shiro.CaptchaException".equals(error)) {
message = Messages.getMessage("org.ukettle.Shiro.Captcha",
defaultLocale);
} else if ("org.apache.shiro.authc.AuthenticationException"
.equals(error)) {
message = Messages.getMessage("org.ukettle.Shiro.Failed",
defaultLocale);
} else if ("org.apache.shiro.authc.DisabledAccountException"
.equals(error)) {
message = Messages.getMessage("org.ukettle.Shiro.Disabled",
defaultLocale);
}
}
return message;
}
示例5: login
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ExceptionForward("/shiro/login")
public String login(HttpServletRequest request) {
String exception = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
if (UnknownAccountException.class.getName().equals(exception)) {
failed("Unknown account.");
} else if (IncorrectCredentialsException.class.getName().equals(exception)) {
failed("Incorrect password.");
} else {
LoggerHelper.error("unknown error : " + exception);
failed("Unknown error.");
}
return "shiro_login";
}
示例6: register
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(method = { RequestMethod.POST })
@ApiOperation(value = "注册", httpMethod = "POST", notes = "注册", response = JsonResponse.class,
produces="application/json",consumes="application/x-www-form-urlencoded")
public RedirectView register(@ApiParam(required=true, value="用户")@Valid SysUser sysUser,
RedirectAttributes redirectAttributes) {
sysUserService.create(sysUser);
redirectAttributes.addFlashAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, sysUser.getLoginName());
return new RedirectView("/login", true, false, false);
//return "redirect:/login";
}
示例7: getFilterChainResolver
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@Produces
public FilterChainResolver getFilterChainResolver() {
FilterChainResolver filterChainResolver = null;
if (filterChainResolver == null) {
FormAuthenticationFilter authc = new FormAuthenticationFilter();
AnonymousFilter anon = new AnonymousFilter();
UserFilter user = new UserFilter();
authc.setLoginUrl(WebPages.LOGIN_URL);
user.setLoginUrl(WebPages.LOGIN_URL);
FilterChainManager fcMan = new DefaultFilterChainManager();
fcMan.addFilter("authc", authc);
fcMan.addFilter("anon", anon);
fcMan.addFilter("user", user);
fcMan.createChain("/index.html", "anon");
fcMan.createChain("/css/**", "anon");
fcMan.createChain("/api/**", "anon");
fcMan.createChain(WebPages.LOGIN_URL, "authc");
fcMan.createChain("/**", "user");
PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver();
resolver.setFilterChainManager(fcMan);
filterChainResolver = resolver;
}
return filterChainResolver;
}
示例8: login
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(value = "/user/login", method = RequestMethod.GET)
public String login(
@RequestParam(value = Constant.USER_STATUS_KEY, defaultValue = Constant.USER_NORMAL_STATUS) String userStatus,
Model model) {
Subject subject = SecurityUtils.getSubject();
if (subject != null && subject.isAuthenticated()) {
return "redirect:/index";
}
// 暂时没有业务逻辑进行处理
if (!Constant.USER_NORMAL_STATUS.equals(userStatus)) {
model.addAttribute(Constant.USER_STATUS_KEY, userStatus);
// return "redirect:/user/onlineStatus";
return "onlineStatus";
}
// 获取记住账号的用户信息
if (subject != null && !subject.isAuthenticated()
&& subject.isRemembered()) {
ShiroUser shiroUser = (ShiroUser) subject.getPrincipal();
if (shiroUser != null) {
// 用户名
model.addAttribute(
FormAuthenticationFilter.DEFAULT_USERNAME_PARAM,
shiroUser.loginName);
}
}
return "login";
}
示例9: fail
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public String fail(
@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName,
HttpServletRequest request, Model model) {
// 用户名
model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM,
userName);
// 登录失败异常
model.addAttribute(
FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME,
request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME));
return "login";
}
示例10: findPassword
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
@RequestMapping(value = "/user/findPassword", method = RequestMethod.POST)
public ModelAndView findPassword(String email, String captcha,
HttpSession session, ModelAndView model) {
try {
model.setViewName("onlineStatus");
if (StringUtils.isBlank(captcha)) {
throw new VerificationException("验证码不允许为空");
}
String code = (String) session
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
if (StringUtils.isBlank(code) || !code.equalsIgnoreCase(captcha)) {
throw new VerificationException("验证码错误");
}
if (!StringUtils.checkEmail(email)) {
throw new VerificationException("邮箱错误");
}
CommonResponseDto response = userService.findPassword(email);
if (response.getResult() == UserConstant.SUCCESS) {
model.addObject(Constant.USER_STATUS_KEY,
Constant.USER_FIND_PASSWORD_SUCCESS);
} else {
throw new VerificationException(response.getErrorMessage());
}
} catch (VerificationException e) {
// 注册失败异常
model.addObject(
FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME,
e.getMessage());
model.addObject(Constant.USER_STATUS_KEY,
Constant.USER_FIND_PASSWORD_FAIL);
}
return model;
}
示例11: configureFormAuthentication
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
/**
* @return the default form authentication mechanism for this realm
*/
private FormAuthenticationFilter configureFormAuthentication() {
final FormAuthenticationFilter formAuthenticator
= new FormAuthenticationFilter();
formAuthenticator.setLoginUrl("/index.xhtml");
formAuthenticator.setSuccessUrl("/secured/dashboard.xhtml");
return formAuthenticator;
}
示例12: configureFormAuthentication
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
/**
* @return the default form authentication mechanism for this realm
*/
private FormAuthenticationFilter configureFormAuthentication() {
final FormAuthenticationFilter formAuthenticator
= new FormAuthenticationFilter();
formAuthenticator.setLoginUrl("/index.xhtml");
formAuthenticator.setSuccessUrl("/secured/index.xhtml");
return formAuthenticator;
}
示例13: fail
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
/**
* @Title: fail
* @Description: TODO(该方法调用前会被Filter拦截,交给shiro验证,如果验证失败会调用该方法)
* @param @param userName
* @param @param model
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/login.htm", method = RequestMethod.POST)
public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM)
String username,String password, Model model,Member member,HttpServletRequest request) {
if (null != SecurityUtils.getSubject() && null != SecurityUtils.getSubject().getSession()) {
SecurityUtils.getSubject().logout();// 进入登录页面,默认把登录用户注销
}
model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, username);
member.setMemberName(username);
member.setMemberPassword(password);
request.setAttribute("member", member);
return "login";
}
示例14: fail
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
/**
* @Title: fail
* @Description: TODO(该方法调用前会被Filter拦截,交给shiro验证,如果验证失败会调用该方法)
* @param @param userName
* @param @param model
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/login.htm", method = RequestMethod.POST)
public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM)
String userName, Model model) {
if (null != SecurityUtils.getSubject() && null != SecurityUtils.getSubject().getSession()) {
SecurityUtils.getSubject().logout();// 进入登录页面,默认把登录用户注销
}
model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName);
return "login";
}
示例15: bindPasswordParamToFormAuthenticationFilter
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; //导入依赖的package包/类
protected void bindPasswordParamToFormAuthenticationFilter() {
FormAuthenticationFilter formAuthenticationFilter = getFormAuthenticationFilter();
if (formAuthenticationFilter != null) {
log.debug("Bind password param {}", passwordParam);
formAuthenticationFilter.setPasswordParam(passwordParam);
}
}