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.github.persapiens.jsfboot.security.AuthenticationFactory.java

private static Collection<? extends GrantedAuthority> grantedAuthorities(String... authorities) {
    Collection<SimpleGrantedAuthority> result = new HashSet<>();
    for (String authority : authorities) {
        result.add(new SimpleGrantedAuthority(authority));
    }/*w  w w . jav a 2  s .  c  om*/
    return result;
}

From source file:org.joinfaces.security.AuthenticationFactory.java

private static Collection<? extends GrantedAuthority> grantedAuthorities(String... authorities) {
    Collection<SimpleGrantedAuthority> result = new HashSet<SimpleGrantedAuthority>();
    for (String authority : authorities) {
        result.add(new SimpleGrantedAuthority(authority));
    }/*  ww w.ja  va 2 s.  c om*/
    return result;
}

From source file:org.cloudbyexample.dc.service.util.SecurityContextUtil.java

public static void createSystemUser() {
    SecurityContext context = SecurityContextHolder.getContext();

    // Set the granted authorities so that the user is not authenticated again
    List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
    grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_SYSTEM"));

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("system", "",
            grantedAuthorities);//w w w. j av a 2  s  . c  o  m

    context.setAuthentication(token);
}

From source file:am.ik.categolj2.domain.service.userdetails.Categolj2UserDetails.java

private static Collection<? extends GrantedAuthority> toAuthorities(Collection<Role> roles) {
    return Collections2.transform(roles, new Function<Role, SimpleGrantedAuthority>() {
        @Override/* w  w  w  .  j  ava2s  . co  m*/
        public SimpleGrantedAuthority apply(Role role) {
            return new SimpleGrantedAuthority("ROLE_" + role.getRoleName());
        }
    });
}

From source file:oobbit.security.AccessLevelToGrantedAuthority.java

@Deprecated
public SimpleGrantedAuthority accessLevelToSimpleGrantedAuthority(int accessLevel) {
    switch (accessLevel) {
    case 0://w  w  w . j a  v a 2s. c om
        return new SimpleGrantedAuthority("ROLE_BANNED");
    case 1:
        return new SimpleGrantedAuthority("ROLE_USER");
    case 10:
        return new SimpleGrantedAuthority("ROLE_MODERATOR");
    case 100:
        return new SimpleGrantedAuthority("ROLE_ADMINISTRATOR");
    default:
        throw new AssertionError();
    }
}

From source file:com.jevontech.wabl.services.implementation.SecurityServiceImpl.java

@Override
public Boolean hasProtectedAccess() {
    return (SecurityContextHolder.getContext().getAuthentication().getAuthorities()
            .contains(new SimpleGrantedAuthority("ADMIN")));
}

From source file:th.co.geniustree.osgi.prototype.authen.security.UserDetailsImpl.java

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    GrantedAuthority ga = new SimpleGrantedAuthority("ADMIN");
    return Arrays.asList(ga);
}

From source file:com.mtech.easyexchange.user.WebUser.java

public WebUser(Integer id, String email, String password) {
    this.id = id;
    this.email = email;
    this.password = password;

    authorities = new ArrayList<GrantedAuthority>();
    authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
}

From source file:org.obozek.minermonitor.config.MinerUserDetails.java

public MinerUserDetails(User user) {
    this.user = user;
    grantedAuthorities = new ArrayList<>();
    for (UserRole role : user.getUserRoles()) {
        SimpleGrantedAuthority sga = new SimpleGrantedAuthority(role.getRoleName());
        grantedAuthorities.add(sga);/*from w w w  . j a v  a2  s  .  c o m*/
    }
}

From source file:org.atomsphere.management.authentication.AuthenticationUtils.java

/**
 * Accepts list of Roles and return array[] of ACEGI GrantedAuthorityImpl
 *///from   www.  j  a va 2 s .  c o  m
public static Collection<GrantedAuthority> toGrantedAuthority(User user) {
    if (user.getAuthorities() != null && user.getAuthorities().size() > 0) {
        return user.getAuthorities();
    }

    Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();

    if (user.isAdministrator()) {
        grantedAuthorities.add(new SimpleGrantedAuthority(ROLE_ADMIN));
    } else {
        grantedAuthorities.add(new SimpleGrantedAuthority(ROLE_USER));
    }

    return grantedAuthorities;
}