Update the web configuration to add the TokenFactory.

This commit is contained in:
2023-12-01 18:49:49 +02:00
parent f7d81a2fb8
commit c6ff965796
2 changed files with 10 additions and 4 deletions
@@ -14,7 +14,9 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection;
import space.kklochko.spring_rest_example.db.repositories.IndicatorRepository;
import space.kklochko.spring_rest_example.models.Indicator;
import space.kklochko.spring_rest_example.models.factories.TokenFactory;
import space.kklochko.spring_rest_example.security.tokens.SimpleRandomToken;
import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory;
@EnableWebMvc
@Configuration
@@ -34,4 +36,10 @@ public class WebConfig implements WebMvcConfigurer {
public IndicatorRepository indicatorRepository(EntityManager manager) {
return new IndicatorRepository(manager);
}
@Bean
public TokenFactory tokenFactory() {
StringTokenFactory stringTokenFactory = new SimpleRandomToken();
return new TokenFactory(stringTokenFactory);
}
}
@@ -2,14 +2,13 @@ package space.kklochko.spring_rest_example.models.factories;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import space.kklochko.spring_rest_example.models.Token;
import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory;
@AllArgsConstructor
@Getter
public class TokenFactory {
public StringTokenFactory factory;
private StringTokenFactory factory;
public TokenFactory() {
setFactory(null);
@@ -25,7 +24,6 @@ public class TokenFactory {
return token;
}
@Autowired
public void setFactory(StringTokenFactory factory) {
this.factory = factory;
}