Package org.springframework.security.core.authority

Examples of org.springframework.security.core.authority.SimpleGrantedAuthority


    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        ensureAuthorityCodes();
        Collection<GrantedAuthority> grantedAuthorities = Lists.newArrayList();
        for (String code : authorityCodes) {
            grantedAuthorities.add(new SimpleGrantedAuthority(code));
        }
        return grantedAuthorities;
    }
View Full Code Here


    @Override
    public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException, DataAccessException {
        final Set<SimpleGrantedAuthority> authorities = new HashSet<SimpleGrantedAuthority>();
        if (adminUser.equals(username)) {
            for (Entitlement entitlement : entitlementDAO.findAll()) {
                authorities.add(new SimpleGrantedAuthority(entitlement.getName()));
            }
        } else {
            final SyncopeUser user = userDAO.find(username);

            if (user == null) {
                throw new UsernameNotFoundException("Could not find any user with id " + username);
            }

            // Give entitlements based on roles assigned to user (and their ancestors)
            final Set<SyncopeRole> roles = new HashSet<SyncopeRole>(user.getRoles());
            for (SyncopeRole role : user.getRoles()) {
                roles.addAll(roleDAO.findAncestors(role));
            }
            for (SyncopeRole role : roles) {
                for (Entitlement entitlement : role.getEntitlements()) {
                    authorities.add(new SimpleGrantedAuthority(entitlement.getName()));
                }
            }
            // Give role operational entitlements for owned roles
            List<SyncopeRole> ownedRoles = roleDAO.findOwned(user);
            if (!ownedRoles.isEmpty()) {
                authorities.add(new SimpleGrantedAuthority("ROLE_CREATE"));
                authorities.add(new SimpleGrantedAuthority("ROLE_READ"));
                authorities.add(new SimpleGrantedAuthority("ROLE_UPDATE"));
                authorities.add(new SimpleGrantedAuthority("ROLE_DELETE"));

                for (SyncopeRole role : ownedRoles) {
                    authorities.add(new SimpleGrantedAuthority(EntitlementUtil.
                            getEntitlementNameFromRoleId(role.getId())));
                }
            }
        }
View Full Code Here

    protected String doExecute(final boolean dryRun) throws JobExecutionException {
        // PRE: grant all authorities (i.e. setup the SecurityContextHolder)
        final List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

        for (Entitlement entitlement : entitlementDAO.findAll()) {
            authorities.add(new SimpleGrantedAuthority(entitlement.getName()));
        }

        final UserDetails userDetails = new User("admin", "FAKE_PASSWORD", true, true, true, true, authorities);

        SecurityContextHolder.getContext().setAuthentication(
View Full Code Here

    UserDetails originalUser = super.mapUserFromContext( ctx, username, authority );

    // Current authorities come from LDAP groups

    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
   
    if(isAdmin(originalUser.getUsername())){
      authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }
    logger.debug(originalUser.getUsername());
    logger.debug(originalUser.getPassword());
    logger.debug(authorities.toString());
    User newUser = new User(originalUser.getUsername(), "password", authorities);
View Full Code Here

          }
         
          @Override
          public Collection<? extends GrantedAuthority> getAuthorities() {
            Collection<SimpleGrantedAuthority> auth = new ArrayList<SimpleGrantedAuthority>();
            auth.add(new SimpleGrantedAuthority("GUEST"));
           
            return  auth;
          }
        };
      }
View Full Code Here

    Set<GrantedAuthority> authSet = new HashSet<GrantedAuthority>();
    for (Resources res : resources) {
      // TODO:ZZQ 用户可以访问的资源名称(或者说用户所拥有的权限) 注意:必须"ROLE_"开头
      // 关联代码:applicationContext-security.xml
      // 关联代码:com.huaxin.security.MySecurityMetadataSource#loadResourceDefine
      authSet.add(new SimpleGrantedAuthority("ROLE_" + res.getResKey()));
    }
    return authSet;
  }
View Full Code Here

    }

    private Collection<GrantedAuthority> getAuthorities(List<Map<String, String>> authorities) {
        Set<GrantedAuthority> grantedAuthorities = new HashSet<>(authorities.size());
        for(Map<String, String> authority : authorities) {
            grantedAuthorities.add(new SimpleGrantedAuthority(authority.get("role")));
        }
        return grantedAuthorities;
    }
View Full Code Here

            throw new UserNotActivatedException("User " + lowercaseLogin + " was not activated");
        }

        Collection<GrantedAuthority> grantedAuthorities = new ArrayList<>();
        for (Authority authority : userFromDatabase.getAuthorities()) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority.getName());
            grantedAuthorities.add(grantedAuthority);
        }

        return new org.springframework.security.core.userdetails.User(lowercaseLogin, userFromDatabase.getPassword(),
                grantedAuthorities);
View Full Code Here

      throws UsernameNotFoundException {

    try {

      Collection<GrantedAuthority> userAuthorities = new ArrayList<GrantedAuthority>();
      userAuthorities.add(new SimpleGrantedAuthority(ROLE_USER));

      List<Userinfo> userinfos = userService.findByUserName(username);

      Userinfo userinfo = userinfos.get(0);
View Full Code Here

         */
        public UserRequestPostProcessor roles(String... roles) {
            List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
            for(String role : roles) {
                if(this.rolePrefix == null || role.startsWith(this.rolePrefix)) {
                    authorities.add(new SimpleGrantedAuthority(role));
                } else {
                    authorities.add(new SimpleGrantedAuthority(this.rolePrefix + role));
                }
            }
            return this;
        }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.authority.SimpleGrantedAuthority

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.