List of usage examples for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority
public SimpleGrantedAuthority(String role)
From source file:ch.javaee.basicMvc.service.MyUserDetailsService.java
/** * Wraps {@link String} roles to {@link SimpleGrantedAuthority} objects * * @param roles {@link String} of roles/*from w ww.j ava 2 s . c om*/ * @return list of granted authorities */ public static List<GrantedAuthority> getGrantedAuthorities(List<String> roles) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String role : roles) { authorities.add(new SimpleGrantedAuthority(role)); } return authorities; }
From source file:com.t2tierp.controller.LoginController.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String nomeUsuario = authentication.getName(); String senha = authentication.getCredentials().toString(); try {//w w w. j a va 2 s.c o m InitialContext initialContext = new InitialContext(); dao = (UsuarioDAO) initialContext.lookup("java:comp/ejb/usuarioDAO"); Md5PasswordEncoder enc = new Md5PasswordEncoder(); senha = enc.encodePassword(nomeUsuario + senha, null); Usuario usuario = dao.getUsuario(nomeUsuario, senha); if (usuario != null) { List<PapelFuncao> funcoes = dao.getPapelFuncao(usuario); List<GrantedAuthority> grantedAuths = new ArrayList<>(); for (PapelFuncao p : funcoes) { grantedAuths.add(new SimpleGrantedAuthority(p.getFuncao().getNome())); } Authentication auth = new UsernamePasswordAuthenticationToken(nomeUsuario, senha, grantedAuths); return auth; } } catch (Exception e) { //e.printStackTrace(); } return null; }
From source file:com.sentinel.service.UserProfileService.java
private final List<GrantedAuthority> getGrantedAuthorities(final List<String> permissions) { final List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (final String permission : permissions) { authorities.add(new SimpleGrantedAuthority(permission)); }/* ww w. j a v a 2 s .com*/ return authorities; }
From source file:org.jasig.portlet.survey.security.uportal.UPortalSecurityFilter.java
private void populateAuthorites(final RenderRequest req, final String principal) { // But the user's access has not yet been established... final Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); boolean isSurveyAdmin = req.isUserInRole("survey-admin"); if (isSurveyAdmin) { authorities.add(new SimpleGrantedAuthority(ROLE_ADMIN)); }/* w ww .jav a 2 s . c om*/ boolean isSurveyUser = req.isUserInRole("survey-user"); if (isSurveyUser) { authorities.add(new SimpleGrantedAuthority(ROLE_USER)); } logger.debug("Setting up GrantedAutorities for user '{}' -- {}", principal, authorities.toString()); final UPortalUserDetails userDetails = new UPortalUserDetails(principal, Collections.unmodifiableSet(authorities)); // Add UserDetails to Session final PortletSession session = req.getPortletSession(); session.setAttribute(AUTHENTICATION_TOKEN_KEY, userDetails, PortletSession.APPLICATION_SCOPE); }
From source file:com.katropine.services.CustomUserDetailsService.java
public static List<GrantedAuthority> getGrantedAuthorities(List<String> roles) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String role : roles) { authorities.add(new SimpleGrantedAuthority(role)); }/* w w w . j av a2 s . c o m*/ return authorities; }
From source file:it.f2informatica.webapp.test.security.DatabaseUserDetailServiceTest.java
private List<GrantedAuthority> getGrantedAuthorities() { return Lists.<GrantedAuthority>newArrayList(new SimpleGrantedAuthority(Authority.ROLE_ADMIN.toString())); }
From source file:com.wandrell.example.swss.service.security.DefaultUserDetailsService.java
@Override public final UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { final UserDetails user; // Details for the user final Collection<SimpleGrantedAuthority> authorities; // Privileges of // the user checkNotNull(username, "Received a null pointer as username"); if ("myUser".equalsIgnoreCase(username)) { // User for password-based security authorities = new ArrayList<SimpleGrantedAuthority>(); authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); user = new User(username, "myPassword", authorities); } else {/*w w w. j a v a 2s. c om*/ // User not found LOGGER.debug(String.format("User for username %s not found", username)); throw new UsernameNotFoundException(String.format("Invalid username '%s'", username)); } LOGGER.debug(String.format("Found user for username %s", username)); return user; }
From source file:com.coffeebeans.persistence.domain.model.user.User.java
@Override public Collection<? extends GrantedAuthority> getAuthorities() { Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); GrantedAuthority authority = new SimpleGrantedAuthority(role.name()); authorities.add(authority);//from w ww.ja va2s.c om return authorities; }
From source file:fr.gael.dhus.service.TestNetworkService.java
@BeforeClass public void setUp() { String name = "authenticateduser"; this.user = new User(); this.user.setUsername(name); this.user.setPassword("test"); this.user.setEmail("test@test.com"); this.user.setCountry("France"); ApplicationContextProvider.getBean(UserDao.class).create(this.user); Set<GrantedAuthority> roles = new HashSet<>(); roles.add(new SimpleGrantedAuthority(Role.DOWNLOAD.getAuthority())); roles.add(new SimpleGrantedAuthority(Role.SEARCH.getAuthority())); roles.add(new SimpleGrantedAuthority(Role.USER_MANAGER.getAuthority())); SandBoxUser user = new SandBoxUser(name, name, true, 0, roles); auth = new UsernamePasswordAuthenticationToken(user, user.getPassword(), roles); SecurityContextHolder.getContext().setAuthentication(auth); }