Skip to content

Commit f749a7a

Browse files
committed
fixed README for multiple users
1 parent 2ff088f commit f749a7a

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ Build and run it with:
2626
```bash
2727
mvn package
2828

29-
java -jar target/fake_oidc.jar
29+
target/fake_oidc_server.jar
3030
```
3131

32-
By default the application runs at TCP port 8090, uses a self-signed certificate for localhost, and the only
33-
user has username "perun" and password "test". This can be changed by using command line options:
32+
By default the application runs at TCP port 8090, uses a self-signed certificate for localhost, and there are
33+
two users with lognames "perun" and "makub", and passwords "test". This can be changed by using command line options:
3434

3535
```bash
36-
java -jar target/fake_oidc.jar \
37-
--server.port=8100 \
38-
--server.ssl.key-store=mykeystore.p12 \
39-
--oidc.user.logname=john \
40-
--oidc.user.password=bflmpsvz \
41-
42-
--oidc.user.name="John Doe"
36+
target/fake_oidc_server.jar \
37+
--server.port=8100 \
38+
--server.ssl.key-store=mykeystore.p12 \
39+
--oidc.users.john.password=bflmpsvz \
40+
41+
42+
--oidc.users.john.given_name="John" \
43+
--oidc.users.john.family_name="Doe"
4344
```
4445
See all the available options in the file src/main/resources/application.yml
4546

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>cz.metacentrum</groupId>
1111
<artifactId>fake_oidc</artifactId>
12-
<version>1.3.0</version>
12+
<version>1.2.0</version>
1313
<name>fake_oidc</name>
1414
<description>Fake OpenId Connect Authorization Server</description>
1515

src/main/java/cz/metacentrum/fake_oidc/FakeOidcServerProperties.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
import org.springframework.boot.context.properties.ConfigurationProperties;
44
import org.springframework.stereotype.Component;
55

6+
import javax.annotation.PostConstruct;
67
import java.util.List;
8+
import java.util.Map;
79

810
@Component
911
@ConfigurationProperties(prefix="oidc")
1012
public class FakeOidcServerProperties {
1113

12-
private List<User> users;
14+
private Map<String,User> users;
1315
private long tokenExpirationSeconds;
1416

15-
public List<User> getUsers() {
17+
public Map<String, User> getUsers() {
1618
return users;
1719
}
1820

19-
public void setUsers(List<User> users) {
21+
public void setUsers(Map<String, User> users) {
2022
this.users = users;
2123
}
2224

@@ -35,4 +37,15 @@ public String toString() {
3537
", tokenExpirationSeconds=" + tokenExpirationSeconds +
3638
'}';
3739
}
40+
41+
@PostConstruct
42+
public void init() {
43+
for (Map.Entry<String, User> userEntry : users.entrySet()) {
44+
User user = userEntry.getValue();
45+
String login = userEntry.getKey();
46+
user.setLogname(login);
47+
user.setPreferred_username(login);
48+
user.setName(user.getGiven_name()+" "+user.getFamily_name());
49+
}
50+
}
3851
}

src/main/java/cz/metacentrum/fake_oidc/OidcController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ public ResponseEntity<?> authorize(@RequestParam String client_id,
274274
String[] creds = new String(Base64.getDecoder().decode(auth.split(" ")[1])).split(":", 2);
275275
String login = creds[0];
276276
String password = creds[1];
277-
List<User> users = serverProperties.getUsers();
278-
for (User user : users) {
277+
for (User user : serverProperties.getUsers().values()) {
279278
if (user.getLogname().equals(login) && user.getPassword().equals(password)) {
280279
log.info("password for user {} is correct", login);
281280
Set<String> responseType = setFromSpaceSeparatedString(response_type);

src/main/resources/application.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# every value can be changed from command line by preceding the option with --
22
# see https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-command-line-args
33
# example:
4-
# target/fake_oidc_server.jar --server.port=8100 -server.ssl.key-store=mykeystore.p12 --oidc.user.password=bflmpsvz
4+
# target/fake_oidc_server.jar --server.port=8100 -server.ssl.key-store=mykeystore.p12 --oidc.users.makub.password=bflmpsvz
55

66
server:
77
port: 8090
@@ -14,19 +14,15 @@ server:
1414
oidc:
1515
tokenExpirationSeconds: 36000
1616
users:
17-
- logname: "perun"
17+
perun:
1818
password: "test"
1919
sub: "perun1"
20-
name: "Master Perun"
2120
given_name: "Master"
2221
family_name: "Perun"
23-
preferred_username: "perun"
2422
25-
- logname: "makub"
23+
makub:
2624
password: "test"
2725
sub: "makub1"
28-
name: "Martin Kuba"
29-
given_name: "Kuba"
30-
family_name: "Martin"
31-
preferred_username: "makub"
26+
given_name: "Martin"
27+
family_name: "Kuba"
3228

0 commit comments

Comments
 (0)