Search in sources :

Example 1 with Userinfo

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);
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) Header(org.opennms.netmgt.config.users.Header) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) Userinfo(org.opennms.netmgt.config.users.Userinfo) Date(java.util.Date)

Example 2 with Userinfo

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();
    }
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) InputStreamReader(java.io.InputStreamReader) Userinfo(org.opennms.netmgt.config.users.Userinfo)

Example 3 with Userinfo

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));
}
Also used : User(org.opennms.netmgt.config.users.User) Userinfo(org.opennms.netmgt.config.users.Userinfo) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File)

Example 4 with Userinfo

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());
}
Also used : Userinfo(org.opennms.netmgt.config.users.Userinfo) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Before(org.junit.Before)

Example 5 with Userinfo

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());
}
Also used : Userinfo(org.opennms.netmgt.config.users.Userinfo) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Before(org.junit.Before)

Aggregations

Userinfo (org.opennms.netmgt.config.users.Userinfo)5 File (java.io.File)3 User (org.opennms.netmgt.config.users.User)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Before (org.junit.Before)2 OnmsUser (org.opennms.netmgt.model.OnmsUser)2 InputStreamReader (java.io.InputStreamReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Header (org.opennms.netmgt.config.users.Header)1