本文整理汇总了Java中org.apache.shiro.web.filter.AccessControlFilter类的典型用法代码示例。如果您正苦于以下问题:Java AccessControlFilter类的具体用法?Java AccessControlFilter怎么用?Java AccessControlFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessControlFilter类属于org.apache.shiro.web.filter包,在下文中一共展示了AccessControlFilter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redirectToSavedRequest
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
/**
* Redirects the to the request url from a previously
* {@link #saveRequest(javax.servlet.ServletRequest) saved} request, or if there is no saved request, redirects the
* end user to the specified {@code fallbackUrl}. If there is no saved request or fallback url, this method
* throws an {@link IllegalStateException}.
* <p/>
* This method is primarily used to support a common login scenario - if an unauthenticated user accesses a
* page that requires authentication, it is expected that request is
* {@link #saveRequest(javax.servlet.ServletRequest) saved} first and then redirected to the login page. Then,
* after a successful login, this method can be called to redirect them back to their originally requested URL, a
* nice usability feature.
*
* @param request the incoming request
* @param response the outgoing response
* @param fallbackUrl the fallback url to redirect to if there is no saved request available.
* @throws IllegalStateException if there is no saved request and the {@code fallbackUrl} is {@code null}.
* @throws IOException if there is an error redirecting
* @since 1.0
*/
public static void redirectToSavedRequest(ServletRequest request, ServletResponse response, String fallbackUrl)
throws IOException {
String successUrl = null;
boolean contextRelative = true;
SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
if (savedRequest != null && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)) {
successUrl = savedRequest.getRequestUrl();
contextRelative = false;
}
if (successUrl == null) {
successUrl = fallbackUrl;
}
if (successUrl == null) {
throw new IllegalStateException("Success URL not available via saved request or via the " +
"successUrlFallback method parameter. One of these must be non-null for " +
"issueSuccessRedirect() to work.");
}
WebUtils.issueRedirect(request, response, successUrl, null, contextRelative);
}
示例2: applyLoginUrlIfNecessary
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
private void applyLoginUrlIfNecessary(Filter filter) {
String loginUrl = shiroConfig.getProperty("login.url", "/login");
if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
AccessControlFilter acFilter = (AccessControlFilter) filter;
//only apply the login url if they haven't explicitly configured one already:
String existingLoginUrl = acFilter.getLoginUrl();
if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
acFilter.setLoginUrl(loginUrl);
}
}
}
示例3: onForwardUrl
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的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;
}
示例4: applyLoginUrlIfNecessary
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
private void applyLoginUrlIfNecessary(Filter filter) {
String loginUrl = getLoginUrl();
if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
AccessControlFilter acFilter = (AccessControlFilter) filter;
//only apply the login url if they haven't explicitly configured one already:
String existingLoginUrl = acFilter.getLoginUrl();
if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
acFilter.setLoginUrl(loginUrl);
}
}
}
示例5: applyLoginUrlIfNecessary
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
private void applyLoginUrlIfNecessary(Filter filter) {
String loginUrl = getLoginUrl();
if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
AccessControlFilter acFilter = (AccessControlFilter) filter;
// only apply the login url if they haven't explicitly configured
// one already:
String existingLoginUrl = acFilter.getLoginUrl();
if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
acFilter.setLoginUrl(loginUrl);
}
}
}
示例6: getGreen
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_HTML)
public String getGreen(
@Context HttpServletRequest request,
@Context ServletContext servletContext,
@Context UriInfo uriInfo) {
SavedRequest savedRequest = WebUtils.getSavedRequest(request);
if (savedRequest != null && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)) {
if (savedRequest.getRequestUrl() != null && savedRequest.getRequestUrl().contains("/bundles/fm/prototype/")) {
return getStylish(servletContext, uriInfo);
}
}
return get(servletContext, uriInfo, LOGIN_GREEN);
}
示例7: login
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的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);
}
}
示例8: bindLoginUrlToAccessControlFilter
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
protected void bindLoginUrlToAccessControlFilter() {
AccessControlFilter accessControlFilter =
getAccessControlFilter();
if (accessControlFilter != null) {
log.debug("Bind login url {}", loginUrl);
accessControlFilter.setLoginUrl(loginUrl);
}
}
示例9: addShiroFilter
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
public void addShiroFilter(String name, AccessControlFilter filter) {
filterMap.put(name, filter);
}
示例10: getFilterMap
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
public Map<String, AccessControlFilter> getFilterMap() {
return filterMap;
}
示例11: expectSettingLoginUrl
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
private void expectSettingLoginUrl(String loginUrl) {
AccessControlFilter filterMock = expectGettingFormAuthenticationFilter();
// expect setting login url
filterMock.setLoginUrl(loginUrl);
}
示例12: getAccessControlFilter
import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
/**
* Returns the active {@link AccessControlFilter}. The superclass for any filter that
* controls access to a resource and may redirect the user to the login page if they
* are not authenticated.
*
* @return the active {@link AccessControlFilter}
*/
protected AccessControlFilter getAccessControlFilter() {
return (AccessControlFilter) getFilter(DefaultFilter.authc.toString());
}