Search in sources :

Example 1 with OnmsUser

use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.

the class GroupRestService method getUser.

@GET
@Path("{groupName}/users/{userName}")
public OnmsUser getUser(@PathParam("groupName") final String groupName, @PathParam("userName") final String userName) {
    // check if group exists.
    getOnmsGroup(groupName);
    OnmsUser user = m_groupService.getUserForGroup(groupName, userName);
    if (user != null)
        return user;
    throw getException(Status.NOT_FOUND, "User with name '{}' does not exist in group '{}'", userName, groupName);
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with OnmsUser

use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.

the class SpringSecurityUserDaoImplIT method testGetByUsernameDashboard.

@Test
@DirtiesContext
public void testGetByUsernameDashboard() throws Exception {
    final OnmsUser newUser = new OnmsUser("dashboard");
    newUser.setPassword("DC7161BE3DBF2250C8954E560CC35060");
    newUser.getRoles().add(Authentication.ROLE_DASHBOARD);
    m_userManager.save(newUser);
    SpringSecurityUser user = ((SpringSecurityUserDao) m_springSecurityDao).getByUsername("dashboard");
    assertNotNull("user object should not be null", user);
    assertEquals("OnmsUser name", "dashboard", user.getUsername());
    assertEquals("Full name", null, user.getFullName());
    assertEquals("Comments", null, user.getComments());
    assertEquals("Password", "DC7161BE3DBF2250C8954E560CC35060", user.getPassword());
    Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
    assertNotNull("authorities should not be null", authorities);
    assertEquals("authorities size", 1, authorities.size());
    assertContainsAuthority(Authentication.ROLE_DASHBOARD, authorities);
    assertNoWarningsOrGreater();
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 3 with OnmsUser

use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.

the class OpenNMSUserDetailsServiceTest method testGetUser.

public void testGetUser() {
    SpringSecurityUserDao userDao = createMock(SpringSecurityUserDao.class);
    OpenNMSUserDetailsService detailsService = new OpenNMSUserDetailsService();
    detailsService.setUserDao(userDao);
    SpringSecurityUser user = new SpringSecurityUser(new OnmsUser());
    expect(userDao.getByUsername("test_user")).andReturn(user);
    replay(userDao);
    UserDetails userDetails = detailsService.loadUserByUsername("test_user");
    verify(userDao);
    assertNotNull("user object from DAO not null", userDetails);
    assertEquals("user objects", user, userDetails);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) OnmsUser(org.opennms.netmgt.model.OnmsUser)

Example 4 with OnmsUser

use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.

the class AuthenticationIT method testAuthenticateTempUser.

@Test
public void testAuthenticateTempUser() throws Exception {
    OnmsUser user = new OnmsUser("tempuser");
    user.setFullName("Temporary User");
    user.setPassword("18126E7BD3F84B3F3E4DF094DEF5B7DE");
    user.setDutySchedule(Arrays.asList("MoTuWeThFrSaSu800-2300"));
    m_userManager.save(user);
    org.springframework.security.core.Authentication authentication = new UsernamePasswordAuthenticationToken("tempuser", "mike");
    org.springframework.security.core.Authentication authenticated = m_provider.authenticate(authentication);
    assertNotNull("authenticated Authentication object not null", authenticated);
    Collection<? extends GrantedAuthority> authorities = authenticated.getAuthorities();
    assertNotNull("GrantedAuthorities should not be null", authorities);
    assertEquals("GrantedAuthorities size", 1, authorities.size());
    assertContainsAuthority(Authentication.ROLE_USER, authorities);
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 5 with OnmsUser

use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.

the class UserManager method save.

public void save(final OnmsUser onmsUser) throws Exception {
    update();
    m_writeLock.lock();
    try {
        User xmlUser = _getUser(onmsUser.getUsername());
        if (xmlUser == null) {
            xmlUser = new User();
            xmlUser.setUserId(onmsUser.getUsername());
        }
        xmlUser.setFullName(onmsUser.getFullName());
        xmlUser.setUserComments(onmsUser.getComments());
        // Contact info
        _setContact(xmlUser, ContactType.email, onmsUser.getEmail());
        final Password pass = new Password();
        pass.setEncryptedPassword(onmsUser.getPassword());
        pass.setSalt(onmsUser.getPasswordSalted());
        xmlUser.setPassword(pass);
        if (onmsUser.getDutySchedule() != null) {
            xmlUser.setDutySchedules(new ArrayList<String>(onmsUser.getDutySchedule()));
        }
        if (onmsUser.getRoles() != null) {
            xmlUser.setRoles(new ArrayList<String>(onmsUser.getRoles()));
        }
        _writeUser(onmsUser.getUsername(), xmlUser);
    } finally {
        m_writeLock.unlock();
    }
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) Password(org.opennms.netmgt.config.users.Password)

Aggregations

OnmsUser (org.opennms.netmgt.model.OnmsUser)21 Test (org.junit.Test)8 Path (javax.ws.rs.Path)5 User (org.opennms.netmgt.config.users.User)5 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 OnmsUserList (org.opennms.netmgt.model.OnmsUserList)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Matcher (java.util.regex.Matcher)1