Skip to content

Commit

Permalink
fixed README for multiple users
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kuba committed Jan 27, 2022
1 parent 2ff088f commit f749a7a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ Build and run it with:
```bash
mvn package

java -jar target/fake_oidc.jar
target/fake_oidc_server.jar
```

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

```bash
java -jar target/fake_oidc.jar \
--server.port=8100 \
--server.ssl.key-store=mykeystore.p12 \
--oidc.user.logname=john \
--oidc.user.password=bflmpsvz \
[email protected] \
--oidc.user.name="John Doe"
target/fake_oidc_server.jar \
--server.port=8100 \
--server.ssl.key-store=mykeystore.p12 \
--oidc.users.john.password=bflmpsvz \
[email protected] \
[email protected] \
--oidc.users.john.given_name="John" \
--oidc.users.john.family_name="Doe"
```
See all the available options in the file src/main/resources/application.yml

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>cz.metacentrum</groupId>
<artifactId>fake_oidc</artifactId>
<version>1.3.0</version>
<version>1.2.0</version>
<name>fake_oidc</name>
<description>Fake OpenId Connect Authorization Server</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Component
@ConfigurationProperties(prefix="oidc")
public class FakeOidcServerProperties {

private List<User> users;
private Map<String,User> users;
private long tokenExpirationSeconds;

public List<User> getUsers() {
public Map<String, User> getUsers() {
return users;
}

public void setUsers(List<User> users) {
public void setUsers(Map<String, User> users) {
this.users = users;
}

Expand All @@ -35,4 +37,15 @@ public String toString() {
", tokenExpirationSeconds=" + tokenExpirationSeconds +
'}';
}

@PostConstruct
public void init() {
for (Map.Entry<String, User> userEntry : users.entrySet()) {
User user = userEntry.getValue();
String login = userEntry.getKey();
user.setLogname(login);
user.setPreferred_username(login);
user.setName(user.getGiven_name()+" "+user.getFamily_name());
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/cz/metacentrum/fake_oidc/OidcController.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ public ResponseEntity<?> authorize(@RequestParam String client_id,
String[] creds = new String(Base64.getDecoder().decode(auth.split(" ")[1])).split(":", 2);
String login = creds[0];
String password = creds[1];
List<User> users = serverProperties.getUsers();
for (User user : users) {
for (User user : serverProperties.getUsers().values()) {
if (user.getLogname().equals(login) && user.getPassword().equals(password)) {
log.info("password for user {} is correct", login);
Set<String> responseType = setFromSpaceSeparatedString(response_type);
Expand Down
14 changes: 5 additions & 9 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# every value can be changed from command line by preceding the option with --
# see https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-command-line-args
# example:
# target/fake_oidc_server.jar --server.port=8100 -server.ssl.key-store=mykeystore.p12 --oidc.user.password=bflmpsvz
# target/fake_oidc_server.jar --server.port=8100 -server.ssl.key-store=mykeystore.p12 --oidc.users.makub.password=bflmpsvz

server:
port: 8090
Expand All @@ -14,19 +14,15 @@ server:
oidc:
tokenExpirationSeconds: 36000
users:
- logname: "perun"
perun:
password: "test"
sub: "perun1"
name: "Master Perun"
given_name: "Master"
family_name: "Perun"
preferred_username: "perun"
email: "[email protected]"
- logname: "makub"
makub:
password: "test"
sub: "makub1"
name: "Martin Kuba"
given_name: "Kuba"
family_name: "Martin"
preferred_username: "makub"
given_name: "Martin"
family_name: "Kuba"
email: "[email protected]"

0 comments on commit f749a7a

Please sign in to comment.