Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 216a8f66

Přidáno uživatelem Jakub Danek před více než 5 roky(ů)

re #41 move enumerations from dto to domain package

Zobrazit rozdíly:

server/src/main/java/org/danekja/ymanager/MethodSecurityConfiguration.java
1
package org.danekja.ymanager;
2

  
3
import org.springframework.context.annotation.Configuration;
4
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
5
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
6

  
7
@Configuration
8
@EnableGlobalMethodSecurity (jsr250Enabled = true, prePostEnabled = true)
9
public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
10
}
server/src/main/java/org/danekja/ymanager/SecurityConfiguration.java
1
package org.danekja.ymanager;
2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
import org.springframework.context.annotation.Bean;
6
import org.springframework.context.annotation.Configuration;
7
import org.springframework.security.authentication.AuthenticationProvider;
8
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
10
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
11
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
12
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
13
import org.springframework.security.core.AuthenticationException;
14
import org.springframework.security.core.userdetails.UserDetails;
15
import org.springframework.security.core.userdetails.UserDetailsService;
16

  
17
@Configuration
18
@EnableWebSecurity
19
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
20

  
21
    @Override
22
    protected void configure(HttpSecurity http) throws Exception {
23
        http.cors()
24
                .and()
25
                .authorizeRequests()
26
                .anyRequest().authenticated()
27
                .and()
28
                .httpBasic();
29
    }
30

  
31
    /**
32
     * This is a dummy authentication provider which does not check password at all.
33
     * <p>
34
     * To be replaced with OAuth2 client
35
     *
36
     * @param userDetailsService
37
     * @return
38
     */
39
    @Bean
40
    public AuthenticationProvider dummyAuthManager(UserDetailsService userDetailsService) {
41
        return new AbstractUserDetailsAuthenticationProvider() {
42

  
43
            private final Logger LOG = LoggerFactory.getLogger("DummyLogger");
44

  
45
            @Override
46
            protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
47

  
48
            }
49

  
50
            @Override
51
            protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
52
                return userDetailsService.loadUserByUsername(username);
53
            }
54
        };
55
    }
56

  
57
}
server/src/main/java/org/danekja/ymanager/WebSecurityConfiguration.java
1
package org.danekja.ymanager;
2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
import org.springframework.context.annotation.Bean;
6
import org.springframework.context.annotation.Configuration;
7
import org.springframework.security.authentication.AuthenticationProvider;
8
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
10
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
11
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
12
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
13
import org.springframework.security.core.AuthenticationException;
14
import org.springframework.security.core.userdetails.UserDetails;
15
import org.springframework.security.core.userdetails.UserDetailsService;
16

  
17
@Configuration
18
@EnableWebSecurity
19
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
20

  
21
    @Override
22
    protected void configure(HttpSecurity http) throws Exception {
23
        http.cors()
24
                .and()
25
                .authorizeRequests()
26
                .anyRequest().authenticated()
27
                .and()
28
                .httpBasic();
29
    }
30

  
31
    /**
32
     * This is a dummy authentication provider which does not check password at all.
33
     * <p>
34
     * To be replaced with OAuth2 client
35
     *
36
     * @param userDetailsService
37
     * @return
38
     */
39
    @Bean
40
    public AuthenticationProvider dummyAuthManager(UserDetailsService userDetailsService) {
41
        return new AbstractUserDetailsAuthenticationProvider() {
42

  
43
            private final Logger LOG = LoggerFactory.getLogger("DummyLogger");
44

  
45
            @Override
46
            protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
47

  
48
            }
49

  
50
            @Override
51
            protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
52
                return userDetailsService.loadUserByUsername(username);
53
            }
54
        };
55
    }
