• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 14735285473

29 Apr 2025 03:33PM UTC coverage: 65.095% (-0.09%) from 65.187%
14735285473

push

github

web-flow
TRUNK-6329: Modernize OpenMRS installation wizard UI to match the current OpenMRS branding (#4995)

0 of 50 new or added lines in 2 files covered. (0.0%)

11 existing lines in 4 files now uncovered.

23397 of 35943 relevant lines covered (65.09%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/web/src/main/java/org/openmrs/web/filter/util/SessionModelUtils.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.web.filter.util;
11

12
import org.openmrs.web.filter.initialization.InitializationWizardModel;
13
import org.slf4j.LoggerFactory;
14
import org.slf4j.Logger;
15

16
import javax.servlet.http.HttpSession;
17
import java.lang.reflect.Field;
18
import java.util.Enumeration;
19

20
/**
21
 * Utility class for saving and loading the state of an {@link InitializationWizardModel}
22
 * to and from an {@link HttpSession}.
23
 */
NEW
24
public class SessionModelUtils {
×
25
        
NEW
26
        private static final Logger log = LoggerFactory.getLogger(SessionModelUtils.class);
×
27
        
28
        private static final String PREFIX = "setup.";
29
        
30
        /**
31
         * Saves all non-null fields of the {@link InitializationWizardModel} to the HTTP session.
32
         * The field name is used as the session key, prefixed with "setup.".
33
         *
34
         * @param session the current {@link HttpSession}, must not be null
35
         * @param model the {@link InitializationWizardModel} to save
36
         */
37
        public static void saveToSession(HttpSession session, InitializationWizardModel model) {
NEW
38
                if (session == null || model == null) {
×
NEW
39
                        return;
×
40
                }
41
                
NEW
42
                for (Field field : model.getClass().getDeclaredFields()) {
×
NEW
43
                        field.setAccessible(true);
×
NEW
44
                        String fieldName = field.getName().toLowerCase();
×
45
                        // NOTE: Passwords should not be stored in session as this poses a risk of unintended exposure.
NEW
46
                        if (fieldName.contains("password")) {
×
NEW
47
                                continue;
×
48
                        }
49
                        try {
NEW
50
                                Object value = field.get(model);
×
NEW
51
                                if (value != null) {
×
NEW
52
                                        String key = PREFIX + field.getName();
×
NEW
53
                                        session.setAttribute(key, value);
×
54
                                }
NEW
55
                        } catch (IllegalAccessException e) {
×
NEW
56
                                log.error("Could not access field during save: {}", field.getName(), e);
×
NEW
57
                        }
×
58
                }
NEW
59
        }
×
60
        
61
        /**
62
         * Loads all existing session attributes (with "setup." prefix) into the corresponding fields
63
         * of the given {@link InitializationWizardModel}, if present.
64
         *
65
         * @param session the current {@link HttpSession}, must not be null
66
         * @param model the {@link InitializationWizardModel} to populate with values
67
         */
68
        public static void loadFromSession(HttpSession session, InitializationWizardModel model) {
NEW
69
                if (session == null || model == null) {
×
NEW
70
                        return;
×
71
                }
72
                
NEW
73
                for (Field field : model.getClass().getDeclaredFields()) {
×
NEW
74
                        field.setAccessible(true);
×
NEW
75
                        String fieldName = field.getName().toLowerCase();
×
76
                        // NOTE: Passwords should not be restored from session to avoid persisting sensitive credentials in memory.
NEW
77
                        if (fieldName.contains("password")) {
×
NEW
78
                                continue;
×
79
                        }
80
                        try {
NEW
81
                                String key = PREFIX + field.getName();
×
NEW
82
                                Object value = session.getAttribute(key);
×
NEW
83
                                if (value != null) {
×
NEW
84
                                        field.set(model, value);
×
85
                                }
NEW
86
                        } catch (IllegalAccessException e) {
×
NEW
87
                                log.error("Could not set field during load: {}", field.getName(), e);
×
NEW
88
                        }
×
89
                }
NEW
90
        }
×
91
        
92
        /**
93
         * Clears all session attributes previously saved by the wizard,
94
         * i.e., those with the "setup." prefix.
95
         *
96
         * @param session the current {@link HttpSession}, must not be null
97
         */
98
        public static void clearWizardSessionAttributes(HttpSession session) {
NEW
99
                if (session == null) {
×
NEW
100
                        return;
×
101
                }
102

NEW
103
                Enumeration<String> names = session.getAttributeNames();
×
NEW
104
                while (names.hasMoreElements()) {
×
NEW
105
                        String name = names.nextElement();
×
NEW
106
                        if (name.startsWith(PREFIX)) {
×
NEW
107
                                session.removeAttribute(name);
×
108
                        }
NEW
109
                }
×
NEW
110
        }
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc