List of usage examples for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority
public SimpleGrantedAuthority(String role)
From source file:com.expedia.seiso.core.security.UserDetailsAdapter.java
@Override public Collection<? extends GrantedAuthority> getAuthorities() { val authorities = new ArrayList<GrantedAuthority>(); val roles = user.getRoles(); for (Role role : roles) { authorities.add(new SimpleGrantedAuthority(role.getName())); }/*from w ww .jav a2s.c o m*/ return authorities; }
From source file:org.socialsignin.springsocial.security.userauthorities.SimpleUserAuthoritiesService.java
protected List<GrantedAuthority> getDefaultAuthorities(Set<ConnectionKey> connectionKeys) { List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); grantedAuthorities.add(new SimpleGrantedAuthority(defaultAuthorityName)); for (ConnectionKey connectionKey : connectionKeys) { grantedAuthorities.add(getProviderAuthority(connectionKey)); }/*from w ww . j ava 2s . c o m*/ return grantedAuthorities; }
From source file:com.devicehive.auth.websockets.WebSocketActionAuthenticationAspect.java
@Before("publicHandlerMethod(session)") public void authenticate(WebSocketSession session) throws Exception { HiveAuthentication authentication = (HiveAuthentication) session.getAttributes() .get(WebSocketAuthenticationManager.SESSION_ATTR_AUTHENTICATION); //if not authenticated - authenticate as device or anonymous if (authentication == null || authentication.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_ANONYMOUS"))) { HiveAuthentication.HiveAuthDetails details = authenticationManager.getDetails(session); authentication = authenticationManager.authenticateAnonymous(details); session.getAttributes().put(WebSocketAuthenticationManager.SESSION_ATTR_AUTHENTICATION, authentication); }//from w w w .ja v a 2s. c o m SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:io.manasobi.security.UserDetailsController.java
@RequestMapping(value = "/reg/user", method = RequestMethod.POST) public String register(String username, String password, String confirmPwd, Model model) { String viewName = "register"; if (!StringUtils.equals(password, confirmPwd)) { model.addAttribute("PWD_ERROR_MSG", Result.ERROR_101002.getMessage()); } else {//from w w w .j a v a 2s . co m List<GrantedAuthority> roles = Lists.newArrayList(); roles.add(new SimpleGrantedAuthority("USER")); Client client = new Client(); client.setUsername(username); client.setPassword(passwordEncoder.encode(password)); client.setRoles(roles); Result result = userDetailsService.register(client); if (result == Result.ERROR_101001) { model.addAttribute("USERNAME_ERROR_MSG", result.getMessage()); } else { viewName = "main"; } } return viewName; }
From source file:br.com.icone.martan.security.AppUserDetailsService.java
private Collection<? extends GrantedAuthority> getGrupos(Usuario usuario) { List<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>(); for (Grupo grupo : usuario.getGrupos()) { authorities.add(new SimpleGrantedAuthority(grupo.getNome().toUpperCase())); }//from w w w .ja v a2 s .c o m return authorities; }
From source file:de.thm.arsnova.security.DbUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) { LOGGER.debug("Load user: " + username); DbUser dbUser = dao.getUser(username); if (null == dbUser) { throw new UsernameNotFoundException("User does not exist."); }/*from ww w .ja v a 2 s . c o m*/ final List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_USER")); grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_DB_USER")); return new User(username, dbUser.getPassword(), null == dbUser.getActivationKey(), true, true, true, grantedAuthorities); }
From source file:ltistarter.oauth.MyConsumerDetailsService.java
@Override public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException { BaseConsumerDetails cd;//from ww w. ja v a 2s .c o m // NOTE: really lookup the key and secret, for the sample here we just hardcoded if ("key".equals(consumerKey)) { // allow this oauth request cd = new BaseConsumerDetails(); cd.setConsumerKey(consumerKey); cd.setSignatureSecret(new SharedConsumerSecretImpl("secret")); cd.setConsumerName("Sample"); cd.setRequiredToObtainAuthenticatedToken(false); // no token required (0-legged) cd.getAuthorities().add(new SimpleGrantedAuthority("ROLE_OAUTH")); // add the ROLE_OAUTH (can add others as well) log.info("OAuth check SUCCESS, consumer key: " + consumerKey); } else { // deny - failed to match throw new OAuthException("For this example, key must be 'key'"); } return cd; }
From source file:waffle.spring.FqnGrantedAuthorityFactory.java
@Override public GrantedAuthority createGrantedAuthority(final WindowsAccount windowsAccount) { String grantedAuthorityString = windowsAccount.getFqn(); if (this.prefix != null) { grantedAuthorityString = this.prefix + grantedAuthorityString; }/* w w w. j ava2 s. co m*/ if (this.convertToUpperCase) { grantedAuthorityString = grantedAuthorityString.toUpperCase(); } return new SimpleGrantedAuthority(grantedAuthorityString); }
From source file:com.itn.services.CustomUserDetailsService.java
private List<GrantedAuthority> getGrantedAuthorities(Users user) { List<GrantedAuthority> authorities = new ArrayList<>(); user.getUserProfiles().stream().map((userProfile) -> { System.out.println("UserProfile : " + userProfile); return userProfile; }).forEach((userProfile) -> {//from w w w .jav a 2s.co m authorities.add(new SimpleGrantedAuthority("ROLE_" + userProfile.getType())); }); System.out.print("authorities :" + authorities); return authorities; }
From source file:uk.co.threeonefour.ifictionary.web.user.service.DaoUserService.java
private org.springframework.security.core.userdetails.User buildUserFromUserEntity(User userEntity) { // convert model user to spring security user String username = userEntity.getUserId(); String password = userEntity.getPassword(); boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); Collection<Role> roles = userEntity.getRoles(); for (Role role : roles) { authorities.add(new SimpleGrantedAuthority(role.name())); }//from w w w . ja v a 2 s . c o m org.springframework.security.core.userdetails.User springUser = new org.springframework.security.core.userdetails.User( username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); return springUser; }