56

  
57
}
server/src/main/java/org/danekja/ymanager/business/ApiManager.java
1 1
package org.danekja.ymanager.business;
2 2

  
3
import org.danekja.ymanager.domain.User;
4
import org.danekja.ymanager.domain.Vacation;
3
import org.danekja.ymanager.domain.*;
5 4
import org.danekja.ymanager.dto.*;
5
import org.danekja.ymanager.dto.DefaultSettings;
6 6
import org.danekja.ymanager.repository.RequestRepository;
7 7
import org.danekja.ymanager.repository.UserRepository;
8 8
import org.danekja.ymanager.repository.VacationRepository;
server/src/main/java/org/danekja/ymanager/business/Manager.java
1 1
package org.danekja.ymanager.business;
2 2

  
3
import org.danekja.ymanager.domain.RequestType;
4
import org.danekja.ymanager.domain.Status;
3 5
import org.danekja.ymanager.dto.*;
4 6
import org.danekja.ymanager.ws.rest.RESTFullException;
5 7

  
server/src/main/java/org/danekja/ymanager/business/mock/ManagerMock.java
1 1
package org.danekja.ymanager.business.mock;
2 2

  
3 3
import org.danekja.ymanager.business.Manager;
4
import org.danekja.ymanager.domain.RequestType;
5
import org.danekja.ymanager.domain.Status;
6
import org.danekja.ymanager.domain.UserRole;
7
import org.danekja.ymanager.domain.VacationType;
4 8
import org.danekja.ymanager.dto.*;
5 9
import org.danekja.ymanager.ws.rest.RESTFullException;
6 10

  
server/src/main/java/org/danekja/ymanager/domain/RequestType.java
1
package org.danekja.ymanager.domain;
2

  
3
/**
4
 * The enum {@code RequestType} represents different types of a request.
5
 */
