Search in sources :

Example 1 with UserImpl

use of cern.modesti.user.UserImpl in project modesti by jlsalmon.

the class LdapUserDetailsMapper method mapUserFromContext.

@Override
public UserDetails mapUserFromContext(DirContextOperations context, String username, Collection<? extends GrantedAuthority> grantedAuthorities) {
    UserImpl user = new UserImpl();
    user.setEmployeeId(Integer.valueOf(context.getStringAttribute("employeeID")));
    user.setUsername(context.getStringAttribute("cn"));
    user.setFirstName(context.getStringAttribute("givenName"));
    user.setLastName(context.getStringAttribute("sn"));
    user.setEmail(context.getStringAttribute("mail"));
    for (GrantedAuthority authority : grantedAuthorities) {
        user.getAuthorities().add(new SimpleGrantedAuthority(authority.getAuthority()));
    }
    return user;
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UserImpl(cern.modesti.user.UserImpl)

Example 2 with UserImpl

use of cern.modesti.user.UserImpl in project modesti by jlsalmon.

the class MockUserServiceImpl method loadMockUsers.

private void loadMockUsers() throws IOException {
    for (Resource resource : resolver.getResources("classpath*:mock-users.txt")) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty() || line.startsWith("#")) {
                continue;
            }
            String[] props = line.split(" ");
            List<SimpleGrantedAuthority> roles = Arrays.stream(props[4].split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
            User user = new UserImpl(users.size() + 1, props[0], props[1], props[2], props[3], roles);
            boolean store = true;
            for (User existingUser : users) {
                if (existingUser.getUsername().equals(user.getUsername())) {
                    store = false;
                }
            }
            if (store) {
                addMockUser(user);
            }
        }
    }
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(cern.modesti.user.User) InputStreamReader(java.io.InputStreamReader) Resource(org.springframework.core.io.Resource) BufferedReader(java.io.BufferedReader) UserImpl(cern.modesti.user.UserImpl)

Aggregations

UserImpl (cern.modesti.user.UserImpl)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 User (cern.modesti.user.User)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Resource (org.springframework.core.io.Resource)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1