|
26 | 26 | import de.rwth.idsg.steve.repository.WebUserRepository;
|
27 | 27 | import jooq.steve.db.tables.records.WebUserRecord;
|
28 | 28 | import lombok.RequiredArgsConstructor;
|
| 29 | +import org.apache.commons.lang3.StringUtils; |
29 | 30 | import org.jooq.JSON;
|
30 | 31 | import org.springframework.context.event.ContextRefreshedEvent;
|
31 | 32 | import org.springframework.context.event.EventListener;
|
32 | 33 | import org.springframework.security.access.AccessDeniedException;
|
33 | 34 | import org.springframework.security.core.Authentication;
|
34 | 35 | import org.springframework.security.core.GrantedAuthority;
|
| 36 | +import org.springframework.security.core.authority.AuthorityUtils; |
35 | 37 | import org.springframework.security.core.context.SecurityContext;
|
36 | 38 | import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
37 | 39 | import org.springframework.security.core.userdetails.User;
|
@@ -80,14 +82,20 @@ public void afterStart(ContextRefreshedEvent event) {
|
80 | 82 | return;
|
81 | 83 | }
|
82 | 84 |
|
83 |
| - var user = User |
84 |
| - .withUsername(SteveConfiguration.CONFIG.getAuth().getUserName()) |
85 |
| - .password(SteveConfiguration.CONFIG.getAuth().getEncodedPassword()) |
86 |
| - .disabled(false) |
87 |
| - .authorities("ADMIN") |
88 |
| - .build(); |
| 85 | + var headerKey = SteveConfiguration.CONFIG.getWebApi().getHeaderKey(); |
| 86 | + |
| 87 | + var encodedApiPassword = StringUtils.isEmpty(headerKey) |
| 88 | + ? null |
| 89 | + : SteveConfiguration.CONFIG.getAuth().getPasswordEncoder().encode(headerKey); |
| 90 | + |
| 91 | + var user = new WebUserRecord() |
| 92 | + .setUsername(SteveConfiguration.CONFIG.getAuth().getUserName()) |
| 93 | + .setPassword(SteveConfiguration.CONFIG.getAuth().getEncodedPassword()) |
| 94 | + .setApiPassword(encodedApiPassword) |
| 95 | + .setEnabled(true) |
| 96 | + .setAuthorities(toJson(AuthorityUtils.createAuthorityList("ADMIN"))); |
89 | 97 |
|
90 |
| - this.createUser(user); |
| 98 | + webUserRepository.createUser(user); |
91 | 99 | }
|
92 | 100 |
|
93 | 101 | @Override
|
|
0 commit comments