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


Java SwitchUserFilter类代码示例

本文整理汇总了Java中org.springframework.security.web.authentication.switchuser.SwitchUserFilter的典型用法代码示例。如果您正苦于以下问题:Java SwitchUserFilter类的具体用法?Java SwitchUserFilter怎么用?Java SwitchUserFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SwitchUserFilter类属于org.springframework.security.web.authentication.switchuser包,在下文中一共展示了SwitchUserFilter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: switchToUser

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
/**
 * Change le rôle de l'utilisateur courant
 * 
 * @param username
 *            le nom de l'utilisateur a prendre
 */
public void switchToUser(String username) {
	Assert.hasText(username, applicationContext.getMessage("assert.hasText", null, UI.getCurrent().getLocale()));

	/* Vérifie que l'utilisateur existe */
	try {
		UserDetails details = userDetailsService.loadUserByUsername(username);
		if (details == null || details.getAuthorities() == null || details.getAuthorities().size() == 0) {
			Notification.show(applicationContext.getMessage("admin.switchUser.usernameNotFound",
					new Object[] { username }, UI.getCurrent().getLocale()), Notification.Type.WARNING_MESSAGE);
			return;
		}
	} catch (UsernameNotFoundException unfe) {
		Notification.show(applicationContext.getMessage("admin.switchUser.usernameNotFound",
				new Object[] { username }, UI.getCurrent().getLocale()), Notification.Type.WARNING_MESSAGE);
		return;
	}
	String switchToUserUrl = MethodUtils.formatSecurityPath(loadBalancingController.getApplicationPath(false),
			ConstanteUtils.SECURITY_SWITCH_PATH) + "?" + SwitchUserFilter.SPRING_SECURITY_SWITCH_USERNAME_KEY + "="
			+ username;
	Page.getCurrent().open(switchToUserUrl, null);
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:28,代码来源:UserController.java

示例2: configure

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
/**
 * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)
 */
@Override
protected void configure(HttpSecurity http) throws Exception {
	http.exceptionHandling()
			.authenticationEntryPoint(casEntryPoint())
			.and()
		.authorizeRequests()
			.antMatchers(ConstanteUtils.SECURITY_CONNECT_PATH+"/**").authenticated()
			.antMatchers("/**").permitAll()
			.antMatchers(ConstanteUtils.SECURITY_SWITCH_PATH).hasAuthority(NomenclatureUtils.DROIT_PROFIL_ADMIN)
			.antMatchers(ConstanteUtils.SECURITY_SWITCH_BACK_PATH).hasAuthority(SwitchUserFilter.ROLE_PREVIOUS_ADMINISTRATOR)
			.anyRequest().authenticated()
			.and()
		.addFilterBefore(singleSignOutFilter(), LogoutFilter.class)
		.addFilter(new LogoutFilter(casUrl + ConstanteUtils.SECURITY_LOGOUT_PATH, new SecurityContextLogoutHandler()))
		.addFilter(casAuthenticationFilter())
		.addFilterAfter(switchUserFilter(), FilterSecurityInterceptor.class)
		/* La protection Spring Security contre le Cross Scripting Request Forgery est désactivée, Vaadin implémente sa propre protection */
		.csrf().disable()
		.headers()
			/* Autorise l'affichage en iFrame */
			.frameOptions().disable()
			/* Supprime la gestion du cache du navigateur, pour corriger le bug IE de chargement des polices cf. http://stackoverflow.com/questions/7748140/font-face-eot-not-loading-over-https */
			.cacheControl().disable();
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:28,代码来源:SecurityConfig.java

示例3: doConfigure

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
@Override
protected void doConfigure(HttpSecurity http) throws Exception {
	http.authorizeRequests()
			// The order of the matchers matters
			.antMatchers(HttpMethod.OPTIONS, REST_API_URL_PREFIX + "/**")
			.permitAll()
			// The REST ping service is temporarily authenticated (see PIVOT-3149)
			.antMatchers(url(REST_API_URL_PREFIX, PING_SUFFIX))
			.hasAnyAuthority(ROLE_USER, ROLE_TECH)
			// REST services
			.antMatchers(REST_API_URL_PREFIX + "/**")
			.hasAnyAuthority(ROLE_USER)
			// One has to be a user for all the other URLs
			.antMatchers("/**")
			.hasAuthority(ROLE_USER)
			.and()
			.httpBasic()
			// SwitchUserFilter is the last filter in the chain. See FilterComparator class.
			.and()
			.addFilterAfter(activePivotConfig.contextValueFilter(), SwitchUserFilter.class);
}
 
开发者ID:activeviam,项目名称:autopivot,代码行数:22,代码来源:SecurityConfig.java

示例4: isUserSwitched

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
/**
 * @return true si l'utilisateur a pris le rôle d'un autre utilisateur
 */
public boolean isUserSwitched() {
	Authentication auth = getCurrentAuthentication();
	if (auth == null) {
		return false;
	}
	return auth.getAuthorities().stream().map(GrantedAuthority::getAuthority)
			.filter(Predicate.isEqual(SwitchUserFilter.ROLE_PREVIOUS_ADMINISTRATOR)).findAny().isPresent();
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:12,代码来源:UserController.java

示例5: configure

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
@Override
        protected void configure(HttpSecurity http) throws Exception {
            final String uiPrefix = "/ui/";
            final String loginUrl = uiPrefix + "login.html";

            TokenAuthFilterConfigurer<HttpSecurity> tokenFilterConfigurer =
                    new TokenAuthFilterConfigurer<>(new RequestTokenHeaderRequestMatcher(),
                            new TokenAuthProvider(tokenValidator, userDetailsService, authProcessor));
            http.csrf().disable()
                    .authenticationProvider(provider).userDetailsService(userDetailsService)
                    .anonymous().principal(SecurityUtils.USER_ANONYMOUS).and()
                    .authorizeRequests().antMatchers(uiPrefix + "/token/login").permitAll()
                    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()//allow CORS option calls
                    .antMatchers(uiPrefix + "**").authenticated()
                    .and().headers().cacheControl().disable()
                    .and().formLogin().loginPage(loginUrl).permitAll().defaultSuccessUrl(uiPrefix)
                    .and().logout().logoutUrl(uiPrefix + "logout").logoutSuccessUrl(loginUrl)
                    .and().apply(tokenFilterConfigurer);
//                enable after testing
//                        .and().sessionManagement()
//                        .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

            // X-Frame-Options
            http.headers()
              .frameOptions().sameOrigin();

            http.addFilterAfter(new AccessContextFilter(aclContextFactory), SwitchUserFilter.class);

            //we use basic in testing and scripts
            if (basicAuthEnable) {
                http.httpBasic();
            }

        }
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:35,代码来源:ServletContainerConfiguration.java

示例6: switchUserFilter

import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; //导入依赖的package包/类
@Bean
public SwitchUserFilter switchUserFilter(UserDetailsService userDetailsService) {
    SwitchUserFilter suFilter = new SwitchUserFilter();
    suFilter.setUserDetailsService(userDetailsService);
    suFilter.setSuccessHandler((httpServletRequest, httpServletResponse, authentication) -> {
        String url = httpServletRequest.getHeader("referer");
        if (url == null) {
            httpServletResponse.sendRedirect("/");
        } else {
            httpServletResponse.sendRedirect(url);
        }
    });
    return suFilter;
}
 
开发者ID:mattpwest,项目名称:entelect-spring-webapp-template,代码行数:15,代码来源:SpringSecurityConfig.java


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