Skip to content
Snippets Groups Projects
Commit ba12ff1b authored by Kristiane Skogvang Kolshus's avatar Kristiane Skogvang Kolshus
Browse files

Merge branch 'final-changes' into 'main'

Final changes

See merge request !52
parents a7fbbad3 fc756f0a
Branches master
No related tags found
1 merge request!52Final changes
Pipeline #270181 passed
......@@ -21,5 +21,24 @@ public class FullstackProsjektApplication {
SpringApplication.run(FullstackProsjektApplication.class, args);
}
@Bean
CommandLineRunner run(RoleRepository roleRepository, UserRepository userRepository, PasswordEncoder encoder) {
return args -> {
// Exit early if DB already contains the admin user
if (roleRepository.findByAuthority("ADMIN").isPresent()) return;
Role adminRole = roleRepository.save(new Role("ADMIN"));
Role userRole = roleRepository.save(new Role("USER"));
Set<Role> roles = new HashSet<>();
roles.add(userRole);
User testUser = new User("test", encoder.encode("test"), roles);
if(userRepository.findByUsername(testUser.getUsername()).isEmpty()) userRepository.save(testUser);
roles.add(adminRole);
User admin = new User("admin", encoder.encode("password"), roles);
if(userRepository.findByUsername(admin.getUsername()).isEmpty()) userRepository.save(admin);
};
}
}
\ No newline at end of file
......@@ -76,7 +76,7 @@ public class SecurityConfiguration {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/api/**",
auth.requestMatchers("/api/auth/**",
"/v3/api-docs/",
"/swagger-ui/").permitAll();
auth.anyRequest().authenticated();
......
......@@ -5,15 +5,15 @@ export const apiClient = axios.create({
baseURL: 'http://localhost:8080/api',
//TODO: set api URL
});
/*
apiClient.interceptors.request.use(
(config) => {
const token = getToken();
if(token) {
config.headers['Authorization'] = `Bearer ${token}`;
}
}else
return config;
},
(error) => {
return Promise.reject(error);
});
\ No newline at end of file
//return Promise.reject("Problem with token: " + error);
});*/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment