Skip to content

Commit 4a5c76d

Browse files
Merge pull request #9934 from stuartwdouglas/runtime-embedded-config
Make embedded users runtime properties
2 parents 399e16b + ab5f12e commit 4a5c76d

File tree

4 files changed

+45
-50
lines changed

4 files changed

+45
-50
lines changed

extensions/elytron-security-properties-file/deployment/src/main/java/io/quarkus/elytron/security/properties/deployment/ElytronPropertiesProcessor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.quarkus.elytron.security.deployment.SecurityRealmBuildItem;
1515
import io.quarkus.elytron.security.runtime.ElytronPropertiesFileRecorder;
1616
import io.quarkus.elytron.security.runtime.MPRealmConfig;
17+
import io.quarkus.elytron.security.runtime.MPRealmRuntimeConfig;
1718
import io.quarkus.elytron.security.runtime.PropertiesRealmConfig;
1819
import io.quarkus.elytron.security.runtime.SecurityUsersConfig;
1920
import io.quarkus.runtime.RuntimeValue;
@@ -25,11 +26,6 @@
2526
* and {@linkplain org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm} realm implementations. Others could be
2627
* added by creating an extension that produces a SecurityRealmBuildItem for the realm.
2728
*
28-
* Additional authentication mechanisms can be added by producing AuthConfigBuildItems and including the associated
29-
* {@linkplain io.undertow.servlet.ServletExtension} implementations to register the
30-
* {@linkplain io.undertow.security.api.AuthenticationMechanismFactory}.
31-
*
32-
*
3329
*/
3430
class ElytronPropertiesProcessor {
3531
private static final Logger log = Logger.getLogger(ElytronPropertiesProcessor.class.getName());
@@ -39,6 +35,7 @@ class ElytronPropertiesProcessor {
3935
private static final String ROLES_PREFIX = "quarkus.security.embedded.roles";
4036

4137
SecurityUsersConfig propertiesConfig;
38+
MPRealmRuntimeConfig runtimeConfig;
4239

4340
@BuildStep
4441
FeatureBuildItem feature() {
@@ -112,7 +109,8 @@ void configureMPRealmConfig(ElytronPropertiesFileRecorder recorder,
112109

113110
RuntimeValue<SecurityRealm> realm = recorder.createRealm(realmConfig);
114111
securityRealm
115-
.produce(new SecurityRealmBuildItem(realm, realmConfig.realmName, recorder.loadRealm(realm, realmConfig)));
112+
.produce(new SecurityRealmBuildItem(realm, realmConfig.realmName,
113+
recorder.loadRealm(realm, realmConfig, runtimeConfig)));
116114
}
117115
}
118116
}

extensions/elytron-security-properties-file/runtime/src/main/java/io/quarkus/elytron/security/runtime/ElytronPropertiesFileRecorder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public void run() {
114114
* @param config - the realm config
115115
* @throws Exception
116116
*/
117-
public Runnable loadRealm(RuntimeValue<SecurityRealm> realm, MPRealmConfig config) throws Exception {
117+
public Runnable loadRealm(RuntimeValue<SecurityRealm> realm, MPRealmConfig config, MPRealmRuntimeConfig runtimeConfig)
118+
throws Exception {
118119
return new Runnable() {
119120
@Override
120121
public void run() {
@@ -125,15 +126,15 @@ public void run() {
125126
}
126127
SimpleMapBackedSecurityRealm memRealm = (SimpleMapBackedSecurityRealm) secRealm;
127128
HashMap<String, SimpleRealmEntry> identityMap = new HashMap<>();
128-
Map<String, String> userInfo = config.getUsers();
129+
Map<String, String> userInfo = runtimeConfig.users;
129130
log.debugf("UserInfoMap: %s%n", userInfo);
130-
Map<String, String> roleInfo = config.getRoles();
131+
Map<String, String> roleInfo = runtimeConfig.roles;
131132
log.debugf("RoleInfoMap: %s%n", roleInfo);
132133
for (Map.Entry<String, String> userPasswordEntry : userInfo.entrySet()) {
133134
Password password;
134135
String user = userPasswordEntry.getKey();
135136

136-
if (config.plainText) {
137+
if (runtimeConfig.plainText) {
137138
password = ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR,
138139
userPasswordEntry.getValue().toCharArray());
139140
} else {
Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.quarkus.elytron.security.runtime;
22

3-
import java.util.Map;
4-
53
import io.quarkus.runtime.annotations.ConfigGroup;
64
import io.quarkus.runtime.annotations.ConfigItem;
75

@@ -18,32 +16,12 @@ public class MPRealmConfig {
1816
@ConfigItem(defaultValue = "Quarkus")
1917
public String realmName;
2018

21-
/**
22-
* If the properties are stored in plain text. If this is false (the default) then it is expected
23-
* that the passwords are of the form HEX( MD5( username ":" realm ":" password ) )
24-
*/
25-
@ConfigItem
26-
public boolean plainText;
2719
/**
2820
* Determine whether security via the embedded realm is enabled.
2921
*/
3022
@ConfigItem
3123
public boolean enabled;
3224

33-
/**
34-
* The realm users user1=password\nuser2=password2... mapping.
35-
* See <a href="#embedded-users">Embedded Users</a>.
36-
*/
37-
@ConfigItem(defaultValueDocumentation = "none")
38-
public Map<String, String> users;
39-
40-
/**
41-
* The realm roles user1=role1,role2,...\nuser2=role1,role2,... mapping
42-
* See <a href="#embedded-roles">Embedded Roles</a>.
43-
*/
44-
@ConfigItem(defaultValueDocumentation = "none")
45-
public Map<String, String> roles;
46-
4725
public String getRealmName() {
4826
return realmName;
4927
}
@@ -60,29 +38,11 @@ public void setEnabled(boolean enabled) {
6038
this.enabled = enabled;
6139
}
6240

63-
public Map<String, String> getUsers() {
64-
return users;
65-
}
66-
67-
public void setUsers(Map<String, String> users) {
68-
this.users = users;
69-
}
70-
71-
public Map<String, String> getRoles() {
72-
return roles;
73-
}
74-
75-
public void setRoles(Map<String, String> roles) {
76-
this.roles = roles;
77-
}
78-
7941
@Override
8042
public String toString() {
8143
return "MPRealmConfig{" +
8244
", realmName='" + realmName + '\'' +
8345
", enabled=" + enabled +
84-
", users=" + users +
85-
", roles=" + roles +
8646
'}';
8747
}
8848
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.quarkus.elytron.security.runtime;
2+
3+
import java.util.Map;
4+
5+
import io.quarkus.runtime.annotations.ConfigItem;
6+
import io.quarkus.runtime.annotations.ConfigRoot;
7+
8+
/**
9+
* Configuration information used to populate a {@linkplain org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm}
10+
* }
11+
*/
12+
@ConfigRoot(name = "security.users.embedded")
13+
public class MPRealmRuntimeConfig {
14+
15+
/**
16+
* If the properties are stored in plain text. If this is false (the default) then it is expected
17+
* that the passwords are of the form HEX( MD5( username ":" realm ":" password ) )
18+
*/
19+
@ConfigItem
20+
public boolean plainText;
21+
22+
/**
23+
* The realm users user1=password\nuser2=password2... mapping.
24+
* See <a href="#embedded-users">Embedded Users</a>.
25+
*/
26+
@ConfigItem(defaultValueDocumentation = "none")
27+
public Map<String, String> users;
28+
29+
/**
30+
* The realm roles user1=role1,role2,...\nuser2=role1,role2,... mapping
31+
* See <a href="#embedded-roles">Embedded Roles</a>.
32+
*/
33+
@ConfigItem(defaultValueDocumentation = "none")
34+
public Map<String, String> roles;
35+
36+
}

0 commit comments

Comments
 (0)