6
public enum RequestType {
7
    /**
8
     * The request for a vacation.
9
     */
10
    VACATION,
11

  
12
    /**
13
     * The request for an authorization.
14
     */
15
    AUTHORIZATION;
16

  
17
    /**
18
     * Creates the type of a request from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param type the string representation of the type of a request
22
     * @return the value of the enum or null
23
     */
24
    public static RequestType getType(final String type) {
25
        if (type == null || type.isEmpty()) return null;
26
        try {
27
            return RequestType.valueOf(type.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/domain/Status.java
1
package org.danekja.ymanager.domain;
2

  
3
/**
4
 * The enum {@code Status} represents states of authorization and vacation approval process.
5
 */
6
public enum Status {
7
    /**
8
     * The subject of a request is accepted.
9
     */
10
    ACCEPTED,
11

  
12
    /**
13
     * The subject of a request is waiting for an answer.
14
     */
15
    PENDING,
16

  
17
    /**
18
     * The subject of a request is rejected.
19
     */
20
    REJECTED;
21

  
22
    /**
23
     * Creates the status from the provided string.
24
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
25
     *
26
     * @param status the string representation of the status
27
     * @return the value of the enum or null
28
     */
29
    public static Status getStatus(final String status) {
30
        if (status == null || status.isEmpty()) return null;
31
        try {
32
            return Status.valueOf(status.toUpperCase());
33
        } catch (final IllegalArgumentException e) {
34
            return null;
35
        }
36
    }
37
}
server/src/main/java/org/danekja/ymanager/domain/User.java
1 1
package org.danekja.ymanager.domain;
2 2

  
3
import org.danekja.ymanager.dto.Status;
4
import org.danekja.ymanager.dto.UserRole;
5 3
import org.slf4j.Logger;
6 4
import org.slf4j.LoggerFactory;
7 5
import org.springframework.security.core.GrantedAuthority;
server/src/main/java/org/danekja/ymanager/domain/UserRole.java
1
package org.danekja.ymanager.domain;
2

  
3
/**
4
 * The enum {@code UserRole} represents different roles of a user.
5
 */
6
public enum UserRole {
7
    /**
8
     * The user is an employee.
9
     */
10
    EMPLOYEE,
11

  
12
    /**
13
     * The user is na employer. This user has more rights than an employee.
14
     */
15
    EMPLOYER;
16

  
17
    /**
18
     * Creates the role from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param role the string representation of the role
22
     * @return the value of the enum or null
23
     */
24
    public static UserRole getUserRole(final String role) {
25
        if (role == null || role.isEmpty()) return null;
26
        try {
27
            return UserRole.valueOf(role.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/domain/Vacation.java
1 1
package org.danekja.ymanager.domain;
2 2

  
3
import org.danekja.ymanager.dto.Status;
4
import org.danekja.ymanager.dto.VacationType;
5 3
import org.slf4j.Logger;
6 4
import org.slf4j.LoggerFactory;
7 5

  
server/src/main/java/org/danekja/ymanager/domain/VacationType.java
1
package org.danekja.ymanager.domain;
2

  
3
/**
4
 * The enum {@code VacationType} represents different types of a vacation.
5
 */
6
public enum VacationType {
7
    /**
8
     * The vacation represents a sick day.
9
     */
10
    SICK_DAY,
11

  
12
    /**
13
     * The vacation represents an overtime.
14
     */
15
    VACATION;
16

  
17
    /**
18
     * Creates the type of a vacation from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param type the string representation of the type of a vacation
22
     * @return the value of the enum or null
23
     */
24
    public static VacationType getVacationType(final String type) {
25
        if (type == null || type.isEmpty()) return null;
26
        try {
27
            return VacationType.valueOf(type.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/dto/AuthorizationRequest.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.Status;
4

  
3 5
import java.time.LocalDateTime;
4 6

  
5 7
/**
server/src/main/java/org/danekja/ymanager/dto/BasicRequest.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.Status;
4

  
3 5
/**
4 6
 * An instance of the messenger class {@code BasicRequest} can represent an authorization or a vacation request.
5 7
 * The class is used for changing a status of the authorization or the vacation request when a client sends a request on an api endpoint.
server/src/main/java/org/danekja/ymanager/dto/FullUserProfile.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.Status;
3 4
import org.danekja.ymanager.domain.User;
5
import org.danekja.ymanager.domain.UserRole;
4 6

  
5 7
import java.time.LocalDateTime;
6 8

  
server/src/main/java/org/danekja/ymanager/dto/RequestType.java
1
package org.danekja.ymanager.dto;
2

  
3
/**
4
 * The enum {@code RequestType} represents different types of a request.
5
 */
6
public enum RequestType {
7
    /**
8
     * The request for a vacation.
9
     */
10
    VACATION,
11

  
12
    /**
13
     * The request for an authorization.
14
     */
15
    AUTHORIZATION;
16

  
17
    /**
18
     * Creates the type of a request from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param type the string representation of the type of a request
22
     * @return the value of the enum or null
23
     */
24
    public static RequestType getType(final String type) {
25
        if (type == null || type.isEmpty()) return null;
26
        try {
27
            return RequestType.valueOf(type.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/dto/Status.java
1
package org.danekja.ymanager.dto;
2

  
3
/**
4
 * The enum {@code Status} represents states of authorization and vacation approval process.
5
 */
6
public enum Status {
7
    /**
8
     * The subject of a request is accepted.
9
     */
10
    ACCEPTED,
11

  
12
    /**
13
     * The subject of a request is waiting for an answer.
14
     */
15
    PENDING,
16

  
17
    /**
18
     * The subject of a request is rejected.
19
     */
20
    REJECTED;
21

  
22
    /**
23
     * Creates the status from the provided string.
24
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
25
     *
26
     * @param status the string representation of the status
27
     * @return the value of the enum or null
28
     */
29
    public static Status getStatus(final String status) {
30
        if (status == null || status.isEmpty()) return null;
31
        try {
32
            return Status.valueOf(status.toUpperCase());
33
        } catch (final IllegalArgumentException e) {
34
            return null;
35
        }
36
    }
37
}
server/src/main/java/org/danekja/ymanager/dto/UserRole.java
1
package org.danekja.ymanager.dto;
2

  
3
/**
4
 * The enum {@code UserRole} represents different roles of a user.
5
 */
6
public enum UserRole {
7
    /**
8
     * The user is an employee.
9
     */
10
    EMPLOYEE,
11

  
12
    /**
13
     * The user is na employer. This user has more rights than an employee.
14
     */
15
    EMPLOYER;
16

  
17
    /**
18
     * Creates the role from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param role the string representation of the role
22
     * @return the value of the enum or null
23
     */
24
    public static UserRole getUserRole(final String role) {
25
        if (role == null || role.isEmpty()) return null;
26
        try {
27
            return UserRole.valueOf(role.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/dto/UserSettings.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.UserRole;
4

  
3 5
import java.time.LocalDateTime;
4 6

  
5 7
/**
server/src/main/java/org/danekja/ymanager/dto/VacationDay.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.Status;
4
import org.danekja.ymanager.domain.VacationType;
5

  
3 6
import java.time.LocalDate;
4 7
import java.time.LocalTime;
5 8

  
server/src/main/java/org/danekja/ymanager/dto/VacationRequest.java
1 1
package org.danekja.ymanager.dto;
2 2

  
3
import org.danekja.ymanager.domain.Status;
4
import org.danekja.ymanager.domain.VacationType;
5

  
3 6
import java.time.LocalDate;
4 7
import java.time.LocalDateTime;
5 8
import java.time.LocalTime;
server/src/main/java/org/danekja/ymanager/dto/VacationType.java
1
package org.danekja.ymanager.dto;
2

  
3
/**
4
 * The enum {@code VacationType} represents different types of a vacation.
5
 */
6
public enum VacationType {
7
    /**
8
     * The vacation represents a sick day.
9
     */
10
    SICK_DAY,
11

  
12
    /**
13
     * The vacation represents an overtime.
14
     */
15
    VACATION;
16

  
17
    /**
18
     * Creates the type of a vacation from the provided string.
19
     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
20
     *
21
     * @param type the string representation of the type of a vacation
22
     * @return the value of the enum or null
23
     */
24
    public static VacationType getVacationType(final String type) {
25
        if (type == null || type.isEmpty()) return null;
26
        try {
27
            return VacationType.valueOf(type.toUpperCase());
28
        } catch (final IllegalArgumentException e) {
29
            return null;
30
        }
31
    }
32
}
server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java
1 1
package org.danekja.ymanager.repository;
2 2

  
3
import org.danekja.ymanager.domain.Status;
4
import org.danekja.ymanager.domain.VacationType;
3 5
import org.danekja.ymanager.dto.*;
4 6
import org.slf4j.Logger;
5 7
import org.slf4j.LoggerFactory;
server/src/main/java/org/danekja/ymanager/repository/UserRepository.java
1 1
package org.danekja.ymanager.repository;
2 2

  
3
import org.danekja.ymanager.domain.Status;
3 4
import org.danekja.ymanager.domain.User;
5
import org.danekja.ymanager.domain.UserRole;
4 6
import org.danekja.ymanager.dto.*;
5 7
import org.danekja.ymanager.repository.jdbc.mappers.UserRowMapper;
6 8
import org.slf4j.Logger;
......
18 20
import java.util.Map;
19 21
import java.util.Optional;
20 22

  
21
import static org.danekja.ymanager.dto.UserRole.getUserRole;
23
import static org.danekja.ymanager.domain.UserRole.getUserRole;
22 24

  
23 25
/**
24 26
 * An instance of the class UserRepository handles queries which selects and updates users and their settings in a database.
server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java
2 2

  
3 3
import org.danekja.ymanager.domain.User;
4 4
import org.danekja.ymanager.domain.Vacation;
5
import org.danekja.ymanager.dto.Status;
6
import org.danekja.ymanager.dto.UserRole;
5
import org.danekja.ymanager.domain.Status;
6
import org.danekja.ymanager.domain.UserRole;
7 7
import org.danekja.ymanager.dto.VacationDay;
8
import org.danekja.ymanager.dto.VacationType;
8
import org.danekja.ymanager.domain.VacationType;
9 9
import org.slf4j.Logger;
10 10
import org.slf4j.LoggerFactory;
11 11
import org.springframework.beans.factory.annotation.Autowired;
......
21 21
import java.util.Optional;
22 22

  
23 23
import static java.util.Optional.ofNullable;
24
import static org.danekja.ymanager.dto.Status.getStatus;
24
import static org.danekja.ymanager.domain.Status.getStatus;
25 25

  
26 26
@Repository
27 27
public class VacationRepository {
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/UserRowMapper.java
1 1
package org.danekja.ymanager.repository.jdbc.mappers;
2 2

  
3 3
import org.danekja.ymanager.domain.User;
4
import org.danekja.ymanager.dto.Status;
5
import org.danekja.ymanager.dto.UserRole;
4
import org.danekja.ymanager.domain.Status;
5
import org.danekja.ymanager.domain.UserRole;
6 6
import org.springframework.jdbc.core.RowMapper;
7 7

  
8 8
import java.sql.ResultSet;
server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java
3 3
import org.apache.commons.lang3.StringUtils;
4 4
import org.danekja.ymanager.business.FileService;
5 5
import org.danekja.ymanager.business.Manager;
6
import org.danekja.ymanager.domain.RequestType;
7
import org.danekja.ymanager.domain.Status;
6 8
import org.danekja.ymanager.dto.*;
7 9
import org.danekja.ymanager.util.localization.Language;
8 10
import org.springframework.beans.factory.annotation.Autowired;
server/src/test/java/org/danekja/ymanager/domain/UserTest.java
1 1
package org.danekja.ymanager.domain;
2 2

  
3
import org.danekja.ymanager.dto.Status;
4
import org.danekja.ymanager.dto.UserRole;
5 3
import org.junit.jupiter.api.BeforeEach;
6 4
import org.junit.jupiter.api.Test;
7 5

  
server/src/test/java/org/danekja/ymanager/domain/VacationTest.java
1 1
package org.danekja.ymanager.domain;
2 2

  
3
import org.danekja.ymanager.dto.Status;
4
import org.danekja.ymanager.dto.VacationType;
5 3
import org.junit.jupiter.api.BeforeEach;
6 4
import org.junit.jupiter.api.Test;
7 5

  

Také k dispozici: Unified diff