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:org.openinfinity.core.security.principal.Identity.java

/**
 * Returns collections of GrantedAuthorities for the user.
 *///from   ww w  .ja  va  2  s . c  o m
public Collection<GrantedAuthority> getAuthorities() {
    Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
    for (Principal principal : getAllPrincipalsForIdentity()) {
        if (principal != null) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(principal.getName());
            grantedAuthorities.add(grantedAuthority);
        }
    }
    return grantedAuthorities;
}

From source file:com.sonymobile.backlogtool.Util.java

/**
 * Checks if active user is logged in.//  w ww.j a  v a 2  s .  c  o  m
 * @return true if logged in, otherwise false
 */
public static boolean isLoggedIn() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null) {
        return false;
    }
    GrantedAuthority anonymous = new SimpleGrantedAuthority("ROLE_ANONYMOUS");
    return !auth.getAuthorities().contains(anonymous);
}

From source file:com.hp.autonomy.frontend.configuration.authentication.CommunityAuthenticationProviderTest.java

@Test
public void testAuthenticateReturnsCorrectUser() {
    final UserRoles userRoles = mock(UserRoles.class);
    when(userRoles.getRoles()).thenReturn(Collections.singletonList(APP_ROLE));

    when(userService.getUser(anyString(), eq(true))).thenReturn(userRoles);

    final Authentication authentication = communityAuthenticationProvider.authenticate(springAuthentication);

    //noinspection unchecked
    assertThat((Iterable<GrantedAuthority>) authentication.getAuthorities(),
            hasItem(new SimpleGrantedAuthority(APP_ROLE)));
}

From source file:com.ge.predix.test.utils.UaaTestUtil.java

private void createReadOnlyPolicyScopeClient(final List<String> acsZones) {
    this.createClientWithAuthorities("acs_read_only_client", "acs_read_only_secret",
            Arrays.asList(new SimpleGrantedAuthority[] {
                    new SimpleGrantedAuthority("predix-acs.zones." + acsZones.get(0) + ".user"),
                    new SimpleGrantedAuthority("acs.policies.read") }));
}

From source file:com.tau.domain.core.TeUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (TeAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }//  w w w  .j a  v  a 2 s. co  m

    return list;
}

From source file:com.Truck.domain.core.TrUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (TrAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }/* w ww.j  a va  2s.  c  o  m*/

    return list;
}

From source file:com.TTT.domain.core.GiUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (GiAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }//from   w w w. j  a v a2s  . c o  m

    return list;
}

From source file:com.node.domain.core.NoUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (NoAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }// ww  w .  ja v a2  s.co m

    return list;
}

From source file:com.Null.domain.core.NuUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (NuAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }/*from   w w  w  .j  av a 2  s . c o  m*/

    return list;
}

From source file:com.KhaiA.domain.core.KhUser.java

@Override
public Collection<GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
    for (KhAuthority role : roles) {
        System.out.println("The roles is: " + role.getAuthority());
        list.add(new SimpleGrantedAuthority(role.getAuthority()));
    }//from   www . ja v  a2  s  .com

    return list;
}