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

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

Introduction

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

Prototype

public static List<GrantedAuthority> commaSeparatedStringToAuthorityList(String authorityString) 

Source Link

Document

Creates a array of GrantedAuthority objects from a comma-separated string representation (e.g.

Usage

From source file:com.jevontech.wabl.factories.SecurityUserFactory.java

public static SecurityUser create(User user) {
    Collection<? extends GrantedAuthority> authorities;
    try {/*  w  w  w .  j  a  v  a2  s. com*/
        authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(user.getAuthorities());
    } catch (Exception e) {
        authorities = null;
    }
    return new SecurityUser(user.getId(), user.getUsername(), user.getPassword(), user.getEmail(),
            user.getLastPasswordReset(), authorities);
}

From source file:com.example.CloudFoundryAuthentication.java

public CloudFoundryAuthentication(String username, OAuth2AccessToken token) {
    this(username, token, AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
}

From source file:org.cloudfoundry.identity.uaa.login.UsernamePasswordExtractingAuthenticationManagerTests.java

@Test
public void testAuthenticate() {
    Authentication expected = new TestingAuthenticationToken("bar", "foo",
            AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
    Mockito.when(delegate.authenticate(Mockito.any(UsernamePasswordAuthenticationToken.class)))
            .thenReturn(expected);//  w w  w.  ja  v  a2 s. c om
    Authentication output = manager.authenticate(new TestingAuthenticationToken("foo", "bar"));
    assertSame(expected, output);
}

From source file:org.zalando.stups.oauth2.spring.server.AbstractAuthenticationExtractor.java

@Override
public OAuth2Authentication extractAuthentication(final Map<String, Object> map, final String clientId) {
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(getPrincipal(map), "N/A",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    user.setDetails(map);/* w w w  . j  av  a  2 s  . co m*/

    // at the moment there is other way
    Set<String> scopes = resolveScopes(map);

    //
    OAuth2Request request = new OAuth2Request(null, clientId, null, true, scopes, null, null, null, null);
    return new OAuth2Authentication(request, user);
}

From source file:od.lti.LTIUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String ltiJson) throws UsernameNotFoundException {
    log.info(ltiJson);//w  w w  . ja va 2 s . com
    LaunchRequest launchRequest = LaunchRequest.fromJSON(ltiJson);
    String role;
    if (LTIController.hasInstructorRole(null, launchRequest.getRoles())) {
        role = "ROLE_INSTRUCTOR";
    } else {
        role = "ROLE_STUDENT";
    }

    return new OpenDashboardUser(launchRequest.getUser_id(), launchRequest.getUser_id(),
            AuthorityUtils.commaSeparatedStringToAuthorityList(role), launchRequest.getOauth_consumer_key(),
            launchRequest);
}

From source file:org.starfishrespect.myconsumption.server.business.security.AuthConfig.java

@Bean
UserDetailsService userDetailsService() {
    return new UserDetailsService() {

        @Override/*from w  w  w .j  a v a 2 s.  c o m*/
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            org.starfishrespect.myconsumption.server.business.entities.User account = mUserRepository
                    .getUser(username);

            if (account != null) {
                List<GrantedAuthority> auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
                return new User(account.getName(), account.getPassword(), auth);
            } else {
                throw new UsernameNotFoundException("could not find the user '" + username + "'");
            }
        }

    };
}

From source file:org.cloudfoundry.identity.uaa.login.UsernamePasswordExtractingAuthenticationManagerTests.java

@Test
public void testUsernamePassword() {
    Authentication expected = new UsernamePasswordAuthenticationToken("bar", "foo",
            AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
    Authentication output = manager.authenticate(expected);
    assertSame(expected, output);/*from w  w  w . j a v a 2s . co  m*/
}

From source file:org.joinfaces.example.SecurityConfig.java

@Override
protected UserDetailsService userDetailsService() {
    UserDetails user1 = new User("persapiens", "123",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ADMIN"));
    UserDetails user2 = new User("nyilmaz", "qwe",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    return new InMemoryUserDetailsManager(Arrays.asList(user1, user2));
}

From source file:org.cloudfoundry.identity.uaa.user.UaaUserEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    String[] values = text.split("\\|");
    if (values.length < 2) {
        throw new IllegalArgumentException(
                "Specify at least a username and password. Supported formats: " + SUPPORTED_FORMATS);
    }/* ww  w  .jav  a2 s  . c  o  m*/

    String username = values[0], password = values[1];
    String email = username, firstName = null, lastName = null;
    String authorities = null;
    if (values.length > 2) {
        switch (values.length) {
        case 3:
            authorities = values[2];
            break;
        case 6:
            email = values[2];
            firstName = values[3];
            lastName = values[4];
            authorities = values[5];
            break;
        case 5:
            email = values[2];
            firstName = values[3];
            lastName = values[4];
            break;
        default:
            throw new IllegalArgumentException("Supported formats: " + SUPPORTED_FORMATS);
        }
    }

    UaaUser user = new UaaUser(username, password, email, firstName, lastName);
    if (authorities != null) {
        user = user.authorities(AuthorityUtils.commaSeparatedStringToAuthorityList(authorities));
    }
    super.setValue(user);
}

From source file:eu.freme.broker.security.TokenAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    @SuppressWarnings("unchecked")
    Optional<String> token = (Optional<String>) authentication.getPrincipal();
    if (!token.isPresent() || token.get().isEmpty()) {
        throw new BadCredentialsException("Invalid token");
    }/*from w  w  w. j  a  va  2  s.  co m*/

    Token tokenObject = tokenService.retrieve(token.get());
    if (tokenObject == null) {
        throw new BadCredentialsException("Invalid token");
    }

    tokenService.updateLastUsed(tokenObject);

    User user = tokenObject.getUser();
    return new AuthenticationWithToken(user, null,
            AuthorityUtils.commaSeparatedStringToAuthorityList(user.getRole()), tokenObject);
}