本文整理汇总了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 + "'");
}
};
}
示例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 + "]不存在");
}
}
};
}
示例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");
}
}
};
}
示例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 + "'");
}
}
};
}
示例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"));
};
}
示例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
}
示例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
}
示例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;
}
示例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";
}
示例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);
}
示例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;
}
示例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.");
}
示例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"));
}