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


Java AuthorityUtils.createAuthorityList方法代码示例

本文整理汇总了Java中org.springframework.security.core.authority.AuthorityUtils.createAuthorityList方法的典型用法代码示例。如果您正苦于以下问题:Java AuthorityUtils.createAuthorityList方法的具体用法?Java AuthorityUtils.createAuthorityList怎么用?Java AuthorityUtils.createAuthorityList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.core.authority.AuthorityUtils的用法示例。


在下文中一共展示了AuthorityUtils.createAuthorityList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
@Override
public UserDetailsService userDetailsService() {
    return username -> {
        UserAccount account = userAccountService.findByUsername(username);
        if(account != null) {
            RequestContext.getInstance().set(account);

            return new User(account.getUserName(), account.getPassword(),
                    account.getEnabled(), account.getAccountNonExpired(),
                    true, account.getAccountNonLocked(),
                    AuthorityUtils.createAuthorityList(account.getAuthorities()));
        } else {
            throw new UsernameNotFoundException("could not find the user '"
                    + username + "'");
        }
    };
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:19,代码来源:DataGateSecurityConfigurer.java

示例2: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
public UserDetailsService userDetailsService() {
	return new UserDetailsService() {
		@Override
		public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
			// 通过用户名获取用户信息
			Account account = accountRepository.findByName(name);
			if (account != null) {
				// 创建spring security安全用户
				User user = new User(account.getName(), account.getPassword(),
						AuthorityUtils.createAuthorityList(account.getRoles()));
				return user;
			} else {
				throw new UsernameNotFoundException("用户[" + name + "]不存在");
			}
		}
	};

}
 
开发者ID:leftso,项目名称:demo-spring-boot-security-oauth2,代码行数:20,代码来源:SecurityConfiguration.java

示例3: getAuthentication

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
/**
 * Provide the mock user information to be used
 * 
 * @param withMockOAuth2Token
 * @return
 */
private Authentication getAuthentication(WithMockOAuth2Token withMockOAuth2Token) {
	List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(withMockOAuth2Token.authorities());

	User userPrincipal = new User(withMockOAuth2Token.userName(), withMockOAuth2Token.password(), true, true, true,
			true, authorities);

	HashMap<String, String> details = new HashMap<String, String>();
	details.put("user_name", withMockOAuth2Token.userName());
	details.put("email", "[email protected]");
	details.put("name", "Anil Allewar");

	TestingAuthenticationToken token = new TestingAuthenticationToken(userPrincipal, null, authorities);
	token.setAuthenticated(true);
	token.setDetails(details);

	return token;
}
 
开发者ID:anilallewar,项目名称:microservices-basics-spring-boot,代码行数:24,代码来源:WithOAuth2MockAccessTokenSecurityContextFactory.java

示例4: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
UserDetailsService userDetailsService() {
    return username -> {
        LOGGER.debug(String.format("Looking for user [%s]", username));
        Account account = accountRepository.findByUsername(username);
        if (account != null) {
            LOGGER.info(String.format("Found user [%s]", username));
            return new User(account.getUsername(), account.getPassword(),
                    true, true, true, true,
                    AuthorityUtils.createAuthorityList("USER"));
        } else {
            LOGGER.info(String.format("Couldn't find user [%s]", username));
            throw new UsernameNotFoundException(String.format("couldn't find the user '%s'", username));
        }
    };
}
 
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-protocol-poc,代码行数:17,代码来源:WebSecurityAuthenticationConfigurer.java

示例5: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
public UserDetailsService userDetailsService() {
    return new UserDetailsService() {
        public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
            User user = dao.getUserByEmail(email);

            if(user != null) {
                return new org.springframework.security.core.userdetails.User(
                        user.getEmail(),
                        user.getPassword(),
                        user.valid(),
                        true,
                        true,
                        true,
                        AuthorityUtils.createAuthorityList(user.fetchAuthorities())
                );
            }
            else {
                throw new UsernameNotFoundException("Could not find that user");
            }
        }
    };
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:24,代码来源:WebSecurityConfig.java

示例6: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
UserDetailsService userDetailsService() {
	return new UserDetailsService() {

		@Override
		public UserDetails loadUserByUsername(String email)
				throws UsernameNotFoundException {
			Account account = (Account) accountRepository
					.findByEmailAddress(email);
			if (account != null) {
				return new WebUser(account.getEmailAddress(),
						account.getCryptedPassword(), account.getActive(),
						true, true, true,
						AuthorityUtils.createAuthorityList("USER"), account);
			} else {
				throw new UsernameNotFoundException(
						"could not find the user '" + email + "'");
			}
		}

	};
}
 
开发者ID:petabyte-research,项目名称:redflags,代码行数:23,代码来源:SecurityCfg.java

示例7: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
public UserDetailsService userDetailsService() {
    return username -> {

        Optional<Account> accountOptional = accountRepository.findByUsername(username);

        if (!accountOptional.isPresent()) {
            throw new UsernameNotFoundException("Could not find the user '" + username + "'");
        }

        Account account = accountOptional.get();

        return new User(account.getUsername(), account.getPassword(), true, true, true, true,
                AuthorityUtils.createAuthorityList("USER"));
    };
}
 
开发者ID:stevesoltys,项目名称:carrier,代码行数:17,代码来源:WebSecurityConfiguration.java

