Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lottery Assessment #31

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/assessment.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/posttest.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BUISNESS SOLUTION.docx
Binary file not shown.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM amazoncorretto:21.0.2-alpine3.18

WORKDIR /app

COPY . .

RUN ["./gradlew","bootJar"]

ENTRYPOINT ["java", "-jar", "build/libs/posttest-0.0.1-SNAPSHOT.jar"]
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
web:
image: assessment_con:latest
ports:
- "8888:8888"
environment:
- ENV_VARIABLE=value
depends_on:
- database
volumes:
- ./path/to/local/directory:/app/data

database:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=lottery
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata:
7 changes: 7 additions & 0 deletions posttest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.hibernate.validator:hibernate-validator:6.2.0.Final'


implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'

}

tasks.named('test') {
Expand Down
Empty file modified posttest/gradlew
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
@SpringBootApplication
public class PosttestApplication {

public static void main(String[] args) {
SpringApplication.run(PosttestApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(PosttestApplication.class, args);
System.out.println("START OK! START OK!");


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.kbtg.bootcamp.posttest;

import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.WebSecurityConfiguration;
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.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.stereotype.Component;
import static org.springframework.security.config.Customizer.withDefaults;

@Component
@EnableWebSecurity
@Configuration
public class SecurityConfig {

@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.disable())
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/users/lotteries/**").permitAll()
.requestMatchers("/users/**").permitAll()
.requestMatchers(HttpMethod.POST, "/admin/lotteries").hasAuthority("ADMIN_CREATE")
.requestMatchers(HttpMethod.GET, "/admin/lotteries").hasAuthority("ADMIN_READ")
.anyRequest().authenticated()
)
.httpBasic(withDefaults())
.build();
}

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

@Bean
public UserDetailsService userDetailsService() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

UserDetails user = User.withUsername("admin")
.password(encoder.encode("password"))
.authorities("ADMIN_CREATE", "ADMIN_READ")
.build();

return new InMemoryUserDetailsManager(user);
}

}
Loading