use of org.opennms.netmgt.config.users.Userinfo in project opennms by OpenNMS.
the class UserManager method _saveCurrent.
/**
* Saves into "users.xml" file
*/
private void _saveCurrent() throws Exception {
final List<User> users = new ArrayList<>(m_users.values());
final Userinfo userinfo = new Userinfo();
userinfo.setUsers(users);
final Header header = oldHeader;
if (header != null) {
header.setCreated(EventConstants.formatToString(new Date()));
userinfo.setHeader(header);
}
oldHeader = header;
// marshal to a string first, then write the string to the file. This
// way the original configuration
// isn't lost if the XML from the marshal is hosed.
final StringWriter stringWriter = new StringWriter();
JaxbUtils.marshal(userinfo, stringWriter);
final String writerString = stringWriter.toString();
saveXML(writerString);
}
use of org.opennms.netmgt.config.users.Userinfo in project opennms by OpenNMS.
the class UserManager method parseXML.
/**
* <p>parseXML</p>
*
* @param in a {@link java.io.InputStream} object.
*/
public void parseXML(final InputStream in) {
m_writeLock.lock();
InputStreamReader isr = null;
try {
isr = new InputStreamReader(in);
final Userinfo userinfo = JaxbUtils.unmarshal(Userinfo.class, isr);
oldHeader = userinfo.getHeader();
m_users = new TreeMap<String, User>();
for (final User curUser : userinfo.getUsers()) {
m_users.put(curUser.getUserId(), curUser);
}
_buildDutySchedules(m_users);
} finally {
IOUtils.closeQuietly(isr);
m_writeLock.unlock();
}
}
use of org.opennms.netmgt.config.users.Userinfo in project opennms by OpenNMS.
the class MagicUsersMigratorOfflineIT method validateMigration.
/**
* Validate the Migration by checking the updated users.xml
*
* @throws Exception the exception
*/
private void validateMigration() throws Exception {
Userinfo userInfo = JaxbUtils.unmarshal(Userinfo.class, new FileSystemResource(new File("target/home/etc/users.xml")));
final User rtc = getUser(userInfo, "rtc");
Assert.assertNotNull(rtc);
Assert.assertEquals(1, rtc.getRoles().size());
Assert.assertTrue(rtc.getRoles().contains(Authentication.ROLE_RTC));
final User admin = getUser(userInfo, "admin");
Assert.assertNotNull(admin);
Assert.assertEquals(1, admin.getRoles().size());
Assert.assertTrue(admin.getRoles().contains(Authentication.ROLE_ADMIN));
final User jmx = getUser(userInfo, "jmx_operator");
Assert.assertNotNull(jmx);
Assert.assertEquals(1, admin.getRoles().size());
Assert.assertTrue(jmx.getRoles().contains(Authentication.ROLE_JMX));
final User agalue = getUser(userInfo, "agalue");
Assert.assertNotNull(agalue);
Assert.assertEquals(2, agalue.getRoles().size());
Assert.assertTrue(agalue.getRoles().contains(Authentication.ROLE_USER));
Assert.assertTrue(agalue.getRoles().contains("ROLE_MEASUREMENTS"));
final User operator = getUser(userInfo, "operator");
Assert.assertNotNull(operator);
Assert.assertEquals(0, operator.getRoles().size());
final User manager = getUser(userInfo, "manager");
Assert.assertNotNull(manager);
Assert.assertEquals(2, manager.getRoles().size());
Assert.assertTrue(manager.getRoles().contains(Authentication.ROLE_USER));
Assert.assertTrue(manager.getRoles().contains(Authentication.ROLE_READONLY));
}
use of org.opennms.netmgt.config.users.Userinfo in project opennms by OpenNMS.
the class AuthenticationIT method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging(true, "DEBUG");
Userinfo users = JaxbUtils.unmarshal(Userinfo.class, new FileSystemResource(new File("src/test/resources/org/opennms/web/springframework/security/users.xml")));
assertNotNull(users);
m_userManager.saveUsers(users.getUsers());
}
use of org.opennms.netmgt.config.users.Userinfo in project opennms by OpenNMS.
the class SpringSecurityUserDaoImplIT method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging(true, "DEBUG");
Userinfo users = JaxbUtils.unmarshal(Userinfo.class, new FileSystemResource(new File("src/test/resources/org/opennms/web/springframework/security/users.xml")));
assertNotNull(users);
m_userManager.saveUsers(users.getUsers());
}
Aggregations