Package org.springframework.security.core.authority

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


    protected GrantedAuthority createAuthority(Object role) {
        if (role instanceof String) {
            if (convertToUpperCase) {
                role = ((String) role).toUpperCase();
            }
            return new GrantedAuthorityImpl(rolePrefix + role);
        }
        return null;
    }
View Full Code Here


  }

  private void addResearcherToSecurityContext(Researcher researcher, boolean admin) {
    Collection<GrantedAuthority> authorities = researcher.getAuthorities();
    if (admin) {
      authorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
    }
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(researcher, researcher.getPassword(), authorities.toArray(new GrantedAuthority[authorities.size()]));
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(authentication);
  }
View Full Code Here

  }

  public Collection<GrantedAuthority> getRolesAsAuthorities() {
    List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
    for (String s : roles) {
      auths.add(new GrantedAuthorityImpl(s));
    }
    return auths;
  }
View Full Code Here

  }

  public Collection<GrantedAuthority> getPermissionsAsAuthorities() {
    List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
    if (isAdmin()) {
      auths.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
    }

    if (isInternal()) {
      auths.add(new GrantedAuthorityImpl("ROLE_INTERNAL"));
    }

    if (isExternal()) {
      auths.add(new GrantedAuthorityImpl("ROLE_EXTERNAL"));
    }

    return auths;
  }
View Full Code Here

              u.setLoginName(details.getUsername());
              u.setFullName(details.getUsername());
              u.setPassword(details.getPassword());
              u.setActive(true);

              if (details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_ADMIN"))) {
                u.setAdmin(true);
              }

              if (details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_INTERNAL"))) {
                u.setInternal(true);
                u.setRoles(new String[]{"ROLE_INTERNAL"});
              }
              else if (details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_EXTERNAL"))) {
                u.setExternal(true);
                u.setRoles(new String[]{"ROLE_EXTERNAL"});
              }
              else {
                log.warn("Unrecognised roles");
View Full Code Here

            byte[] rbytes = roleblob.getBytes(1, (int) roleblob.length());
            String s1 = new String(rbytes);
            String[] roles = s1.split(",");
            for (String role : roles) {
              System.out.println("Found role " + role + " for " + rs.getString("username"));
              GrantedAuthorityImpl authority = new GrantedAuthorityImpl(role);
              roleList.add(authority);
            }
          }
          else {
            System.out.println("Cannot process user login - cannot extract roles from database");
          }
        }

        try {
          if (rs.getBoolean("admin")) roleList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
          if (rs.getBoolean("external")) roleList.add(new GrantedAuthorityImpl("ROLE_EXTERNAL"));
          if (rs.getBoolean("internal")) roleList.add(new GrantedAuthorityImpl("ROLE_INTERNAL"));
        }
        catch (SQLException e) {
          e.printStackTrace();
          log.warn("Couldn't retrieve a user property to convert to a role: " + e.getMessage());
        }
View Full Code Here

            } else {
                authorities.add(new SimpleGrantedAuthority(permission.getName()));
            }
        }
        for (String perm : AdminSecurityService.DEFAULT_PERMISSIONS) {
            authorities.add(new GrantedAuthorityImpl(perm));
        }
        return new AdminUserDetails(adminUser.getId(), username, adminUser.getPassword(), true, true, true, true, authorities);
    }
View Full Code Here

    // by username. If a user already exists with that username that has been authed, then they must be the same
    // user and this user will inherit the already-persisted userID.
    UserImpl user = new UserImpl();

    user.setActive(details.isAccountNonExpired());
    user.setAdmin(details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_ADMIN")));
    user.setExternal(details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_EXTERNAL")));
    user.setInternal(details.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_INTERNAL")));
    user.setLoginName(details.getUsername());
    user.setPassword(details.getPassword());
    user.setFullName(details.getDisplayName());
    user.setEmail(details.getMail());
View Full Code Here

        long entityId = entity.getId();

        AuditLogger auditLogger = new ConsoleAuditLogger();
        AclAuthorizationStrategy aclAuthorizationStrategy =
                new org.springframework.security.acls.domain.AclAuthorizationStrategyImpl(
                        new GrantedAuthorityImpl("some_role")
                );
        ObjectIdentity entityIdentity = new AclUtil(null).createIdentity(entityId,
                entity.getClass().getSimpleName());
        ExtendedMutableAcl mutableAcl = mock(ExtendedMutableAcl.class);
        List<AccessControlEntry> accessControlEntries = new ArrayList<>();
View Full Code Here

    @Test
    public void testUserDefaultAuthority() {
        JCUser user =  new JCUser("username", "email@mail.com", "pass");

        GrantedAuthority expectedAuthority = new GrantedAuthorityImpl("ROLE_USER");
        assertTrue(user.getAuthorities().contains(expectedAuthority));
    }
View Full Code Here

TOP

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

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.