Add data source properties retrieval and update related components

This commit is contained in:
liosha84
2025-06-30 19:14:15 +03:00
parent 5fce34dfb8
commit 0eeb93cd57
15 changed files with 209 additions and 15 deletions
@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
//@CrossOrigin(origins = "*", maxAge = 3600)
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600, allowCredentials="true")
@CrossOrigin(origins = "http://localhost:4200,https://a576-5-248-149-207.ngrok-free.app", maxAge = 3600, allowCredentials="true")
@RestController
@RequestMapping("/api/auth")
public class AuthController {
@@ -1,9 +1,12 @@
package com.jambotronGroup.jambotron.controllers;
import com.jambotronGroup.jambotron.model.Bean;
import com.jambotronGroup.jambotron.model.NameValueItem;
import com.jambotronGroup.jambotron.model.Setting;
import com.jambotronGroup.jambotron.system.SystemService;
import org.springframework.beans.factory.NamedBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -20,6 +23,24 @@ public class SystemController {
@GetMapping("/data-source-properties")
public ResponseEntity<List<NameValueItem>> getDataSourceProperties(@RequestParam(required = false) String title) {
try {
List<NameValueItem> properties = systemService.getDataSourceProperties();
//userRepository.findAll().forEach(users::add);
if (properties.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(properties, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/beans")
public ResponseEntity<List<Bean>> getLoadedBeans(@RequestParam(required = false) String title) {
try {
@@ -32,6 +32,7 @@ public class Bean {
@Override
public String toString() {
return String.format("name = %s type= %s", this.shortName, this.typeShortName);
}
@@ -0,0 +1,40 @@
package com.jambotronGroup.jambotron.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity
public class NameValueItem {
public NameValueItem(String name, String value){
_name = name;
_value = value;
}
@Id
private String _name;
private String _value;
public String getValue() {
return _value;
}
public void setValue(String _value) {
this._value = _value;
}
public String getName() {
return _name;
}
public void setName(String _name) {
this._name = _name;
}
@Override
public String toString() {
return String.format("name = %s value= %s", this._name, this._value);
}
}
@@ -16,6 +16,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableMethodSecurity
@@ -24,7 +26,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
// securedEnabled = true,
// jsr250Enabled = true,
//prePostEnabled = true)
public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsServiceImpl userDetailsService;
@@ -41,6 +43,11 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
// authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
// }
@Override
public void addCorsMappings(CorsRegistry registry) {
// Do not add any mappings to enable complete disabling of CORS.
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
@@ -108,6 +115,8 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
.requestMatchers("/resources/public/media/**").permitAll()
.requestMatchers("/resources/public/browser/**").permitAll()
.requestMatchers("/media/**").permitAll()
.requestMatchers("/main/**").permitAll()
.requestMatchers("/api/test/**").permitAll()
.requestMatchers("/api/tutorials").permitAll()
@@ -1,6 +1,7 @@
package com.jambotronGroup.jambotron.system;
import com.jambotronGroup.jambotron.model.Bean;
import com.jambotronGroup.jambotron.model.NameValueItem;
import java.util.List;
@@ -9,4 +10,6 @@ public interface SystemService {
List<Bean> getLodedCustomBeans();
List<NameValueItem> getDataSourceProperties();
}
@@ -2,16 +2,17 @@ package com.jambotronGroup.jambotron.system;
import com.jambotronGroup.jambotron.JambotronApplication;
import com.jambotronGroup.jambotron.model.Bean;
import com.jambotronGroup.jambotron.model.NameValueItem;
import com.jambotronGroup.jambotron.utils.EntityLoggingConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -23,9 +24,23 @@ public class SystemServiceImpl implements SystemService {
@Autowired
private Environment environment;
@Autowired
DataSourceProperties _dataSourceProperties;
private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class);
public List<NameValueItem> getDataSourceProperties(){
List<NameValueItem> returnValue = new ArrayList<NameValueItem>();
returnValue.add(new NameValueItem("Username", _dataSourceProperties.getUsername()));
returnValue.add(new NameValueItem("Password", _dataSourceProperties.getPassword()));
returnValue.add(new NameValueItem("Url", _dataSourceProperties.getUrl()));
return returnValue;
}
@Override
public List<Bean> getLodedBeans() {
// Get all bean names from the application context and map them to Bean objects