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);
}
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();
}
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);
}
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);
}
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();
}
}
Aggregations