本文整理匯總了Java中org.apache.shiro.web.util.WebUtils.getAndClearSavedRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java WebUtils.getAndClearSavedRequest方法的具體用法?Java WebUtils.getAndClearSavedRequest怎麽用?Java WebUtils.getAndClearSavedRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.getAndClearSavedRequest方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: issueSuccessRedirect
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
protected void issueSuccessRedirect(ServletRequest request, ServletResponse response)
throws Exception {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String successUrl = req.getParameter(RETURN_URL);
if (StringUtils.isBlank(successUrl)) {
if (req.getRequestURI().startsWith(
req.getContextPath() + getAdminPrefix())) {
// 後台直接返回首頁
successUrl = getAdminIndex();
// 清除SavedRequest
WebUtils.getAndClearSavedRequest(request);
WebUtils.issueRedirect(request, response, successUrl, null,true);
return;
} else {
successUrl = getSuccessUrl();
}
}
WebUtils.redirectToSavedRequest(req, res, successUrl);
}
示例2: doPost
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
public void doPost(MCRServletJob job) throws Exception {
Element output = new Element("userLogging");
String username = getParameter(job, "username");
String password = getParameter(job, "password");
boolean rememberMe = "true".equals(getParameter(job, "rememberMe"));
boolean b = false;
if (username == null)
output.addContent((new Element("message")).addContent("login.message.noUserGiven"));
else if (password == null)
output.addContent((new Element("message")).addContent("login.message.noPasswordGiven"));
else {
b = tryLogin(username, password, rememberMe);
if (b) {
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(job.getRequest());
if (savedRequest != null)
job.getResponse().sendRedirect(savedRequest.getRequestUrl());
else
job.getResponse().sendRedirect("analysis/start");
} else
output.addContent((new Element("message")).addContent("login.message.loginFailed"));
}
sendOutput(job, output);
}
示例3: redirectUrl
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
* 返回重定向的頁麵地址
* @param request
*/
protected String redirectUrl(HttpServletRequest request){
String targetUrl=request.getParameter("targetUrl");//獲取目標url
if(StringUtil.isNull(targetUrl)){
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);//獲取攔截的url
if(savedRequest!=null){
targetUrl = savedRequest.getRequestUrl();
}
try{
if(StringUtil.isNotNull(targetUrl)){
return URLDecoder.decode(targetUrl,"UTF-8");
}
}catch (Exception e){
e.printStackTrace();
}
return request.getContextPath()+"/index.html";
}
return targetUrl;
}
示例4: redirectTarget
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
* 重定向到目標頁麵
* @param request
* @param response
*/
protected void redirectTarget(HttpServletRequest request,HttpServletResponse response){
String targetUrl=null;
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);//獲取攔截的url
if(savedRequest!=null){
targetUrl = savedRequest.getRequestUrl();
}
try{
if(StringUtil.isNotNull(targetUrl)){
response.sendRedirect(URLDecoder.decode(targetUrl,"UTF-8"));
}else{
response.sendRedirect(request.getContextPath()+"/index.html");
}
}catch (Exception e){
e.printStackTrace();
}
}
示例5: login
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
@POST
@Path("login")
public Response login(@NotNull @FormParam("username") String username,
@NotNull @FormParam("password") String password,
@NotNull @FormParam("rememberMe") boolean rememberMe,
@Context HttpServletRequest request) {
boolean justLogged = SecurityUtils.getSubject().isAuthenticated();
try {
SecurityUtils.getSubject().login(new UsernamePasswordToken(username, password, rememberMe));
} catch (Exception e) {
throw new IncorrectCredentialsException("Unknown user, please try again");
}
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
monitoring.fire(new AuthenticationEvent(username, AuthenticationEvent.Type.LOGIN));
if (savedRequest != null) {
return this.getRedirectResponse(savedRequest.getRequestUrl(), request);
} else {
if (justLogged) {
return this.getRedirectResponse(WebPages.DASHBOARD_URL, request);
}
return this.getRedirectResponse(WebPages.HOME_URL, request);
}
}
示例6: onForwardUrl
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
* 獲取重定向跳轉url
*/
public String onForwardUrl(ServletRequest request) {
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
String url = getSuccessUrl();
if (savedRequest != null
&& savedRequest.getMethod().equalsIgnoreCase(
AccessControlFilter.GET_METHOD)) {
url = savedRequest.getRequestUrl();
request.setAttribute("backUrl", url);
}
return url;
}
示例7: login
import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
private Response login(
HttpServletRequest request,
ServletContext servletContext,
UriInfo uriInfo,
String username,
String password,
String ftlFile) {
username = StringUtils.trimToNull(username);
password = StringUtils.trimToNull(password);
if (username == null) {
return displayError(servletContext, uriInfo, username, ftlFile, "UserNameMissing");
}
if (password == null) {
return displayError(servletContext, uriInfo, username, ftlFile, "PasswordMissing");
}
String ipAddress = findIpAddress(request);
UsernamePasswordToken token = new UsernamePasswordToken(username, password, false, ipAddress);
try {
Subject subject = AuthUtils.getSubject();
subject.login(token);
token.clear();
URI successUrl = null;
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
if (savedRequest != null && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)) {
successUrl = uriInfo.getBaseUri().resolve(savedRequest.getRequestUrl());
} else {
if (ftlFile.equals(LOGIN_GREEN)) {
successUrl = WebHomeResource.uri(uriInfo);
} else {
successUrl = uriInfo.getBaseUri().resolve("/");
}
}
return Response.seeOther(successUrl).build();
} catch (AuthenticationException ex) {
String errorCode = StringUtils.substringBeforeLast(ex.getClass().getSimpleName(), "Exception");
return displayError(servletContext, uriInfo, username, ftlFile, errorCode);
}
}