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

openmrs / openmrs-core / 15031236718

14 May 2025 09:13PM UTC coverage: 65.069% (+0.2%) from 64.869%
15031236718

push

github

web-flow
TRUNK-6329: Add consistent font style and change openmrs logo in the footer (#5025)

* TRUNK-6329: Add consistent font style and change openmrs logo in footer

* add more fixes that have been reported

* Fix storeLocale to handle duplicate entry by updating existing user property

* fix localization

* exclude localeToSave from wizard model fields to be persisted

0 of 2 new or added lines in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

23389 of 35945 relevant lines covered (65.07%)

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
 */
24
public class SessionModelUtils {
×
25
        
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) {
38
                if (session == null || model == null) {
×
39
                        return;
×
40
                }
41
                
42
                for (Field field : model.getClass().getDeclaredFields()) {
×
43
                        field.setAccessible(true);
×
44
                        String fieldName = field.getName().toLowerCase();
×
45
                        // NOTE: Passwords should not be stored in session as this poses a risk of unintended exposure.
46
                        // Also exclude localeToSave as it's a temporary value that shouldn't be persisted
NEW
47
                        if (fieldName.contains("password") || fieldName.equals("localetosave")) {
×
UNCOV
48
                                continue;
×
49
                        }
50
                        try {
51
                                Object value = field.get(model);
×
52
                                if (value != null) {
×
53
                                        String key = PREFIX + field.getName();
×
54
                                        session.setAttribute(key, value);
×
55
                                }
56
                        } catch (IllegalAccessException e) {
×
57
                                log.error("Could not access field during save: {}", field.getName(), e);
×
58
                        }
×
59
                }
60
        }
×
61
        
62
        /**
63
         * Loads all existing session attributes (with "setup." prefix) into the corresponding fields
64
         * of the given {@link InitializationWizardModel}, if present.
65
         *
66
         * @param session the current {@link HttpSession}, must not be null
67
         * @param model the {@link InitializationWizardModel} to populate with values
68
         */
69
        public static void loadFromSession(HttpSession session, InitializationWizardModel model) {
70
                if (session == null || model == null) {
×
71
                        return;
×
72
                }
73
                
74
                for (Field field : model.getClass().getDeclaredFields()) {
×
75
                        field.setAccessible(true);
×
76
                        String fieldName = field.getName().toLowerCase();
×
77
                        // NOTE: Passwords should not be restored from session to avoid persisting sensitive credentials in memory.
78
                        // Also exclude localeToSave as it's a temporary value that shouldn't be persisted
NEW
79
                        if (fieldName.contains("password") || fieldName.equals("localetosave")) {
×
UNCOV
80
                                continue;
×
81
                        }
82
                        try {
83
                                String key = PREFIX + field.getName();
×
84
                                Object value = session.getAttribute(key);
×
85
                                if (value != null) {
×
86
                                        field.set(model, value);
×
87
                                }
88
                        } catch (IllegalAccessException e) {
×
89
                                log.error("Could not set field during load: {}", field.getName(), e);
×
90
                        }
×
91
                }
92
        }
×
93
        
94
        /**
95
         * Clears all session attributes previously saved by the wizard,
96
         * i.e., those with the "setup." prefix.
97
         *
98
         * @param session the current {@link HttpSession}, must not be null
99
         */
100
        public static void clearWizardSessionAttributes(HttpSession session) {
101
                if (session == null) {
×
102
                        return;
×
103
                }
104

105
                Enumeration<String> names = session.getAttributeNames();
×
106
                while (names.hasMoreElements()) {
×
107
                        String name = names.nextElement();
×
108
                        if (name.startsWith(PREFIX)) {
×
109
                                session.removeAttribute(name);
×
110
                        }
111
                }
×
112
        }
×
113
}
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