Example usage for org.springframework.security.core.authority AuthorityUtils NO_AUTHORITIES

List of usage examples for org.springframework.security.core.authority AuthorityUtils NO_AUTHORITIES

Introduction

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

Prototype

List NO_AUTHORITIES

To view the source code for org.springframework.security.core.authority AuthorityUtils NO_AUTHORITIES.

Click Source Link

Usage

From source file:com.rockagen.gnext.service.spring.security.aspect.SS3Tools.java

/**
 * Obtain current user principal//from  w w  w  .ja  v a  2s.  c  o m
 * @return BasicSecurityUser
 */
public static BasicSecurityUser getUserInfo() {
    BasicSecurityUser userDetails = null;
    try {
        SecurityContext sc = SecurityContextHolder.getContext();
        Authentication au = sc.getAuthentication();
        userDetails = (BasicSecurityUser) au.getPrincipal();
    } catch (NullPointerException e) {
        userDetails = new BasicSecurityUser("guest", "guest", true, true, true, true,
                AuthorityUtils.NO_AUTHORITIES, "root", "", "127.0.0.1");

    }
    return userDetails;

}

From source file:at.ac.univie.isc.asio.security.FilterAuthoritiesTest.java

@Test
public void should_yield_input_if_none_excluded() throws Exception {
    final FilterAuthorities subject = FilterAuthorities.exclude(AuthorityUtils.NO_AUTHORITIES);
    final Set<GrantedAuthority> mapped = subject.mapAuthorities(authorities("one", "two"));
    assertThat(mapped, containsOnly("one", "two"));
}

From source file:br.com.insula.spring.security.janrain.JanrainAuthenticationToken.java

public JanrainAuthenticationToken(String identifier, String verifiedEmail, String email, String providerName,
        String name) {/*from ww w.j  a  v  a  2s. c o m*/
    super(AuthorityUtils.NO_AUTHORITIES);
    this.principal = null;
    this.identifier = identifier;
    this.verifiedEmail = verifiedEmail;
    this.email = email;
    this.providerName = providerName;
    this.name = name;
}

From source file:com.googlecode.janrain4j.springframework.security.JanrainAuthenticationToken.java

/**
 * Constructor used for an authentication request. The {@link
 * org.springframework.security.core.Authentication#isAuthenticated()} will
 * return <code>false</code>.
 *
 * @param userDataResponse The <code>UserDataResponse</code>.
 *///  w w  w.jav a2  s .  c o  m
public JanrainAuthenticationToken(UserDataResponse userDataResponse) {
    super(AuthorityUtils.NO_AUTHORITIES);
    this.principal = userDataResponse.getProfile().getIdentifier();
    this.userDataResponse = userDataResponse;
    setAuthenticated(false);
}

From source file:com.googlecode.janrain4j.springframework.security.JanrainUserDetails.java

public JanrainUserDetails(UserDataResponse userDataResponse) {
    this(userDataResponse, AuthorityUtils.NO_AUTHORITIES);
    this.userDataResponse = userDataResponse;
}

From source file:at.ac.univie.isc.asio.security.FilterAuthoritiesTest.java

@Test
public void should_always_create_a_copy() throws Exception {
    final FilterAuthorities subject = FilterAuthorities.exclude(AuthorityUtils.NO_AUTHORITIES);
    final Collection<GrantedAuthority> input = authorities("one", "two");
    final Collection<GrantedAuthority> output = subject.mapAuthorities(input);
    assertThat(output, not(sameInstance(input)));
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.ldap.DatabaseOnlyLdapAuthoritiesPopulator.java

/**
 * {@inheritDoc}/*from w  ww.  j  a  v a2s .  co m*/
 * @see org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator#getGrantedAuthorities(
 *    org.springframework.ldap.core.DirContextOperations, java.lang.String)
 */
public Collection<GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {

    UserDetails dbDetails = null;
    try {
        dbDetails = _userDetailsService.loadUserByUsername(username, true);
    } catch (UsernameNotFoundException ignored) {
        // just looking for roles, so ignore the UsernameNotFoundException
        return AuthorityUtils.NO_AUTHORITIES;
    }

    if (dbDetails.getAuthorities() == null) {
        return AuthorityUtils.NO_AUTHORITIES;
    }

    Collection<GrantedAuthority> roles = new HashSet<GrantedAuthority>(dbDetails.getAuthorities());
    if (defaultRole != null) {
        roles.add(defaultRole);
    }

    return roles;
}

From source file:org.openlmis.fulfillment.security.CustomUserAuthenticationConverter.java

private Collection<? extends GrantedAuthority> getAuthorities(Map<String, ?> map) {
    if (!map.containsKey(AUTHORITIES)) {
        return AuthorityUtils.NO_AUTHORITIES;
    }/*from   www. j a  v a  2s.  c  o  m*/
    Object authorities = map.get(AUTHORITIES);
    if (authorities instanceof String) {
        return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
    }
    if (authorities instanceof Collection) {
        return AuthorityUtils.commaSeparatedStringToAuthorityList(
                StringUtils.collectionToCommaDelimitedString((Collection<?>) authorities));
    }
    throw new IllegalArgumentException("Authorities must be either a String or a Collection");
}

From source file:com.epam.ta.reportportal.auth.UserRoleHierarchy.java

@Override
public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(
        Collection<? extends GrantedAuthority> authorities) {

    if ((authorities == null) || (authorities.isEmpty())) {
        return AuthorityUtils.NO_AUTHORITIES;
    }/*from   w w w  .  j a v a  2  s. co m*/

    List<GrantedAuthority> reachableRoles = authorities.stream()
            .filter(authority -> authoritiesMap.containsKey(authority))
            .flatMap(authority -> authoritiesMap.get(authority).stream()).collect(Collectors.toList());

    if (logger.isDebugEnabled()) {
        logger.debug("getReachableGrantedAuthorities() - From the roles " + authorities + " one can reach "
                + reachableRoles + " in zero or more steps.");
    }

    return reachableRoles;
}

From source file:com.rln.acme.security.MongoDBAuthenticationProvider.java

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {

    final String password = (String) authentication.getCredentials();
    if (!StringUtils.isNotBlank(password)) {
        logger.warn("User {}: no password provided", username);
        throw new BadCredentialsException("Please enter password");
    }// ww  w  .j  a  v  a  2s  .c om

    final UserAccount user = userService.findByUsername(username);
    if (user == null) {
        logger.warn("Username {}, password {}: username and password not found", username, password);
        throw new BadCredentialsException("Invalid Username/Password");
    }

    final List<GrantedAuthority> auths;
    if (CollectionUtils.isNotEmpty(user.getRoles())) {
        auths = AuthorityUtils.commaSeparatedStringToAuthorityList(
                user.getRoles().stream().map(r -> r.getId()).collect(Collectors.joining(",")));
    } else {
        auths = AuthorityUtils.NO_AUTHORITIES;
    }

    return new User(username, password, user.getEnabled(), // enabled
            true, // account not expired
            true, // credentials not expired
            true, // account not locked
            auths);
}