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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ target
logs
attachments
*.patch

*.evn
.evn

20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stage 1: build with Maven and OpenJDK 17
FROM maven:3.9.5-eclipse-temurin-17 AS build

WORKDIR /app

COPY pom.xml .
RUN mvn dependency:go-offline

COPY src ./src

RUN mvn clean package -DskipTests

# Stage 2: runtime image with OpenJDK 17
FROM eclipse-temurin:17-jdk

WORKDIR /app

COPY --from=build /app/target/*.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]
2 changes: 1 addition & 1 deletion config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ server {
proxy_connect_timeout 150s;
}
location / {
try_files /view/404.html = 404;
try_files /view/404.html : 404;
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand Down
10 changes: 2 additions & 8 deletions resources/view/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ <h3 class="mb-3">Sign in</h3>
type="button">
<i class="fa-brands fa-google"></i>
</a>
<a class="btn btn-primary btn-lg me-2" href="/oauth2/authorization/vk" style="padding-left: 17px; padding-right: 17px;"
type="button">
<i class="fa-brands fa-vk"></i>
</a>
<a class="btn btn-danger btn-lg me-2" href="/oauth2/authorization/yandex" style="padding-left: 21px; padding-right: 21px;"
type="button">
<i class="fa-brands fa-yandex"></i>
</a>


<a class="btn btn-dark btn-lg me-2" href="/oauth2/authorization/github" type="button">
<i class="fa-brands fa-github"></i>
</a>
Expand Down
10 changes: 2 additions & 8 deletions resources/view/unauth/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ <h3 class="mb-3">Registration</h3>
type="button">
<i class="fa-brands fa-google"></i>
</a>
<a class="btn btn-primary btn-lg me-2" href="/oauth2/authorization/vk" style="padding-left: 17px; padding-right: 17px;"
type="button">
<i class="fa-brands fa-vk"></i>
</a>
<a class="btn btn-danger btn-lg me-2" href="/oauth2/authorization/yandex" style="padding-left: 21px; padding-right: 21px;"
type="button">
<i class="fa-brands fa-yandex"></i>
</a>


<a class="btn btn-dark btn-lg me-2" href="/oauth2/authorization/github" type="button">
<i class="fa-brands fa-github"></i>
</a>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/javarush/jira/JiraRushApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@EnableCaching
public class JiraRushApplication {

public static void main(String[] args) {
public static void main(String[] args)
{
SpringApplication.run(JiraRushApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

@UtilityClass
public class FileUtil {
Expand All @@ -24,15 +25,13 @@ public static void upload(MultipartFile multipartFile, String directoryPath, Str
if (multipartFile.isEmpty()) {
throw new IllegalRequestDataException("Select a file to upload.");
}

File dir = new File(directoryPath);
if (dir.exists() || dir.mkdirs()) {
File file = new File(directoryPath + fileName);
try (OutputStream outStream = new FileOutputStream(file)) {
outStream.write(multipartFile.getBytes());
} catch (IOException ex) {
throw new IllegalRequestDataException("Failed to upload file" + multipartFile.getOriginalFilename());
}
Path dirPath = Paths.get(directoryPath);
try {
Files.createDirectories(dirPath);
Path filePath = dirPath.resolve(fileName);
Files.write(filePath, multipartFile.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException ex) {
throw new IllegalRequestDataException("Failed to upload file: " + multipartFile.getOriginalFilename());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Component
@AllArgsConstructor
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Qualifier("handlerExceptionResolver")
private final HandlerExceptionResolver resolver;
private final RequestMappingHandlerMapping mapping;

public RestAuthenticationEntryPoint(
@Qualifier("handlerExceptionResolver") HandlerExceptionResolver resolver,
RequestMappingHandlerMapping mapping) {
this.resolver = resolver;
this.mapping = mapping;
}

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws ServletException {
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws ServletException {
try {
HandlerExecutionChain handler = mapping.getHandler(request);
resolver.resolveException(request, response, handler == null ? null : handler.getHandler(), authException);
} catch (Exception e) {
throw new ServletException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.javarush.jira.common.BaseRepository;
import com.javarush.jira.common.error.NotFoundException;
import com.javarush.jira.login.User;
import com.javarush.jira.login.AuthUser;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
Expand Down

This file was deleted.

This file was deleted.

69 changes: 6 additions & 63 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ app:
max-pool-size: 100

spring:

config:
import: optional:classpath:privacy.properties
init:
mode: never
jpa:
Expand All @@ -25,13 +28,10 @@ spring:
default_batch_fetch_size: 20
# https://stackoverflow.com/questions/21257819/what-is-the-difference-between-hibernate-jdbc-fetch-size-and-hibernate-jdbc-batc
jdbc.batch_size: 20
datasource:
url: jdbc:postgresql://localhost:5432/jira
username: jira
password: JiraRush

liquibase:
changeLog: "classpath:db/changelog.sql"
clear-checksums: true


# Jackson Fields Serialization
jackson:
Expand All @@ -46,59 +46,6 @@ spring:
cache-names: users
caffeine.spec: maximumSize=10000,expireAfterAccess=5m

security:
oauth2:
client:
registration:
github:
client-id: 3d0d8738e65881fff266
client-secret: 0f97031ce6178b7dfb67a6af587f37e222a16120
scope:
- email
google:
client-id: 329113642700-f8if6pu68j2repq3ef6umd5jgiliup60.apps.googleusercontent.com
client-secret: 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
scope:
- email
- profile
vk:
client-id: 51562377
client-secret: jNM1YHQy1362Mqs49wUN
client-name: Vkontakte
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
client-authentication-method: client_secret_post
authorization-grant-type: authorization_code
scope: email
yandex:
client-id: 2f3395214ba84075956b76a34b231985
client-secret: ed236c501e444a609b0f419e5e88f1e1
client-name: Yandex
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
authorization-grant-type: authorization_code
gitlab:
client-id: b8520a3266089063c0d8261cce36971defa513f5ffd9f9b7a3d16728fc83a494
client-secret: e72c65320cf9d6495984a37b0f9cc03ec46be0bb6f071feaebbfe75168117004
client-name: GitLab
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
authorization-grant-type: authorization_code
scope: read_user
provider:
vk:
authorization-uri: https://oauth.vk.com/authorize
token-uri: https://oauth.vk.com/access_token
user-info-uri: https://api.vk.com/method/users.get?v=8.1
user-name-attribute: response
yandex:
authorization-uri: https://oauth.yandex.ru/authorize
token-uri: https://oauth.yandex.ru/token
user-info-uri: https://login.yandex.ru/info
user-name-attribute: login
gitlab:
authorization-uri: https://gitlab.com/oauth/authorize
token-uri: https://gitlab.com/oauth/token
user-info-uri: https://gitlab.com/api/v4/user
user-name-attribute: email

sql:
init:
mode: always
Expand All @@ -110,10 +57,6 @@ spring:
starttls:
enable: true
auth: true
host: smtp.gmail.com
username: jira4jr@gmail.com
password: zdfzsrqvgimldzyj
port: 587
thymeleaf.check-template-location: false

mvc.throw-exception-if-no-handler-found: true
Expand All @@ -134,4 +77,4 @@ server:
charset: UTF-8 # Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly
enabled: true # Enable http encoding support
force: true
springdoc.swagger-ui.path: /doc
springdoc.swagger-ui.path: /doc
2 changes: 1 addition & 1 deletion src/main/resources/db/changelog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ values ('task', 'Task', 2),
('mobile', 'Mobile', 0),
('phone', 'Phone', 0),
('website', 'Website', 0),
('vk', 'VK', 0),

('linkedin', 'LinkedIn', 0),
('github', 'GitHub', 0),
-- PRIORITY
Expand Down
33 changes: 33 additions & 0 deletions src/main/resources/privacy.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# GitHub OAuth2
spring.security.oauth2.client.registration.github.client-id=3d0d8738e65881fff266
spring.security.oauth2.client.registration.github.client-secret=0f97031ce6178b7dfb67a6af587f37e222a16120
spring.security.oauth2.client.registration.github.scope=email

# Google OAuth2
spring.security.oauth2.client.registration.google.client-id=329113642700-f8if6pu68j2repq3ef6umd5jgiliup60.apps.googleusercontent.co
spring.security.oauth2.client.registration.google.client-secret=OCSPX-OCd-JBle221TaIBohCzQN9m9E-ap
spring.security.oauth2.client.registration.google.scope=email,profile

# GitLab OAuth2 (registration)
spring.security.oauth2.client.registration.gitlab.client-id=b8520a3266089063c0d8261cce36971defa513f5ffd9f9b7a3d16728fc83a494
spring.security.oauth2.client.registration.gitlab.client-secret=e72c65320cf9d6495984a37b0f9cc03ec46be0bb6f071feaebbfe75168117004
spring.security.oauth2.client.registration.gitlab.client-name=GitLab
spring.security.oauth2.client.registration.gitlab.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
spring.security.oauth2.client.registration.gitlab.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.gitlab.scope=read_user

# GitLab OAuth2 (provider)
spring.security.oauth2.client.provider.gitlab.authorization-uri=https://gitlab.com/oauth/authorize
spring.security.oauth2.client.provider.gitlab.token-uri=https://gitlab.com/oauth/token
spring.security.oauth2.client.provider.gitlab.user-info-uri=https://gitlab.com/api/v4/user
spring.security.oauth2.client.provider.gitlab.user-name-attribute=email

#datasource
spring.datasource.url=jdbc:postgresql://localhost:5432/jira
spring.datasource.username=jira
spring.datasource.password=JiraRush
#mail
spring.mail.host=smtp.gmail.com
spring.mail.username=jira4jr@gmail.com
spring.mail.password=zdfzsrqvgimldzyj
spring.mail.port=587
3 changes: 2 additions & 1 deletion src/test/java/com/javarush/jira/AbstractControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;

//https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-testing-spring-boot-applications
@Sql(scripts = {"classpath:db/changelog.sql", "classpath:data.sql"}, config = @SqlConfig(encoding = "UTF-8"))
@Sql(scripts = {"classpath:db/changelog.sql", "classpath:data-test.sql"}, config = @SqlConfig(encoding = "UTF-8"))
@AutoConfigureMockMvc
//https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-testing-spring-boot-applications-testing-with-mock-environment
public abstract class AbstractControllerTest extends BaseTests {
Expand All @@ -20,4 +20,5 @@ public abstract class AbstractControllerTest extends BaseTests {
protected ResultActions perform(MockHttpServletRequestBuilder builder) throws Exception {
return mockMvc.perform(builder);
}

}
Loading