List of usage examples for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority
public SimpleGrantedAuthority(String role)
From source file:com.mycompany.login.filter.AutenticacaoFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { String login = request.getParameter("j_login"); String senha = request.getParameter("j_senha"); try {//from www. j a v a2 s .c om Usuario usuario = buscarUsuario(login, senha); if (usuario != null) { Collection<GrantedAuthority> regras = new ArrayList<GrantedAuthority>(); regras.add(new SimpleGrantedAuthority(usuario.getPermissao())); request.getSession().setAttribute("usuarioLogado", usuario); mensagem = "Bem vindo: " + usuario.getNomeusuario(); return new UsernamePasswordAuthenticationToken(usuario.getLogin(), usuario.getSenha(), regras); } else { mensagem = "Dados Incorretos"; throw new BadCredentialsException(mensagem); } } catch (Exception e) { throw new BadCredentialsException(e.getMessage()); } }
From source file:org.jblogcms.core.security.service.UserDetailsServiceImpl.java
/** * @see UserDetailsService#loadUserByUsername(String) *///from www .j av a 2s . c om @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Account account = accountRepository.findAccountByEmail(username); if (account == null) { throw new UsernameNotFoundException("No user found with username: " + username); } Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); SimpleGrantedAuthority authority = new SimpleGrantedAuthority(account.getAccountRole().toString()); authorities.add(authority); AccountDetails userDetails = new AccountDetails(account.getEmail(), account.getPassword(), authorities); userDetails.setId(account.getId()); userDetails.setFirstName(account.getFirstName()); userDetails.setLastName(account.getLastName()); userDetails.setSocialSignInProvider(account.getSignInProvider()); return userDetails; }
From source file:org.meruvian.yama.service.security.DefaultUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userManager.getUserByUsername(username); if (user != null) { boolean enabled = user.getLogInformation().getActiveFlag() == LogInformation.ACTIVE; List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); Page<? extends Role> roles = userManager.findRoleByUser(user, null); for (Role role : roles) { authorities.add(new SimpleGrantedAuthority(StringUtils.upperCase(role.getName()))); }//w w w. j a va 2s .c om DefaultUserDetails details = new DefaultUserDetails(user.getUsername(), user.getPassword(), enabled, true, true, true, authorities); details.setId(user.getId()); details.setUser(new DefaultUser(user)); return details; } return null; }
From source file:nc.noumea.mairie.appock.core.security.AppockAuthoritiesPopulator.java
@Override public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations dirContextOperations, String login) {/* w w w. ja v a 2 s . c o m*/ List<GrantedAuthority> roles = new ArrayList<>(); AppUser appUser = appUserService.findByLogin(login); if (appUser == null || !appUser.isActif()) { return roles; } for (Role role : appUser.listeRole) { roles.add(new SimpleGrantedAuthority(role.name())); } return roles; }
From source file:org.mitre.oauth2.introspectingfilter.service.impl.ScopeBasedIntrospectionAuthoritiesGranter.java
@Override public List<GrantedAuthority> getAuthorities(JsonObject introspectionResponse) { List<GrantedAuthority> auth = new ArrayList<>(getAuthorities()); if (introspectionResponse.has("scope") && introspectionResponse.get("scope").isJsonPrimitive()) { String scopeString = introspectionResponse.get("scope").getAsString(); Set<String> scopes = OAuth2Utils.parseParameterList(scopeString); for (String scope : scopes) { auth.add(new SimpleGrantedAuthority("OAUTH_SCOPE_" + scope)); }/*from w w w .jav a 2 s.co m*/ } return auth; }
From source file:com.alehuo.wepas2016projekti.service.CustomUserDetailsService.java
/** * Hakee kyttjn tietokannasta ja asettaa sille oikeat kyttoikeudet * @param string Kyttjtunnus//from w ww . j a v a 2s .c o m * @return Kyttjtiedot * @throws UsernameNotFoundException */ @Override public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException { UserAccount u = userRepo.findByUsernameIgnoreCase(string.trim()); if (u == null) { throw new UsernameNotFoundException("Kyttjtunnusta " + string + " ei lydy"); } return new org.springframework.security.core.userdetails.User(u.getUsername(), u.getPassword(), true, true, true, true, Arrays.asList(new SimpleGrantedAuthority(u.getRole().toString()))); }
From source file:org.devgateway.toolkit.persistence.spring.CustomJPAUserDetailsService.java
/** * Reads {@link PersistedAuthority} objects from the * {@link org.devgateway.eudevfin.auth.common.domain.PersistedUser#getPersistedAuthorities()} * and also from the {@link PersistedUserGroup#getPersistedAuthorities()} * (only if the {@link User} belongs to only one {@link PersistedUserGroup}) * and converts all {@link PersistedAuthority} objects to * {@link GrantedAuthority}./*from w w w .j ava2 s . c o m*/ * * @param domainUser * @return a {@link Set} containing the {@link GrantedAuthority}S */ public static Set<GrantedAuthority> getGrantedAuthorities(final Person domainUser) { Set<GrantedAuthority> grantedAuth = new HashSet<GrantedAuthority>(); // get user authorities for (Role authority : domainUser.getRoles()) { grantedAuth.add(new SimpleGrantedAuthority(authority.getAuthority())); } return grantedAuth; }
From source file:com.todo.backend.security.UserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { log.trace(".loadUserByUsername({})", username); final String lowercaseUsername = username.toLowerCase(); final Optional<User> optionalUser = userRepository.findByUsername(lowercaseUsername); if (!optionalUser.isPresent()) { throw new UsernameNotFoundException("User " + username + " not found!"); }/*from w w w . j a v a 2 s . c o m*/ final User user = optionalUser.get(); final List<GrantedAuthority> grantedAuthorities = Collections .singletonList(new SimpleGrantedAuthority(user.getRole().name())); return new org.springframework.security.core.userdetails.User(lowercaseUsername, null, grantedAuthorities); }
From source file:com.github.sshw.security.SSHAuthenticationProvider.java
public SSHAuthenticationProvider() { authorities.add(new SimpleGrantedAuthority("USER")); }
From source file:org.hspconsortium.platform.authorization.userdetails.MappedLdapAuthoritiesPopulator.java
@Override public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {/*w w w. j a va 2 s . c o m*/ List<? extends GrantedAuthority> authorities = null; String quString = "SELECT * from authorities where username = ?"; authorities = jdbcTemplate.query(quString, new String[] { username }, new HSPCAuthResultSetExtractor()); if (authorities == null || authorities.isEmpty()) { List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>(); ; GrantedAuthority a = new SimpleGrantedAuthority("ROLE_USER"); auths.add(a); authorities = auths; } return ImmutableList.copyOf(authorities); }