本文整理匯總了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);
}
}