Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
/modelka.iml
/ui/ui.iml
/main.iml
/src/main/resources/static/node_modules/
/src/main/.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
5 changes: 5 additions & 0 deletions .run/Crome-debug.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Crome-debug" type="ChromiumRemoteDebugType" factoryName="Chromium Remote" port="56116" restartOnDisconnect="true">
<method v="2" />
</configuration>
</component>
48 changes: 39 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.1.RELEASE</version>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <source>8</source>-->
<!-- <target>8</target>-->
<!-- </configuration>-->
<!-- </plugin>-->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.0</version>
</plugin>



</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>static/node_modules/**/*.*</exclude>
</excludes>
</resource>
</resources>
</build>

<dependencies>
Expand All @@ -39,7 +47,12 @@
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- <version>2.9.10.5</version>-->
<!-- </dependency>-->

<dependency>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.0</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
Expand Down Expand Up @@ -78,10 +91,27 @@
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.27.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.20</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Base64 clases (added by Http)
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
</dependency>-->
</dependencies>
</project>
30 changes: 28 additions & 2 deletions src/main/java/ru/hedin/modelka/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,37 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication


public class Application
{
public static void main(String[] args){
SpringApplication.run( Application.class, args );
}
}

/*
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/*")
.allowedOrigins("http://localhost:8080")
.allowedMethods("POST","GET")
// .allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method",
// "Access-Control-Request-Headers")
.exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
// .allowCredentials(true).maxAge(3600);


;
}
};
*/
};

};
47 changes: 36 additions & 11 deletions src/main/java/ru/hedin/modelka/config/MvcConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
package ru.hedin.modelka.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfig
implements WebMvcConfigurer
{
public void addViewControllers( ViewControllerRegistry registry )
{
registry.addViewController( "/" )
.setViewName( "index" );
registry.addViewController( "/main" )
.setViewName( "main" );
registry.addViewController( "/login" )
.setViewName( "login" );
implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/")
.setViewName("index");
registry.addViewController("/main")
.setViewName("main");
registry.addViewController("/login")
.setViewName("login");

}
}

@Override
// @Bean

public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("POST","GET")
.allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method",
"Access-Control-Request-Headers")
.exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
.allowCredentials(true).maxAge(3600);

;

}

//
// @Bean
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**").allowedMethods("POST");
// }
};
12 changes: 6 additions & 6 deletions src/main/java/ru/hedin/modelka/config/PersistenceJPAConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
dataSource.setUsername("sa");
dataSource.setPassword("");
dataSource.setDriverClassName("org.postgresql.ds.PGSimpleDataSource");
dataSource.setUrl("jdbc:postgresql://localhost:5432/spring");
dataSource.setUsername("postgres");
dataSource.setPassword("qwe123");

return dataSource;
}
Expand Down Expand Up @@ -72,9 +72,9 @@ public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){

Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.hbm2ddl.auto", "update");
// properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgresPlusDialect");

return properties;
}
Expand Down
66 changes: 62 additions & 4 deletions src/main/java/ru/hedin/modelka/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,78 @@
package ru.hedin.modelka.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.cors.CorsConfiguration;

@Configuration
//@EnableWebSecurity (debug = true)
/// give 2 bean AuthenticationManager - runtime @EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
@EnableGlobalAuthentication
@ComponentScan
@ImportResource("classpath:security.xml")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {


// http.cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues());
//
//
// http.formLogin().defaultSuccessUrl("/username", true);
// http.authorizeRequests()
// .anyRequest().authenticated()
// .and().httpBasic();


/*

http
.csrf().disable()
.authorizeRequests()
.antMatchers("/register").permitAll()
.antMatchers("/log").permitAll()
.antMatchers("/username").permitAll()
.anyRequest().authenticated()

.antMatchers("/test/admin").hasRole("ROLE_ADMIN")
.antMatchers("/test/gm").hasRole("ROLE_GM")
.antMatchers("/test/user").hasRole("ROLE_USER")
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll()
.and().httpBasic();
*/

}


// @Bean


/*
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder(12);
}
*/

// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
package ru.hedin.modelka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import ru.hedin.modelka.domain.ModUser;
import ru.hedin.modelka.domain.RegistrationService;
import ru.hedin.modelka.service.TestRepository;
import ru.hedin.modelka.service.UserRepository;

@RestController("/register")
@RequestMapping("/register")
public class RegistrationController {

@Autowired
private TestRepository testRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private RegistrationService registrationService;

@GetMapping(name = "")
public String test(){
public String test() {
int size = testRepository.test();
return "test_"+size;
return "test_" + size;
}

@PostMapping(name = "", consumes = {MediaType.APPLICATION_JSON_VALUE})
public String registration(@RequestBody ModUser requestModel) {

ModUser modUser;

modUser = userRepository.getUserByLogin(requestModel.getUserName());

if (modUser != null) {
return "Already Exist";
}
// call Service
if (registrationService.creteUser(requestModel)) {
return "All Ok";
}
return "something wrong";
}


}
Loading