示例8: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Bean
UserDetailsService userDetailsService(JdbcTemplate jdbcTemplate) {
	// @formatter:off
	RowMapper<User> userDetailsRowMapper = (rs, i) -> new User(
			rs.getString("ACCOUNT_NAME"),
			rs.getString("PASSWORD"),
			rs.getBoolean("ENABLED"),
			rs.getBoolean("ENABLED"),
			rs.getBoolean("ENABLED"),
			rs.getBoolean("ENABLED"),
			AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
	return username -> jdbcTemplate.queryForObject(
			"select * from ACCOUNT where ACCOUNT_NAME = ?", userDetailsRowMapper,
			username);
	// @formatter:on
}
 
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:17,代码来源:SsoAuthServerApplication.java

示例9: userDetailsService

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
@Bean
public UserDetailsService userDetailsService() {
    // @formatter:off
    RowMapper<User> userRowMapper = (rs, i) -> new User(
            rs.getString("ACCOUNT_NAME"),
            rs.getString("PASSWORD"),
            rs.getBoolean("ENABLED"),
            rs.getBoolean("ENABLED"),
            rs.getBoolean("ENABLED"),
            rs.getBoolean("ENABLED"),
            AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    return username -> this.jdbcTemplate.queryForObject(
            "select * from ACCOUNT where ACCOUNT_NAME = ?", userRowMapper, username);
    // @formatter:on
}
 
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:17,代码来源:SecurityConfig.java

示例10: getAuthorities

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
private static Collection<? extends GrantedAuthority> getAuthorities(User user)
{
	Set<String> roleAndPermissions = new HashSet<>();
	List<Role> roles = user.getRoles();
	
	for (Role role : roles)
	{
		roleAndPermissions.add(role.getName());
		List<Permission> permissions = role.getPermissions();
		for (Permission permission : permissions)
		{
			roleAndPermissions.add("ROLE_"+permission.getName());
		}
	}
	String[] roleNames = new String[roleAndPermissions.size()];
	Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(roleAndPermissions.toArray(roleNames));
	return authorities;
}
 
开发者ID:sivaprasadreddy,项目名称:jcart,代码行数:19,代码来源:AuthenticatedUser.java

示例11: doRegister

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@RequestMapping(value="/register", method = RequestMethod.POST)
public String doRegister(@Valid @ModelAttribute("user") User user, BindingResult result, RedirectAttributes redirectAttributes) {
	if (result.hasErrors()) {
		return "register";
	}
	userService.save(user);
	List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
	UserDetails userDetails = new org.springframework.security.core.userdetails
			.User(user.getName(), user.getPassword(), authorities);
	
	Authentication auth = 
			new UsernamePasswordAuthenticationToken(userDetails, user.getPassword(), authorities);
	
	SecurityContextHolder.getContext().setAuthentication(auth);
	redirectAttributes.addFlashAttribute("registerMessage", "You have been signed up Successfully...!");
	//return "redirect:/login.html?success=true";
	return "redirect:/account";
}
 
开发者ID:RawSanj,项目名称:spring-tiles-sample-app,代码行数:19,代码来源:RegisterController.java

示例12: loadUserByUsername

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
    UserCredential userCredential = null;
    try {
        userCredential = shopDao.getUserByName(name);
    } catch (ObjectNotFoundException e) {
        logger.error("UserCredential object not found for login: " + name);
        e.printStackTrace();
    }
    if (userCredential == null) {
        throw new UsernameNotFoundException("User with username: " + name + " not found.");
    }

    Collection<? extends GrantedAuthority> authorities =
            AuthorityUtils.createAuthorityList(ROLE_PREFIX + userCredential.getRole());

    return new User(userCredential.getLogin(), userCredential.getPass(), authorities);
}
 
开发者ID:ysalmin,项目名称:spring-app-store,代码行数:19,代码来源:ShoppingCartUserDetailsService.java

示例13: retrieveUser

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    log.trace("retrieveUser()");
    log.debug("retrieving user: " + username);
    User user;
    try {
         user= this.read(username);
    }
    catch(Exception e){
        throw new UsernameNotFoundException("User " + username + " cannot be found");
    }

    String userName = user.getName();
    String pw = user.getPassword();
    String role = user.getRole();
    Collection<GrantedAuthority> auths = AuthorityUtils.createAuthorityList(role);
    boolean enabled = user.getActive();

    UserDetails userDetails = new org.springframework.security.core.userdetails.User(userName, pw, enabled, true, true, true, auths);
    log.debug("returning new userDetails: " + userDetails);
    return userDetails;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:24,代码来源:HSQLAuthenticationProvider.java

示例14: loadUserByUsername

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
/**
 * 获取用户信息,设置角色
 */
@Override
public UserDetails loadUserByUsername(String username)
		throws UsernameNotFoundException {
	// 获取用户信息
	MangoUser mangoUser = userService.getUserByName(username);
	if (mangoUser != null) {
		// 设置角色
		return new User(mangoUser.getUserName(), mangoUser.getPassword(),
				AuthorityUtils.createAuthorityList(mangoUser.getRole()));
	}

	throw new UsernameNotFoundException("User '" + username
			+ "' not found.");
}
 
开发者ID:honghailiang,项目名称:SpringMango,代码行数:18,代码来源:MyUserDetailsService.java

示例15: loadUserByUsername

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    return new User(
            username,
            "notUsed",
            true,
            true,
            true,
            true,
            AuthorityUtils.createAuthorityList("ROLE_USER"));
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:12,代码来源:KerberosUserDetailsService.java


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