Skip to content

Commit

Permalink
Attempt to resolve users and roles externally
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and mmusgrov committed Dec 12, 2019
1 parent e81fc09 commit b7afca9
Showing 1 changed file with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Provider;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -50,25 +53,37 @@ public Runnable loadRealm(RuntimeValue<SecurityRealm> realm, PropertiesRealmConf
return new Runnable() {
@Override
public void run() {
log.debugf("loadRealm, config=%s", config);
SecurityRealm secRealm = realm.getValue();
if (!(secRealm instanceof LegacyPropertiesSecurityRealm)) {
return;
}
log.debugf("Trying to loader users: /%s", config.users);
URL users = Thread.currentThread().getContextClassLoader().getResource(config.users);
log.debugf("users: %s", users);
log.debugf("Trying to loader roles: %s", config.roles);
URL roles = Thread.currentThread().getContextClassLoader().getResource(config.roles);
log.debugf("roles: %s", roles);
if (users == null && roles == null) {
String msg = String.format(
"No PropertiesRealmConfig users/roles settings found. Configure the quarkus.security.file.%s properties",
config.help());
throw new IllegalStateException(msg);
}
LegacyPropertiesSecurityRealm propsRealm = (LegacyPropertiesSecurityRealm) secRealm;
try {
log.debugf("loadRealm, config=%s", config);
SecurityRealm secRealm = realm.getValue();
if (!(secRealm instanceof LegacyPropertiesSecurityRealm)) {
return;
}
log.debugf("Trying to loader users: /%s", config.users);
URL users;
Path p = Paths.get(config.users);
if (Files.exists(p)) {
users = p.toUri().toURL();
} else {
users = Thread.currentThread().getContextClassLoader().getResource(config.users);
}
log.debugf("users: %s", users);
log.debugf("Trying to loader roles: %s", config.roles);
URL roles;
p = Paths.get(config.roles);
if (Files.exists(p)) {
roles = p.toUri().toURL();
} else {
roles = Thread.currentThread().getContextClassLoader().getResource(config.roles);
}
log.debugf("roles: %s", roles);
if (users == null && roles == null) {
String msg = String.format(
"No PropertiesRealmConfig users/roles settings found. Configure the quarkus.security.file.%s properties",
config.help());
throw new IllegalStateException(msg);
}
LegacyPropertiesSecurityRealm propsRealm = (LegacyPropertiesSecurityRealm) secRealm;
propsRealm.load(users.openStream(), roles.openStream());
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit b7afca9

Please sign in to comment.