Example usage for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority

List of usage examples for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority

Introduction

In this page you can find the example usage for org.springframework.security.core.authority SimpleGrantedAuthority SimpleGrantedAuthority.

Prototype

public SimpleGrantedAuthority(String role) 

Source Link

Usage

From source file:com.example.server.user.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
    User user = dao.findByUserName(string);
    if (user == null) {
        throw new UsernameNotFoundException("user with name " + string + " not found");
    }//from w  w w . ja v  a2  s. c o m
    GrantedAuthority authority = new SimpleGrantedAuthority(user.getRole());
    List<GrantedAuthority> list = new ArrayList<>();
    list.add(authority);
    return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), list);
}

From source file:org.mitre.provenance.openid.OpenID2UserDetailsService.java

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Set<SimpleGrantedAuthority> authorities = new HashSet<SimpleGrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
    return new User(username, "", authorities);
}

From source file:oobbit.security.AccessLevelToGrantedAuthority.java

/**
 * Returns a list of GrantedAuthorities based on the given access level.
 *
 * @param accessLevel access level as an integer
 *
 * @return List of GrantedAuthorities/*  w w  w  .j  av  a  2s .  c  o  m*/
 */
public List<GrantedAuthority> accessLevelToSimpleGrantedAuthorityList(int accessLevel) {
    ArrayList<GrantedAuthority> auths = new ArrayList<>();

    switch (accessLevel) {
    case 0:
        auths.add(new SimpleGrantedAuthority("ROLE_BANNED"));
    case 1:
        auths.add(new SimpleGrantedAuthority("ROLE_USER"));
    case 10:
        auths.add(new SimpleGrantedAuthority("ROLE_USER"));
        auths.add(new SimpleGrantedAuthority("ROLE_MODERATOR"));
    case 100:
        auths.add(new SimpleGrantedAuthority("ROLE_USER"));
        auths.add(new SimpleGrantedAuthority("ROLE_MODERATOR"));
        auths.add(new SimpleGrantedAuthority("ROLE_ADMINISTRATOR"));
    }

    return auths;
}

From source file:com.expedia.seiso.security.SeisoGrantedAuthoritiesMapper.java

@Override
public Collection<? extends GrantedAuthority> mapAuthorities(
        Collection<? extends GrantedAuthority> authorities) {
    Set<GrantedAuthority> mapped = new HashSet<>();
    mapped.add(new SimpleGrantedAuthority(Roles.USER));
    return mapped;
}

From source file:com.orange.clara.cloud.servicedbdumper.security.AccessManager.java

public boolean isUserIsAdmin() {
    SecurityContext context = this.getSecurityContextHolder();
    if (context == null) {
        return false;
    }/*from  w  ww  . j av  a2 s. c  om*/
    Authentication authentication = context.getAuthentication();
    if (authentication == null) {
        return false;
    }
    Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
    return authorities.contains(new SimpleGrantedAuthority(AUTHORIZED_AUTHORITY));
}

From source file:opensnap.config.CustomHandshakeHandler.java

@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler,
        Map<String, Object> attributes) {
    Principal principal = request.getPrincipal();
    if (principal == null) {
        principal = new UsernamePasswordAuthenticationToken("anonymous", "jdqsjkdjsqkjd",
                Arrays.asList(new SimpleGrantedAuthority("ANONYMOUS")));
    }/*from   w ww .  j  ava2 s  .  c  o m*/
    return principal;
}

From source file:org.mitre.oauth2.model.convert.SimpleGrantedAuthorityStringConverter.java

@Override
public SimpleGrantedAuthority convertToEntityAttribute(String dbData) {
    if (dbData != null) {
        return new SimpleGrantedAuthority(dbData);
    } else {/*from  ww w  .  j a  va2s .com*/
        return null;
    }
}

From source file:de.sainth.recipe.backend.security.RecipeManagerAuthenticationToken.java

public RecipeManagerAuthenticationToken(Long userId, String role) {
    this.role = role;
    this.authenticated = true;
    this.userId = userId;
    this.permissions = Collections.singletonList(new SimpleGrantedAuthority(role));
}

From source file:org.apache.nifi.minifi.c2.security.authentication.C2AnonymousAuthenticationFilter.java

@Override
protected Authentication createAuthentication(HttpServletRequest request) {
    return new C2AuthenticationToken(ANONYMOUS, null,
            Arrays.asList(new SimpleGrantedAuthority("ROLE_ANONYMOUS")));
}

From source file:com.marklogic.samplestack.domain.ClientRole.java

/**
 * Provides the database client role implied by the security context for the spring application.
 * @return The ClientRole enum value that corresponds to the current logged-in user.
 *//* ww  w  .ja  v  a 2  s . c  o  m*/
public static ClientRole securityContextRole() {
    SecurityContext secContext = SecurityContextHolder.getContext();
    Collection<? extends GrantedAuthority> auths = secContext.getAuthentication().getAuthorities();
    if (auths.contains(new SimpleGrantedAuthority("ROLE_CONTRIBUTORS"))) {
        return SAMPLESTACK_CONTRIBUTOR;
    } else {
        return SAMPLESTACK_GUEST;
    }
}