当前位置: 首页>>代码示例>>Java>>正文


Java AccessControlFilter类代码示例

本文整理汇总了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);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:42,代码来源:WebUtils.java

示例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);
        }
    }
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:12,代码来源:GojaShiroFilter.java

示例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;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:15,代码来源:FormAuthentication2Filter.java

示例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);
        }
    }
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:12,代码来源:CustomDefaultFilterChainManager.java

示例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);
		}
	}
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:13,代码来源:SecurityFilterFactoryBean.java

示例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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:16,代码来源:WebLoginResource.java

示例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);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:41,代码来源:WebLoginResource.java

示例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);
    }
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:10,代码来源:SecurityFilterImpl.java

示例9: addShiroFilter

import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
public void addShiroFilter(String name, AccessControlFilter filter) {
    filterMap.put(name, filter);
}
 
开发者ID:wanghongfei,项目名称:shiro-spring-boot-starter,代码行数:4,代码来源:ShiroFilterRegistry.java

示例10: getFilterMap

import org.apache.shiro.web.filter.AccessControlFilter; //导入依赖的package包/类
public Map<String, AccessControlFilter> getFilterMap() {
    return filterMap;
}
 
开发者ID:wanghongfei,项目名称:shiro-spring-boot-starter,代码行数:4,代码来源:ShiroFilterRegistry.java

示例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);
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:7,代码来源:SecurityFilterImplTest.java

示例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());
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:11,代码来源:SecurityFilterImpl.java


注:本文中的org.apache.shiro.web.filter.AccessControlFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。