Skip to content

Commit

Permalink
fix: atualização versão spring e refactor #64
Browse files Browse the repository at this point in the history
  • Loading branch information
tacianosilva committed Apr 19, 2024
1 parent d85a881 commit 0a9ba96
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 229 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/br/ufrn/dct/apf/APFApplication.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package br.ufrn.dct.apf;

import org.modelmapper.ModelMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EntityScan("br.ufrn.dct.apf")
Expand All @@ -13,9 +11,4 @@ public class APFApplication {
public static void main(String[] args) {
SpringApplication.run(APFApplication.class, args);
}

@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
Original file line number Diff line number Diff line change
@@ -1,81 +1,64 @@
package br.ufrn.dct.apf.configuration;

import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
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.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import javax.sql.DataSource;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
public class SecurityConfiguration {

@Autowired
private DataSource dataSource;

@Value("${spring.queries.users-query}")
private String usersQuery;

@Value("${spring.queries.roles-query}")
private String rolesQuery;

@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.
jdbcAuthentication()
.usersByUsernameQuery(usersQuery)
.authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource)
.passwordEncoder(passwordEncoder());
}
private UserDetailsService userDetailsService;

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

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
ModelMapper modelMapper() {
return new ModelMapper();
}

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

http.
authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/registration").permitAll()
.antMatchers("/admin/**").hasAuthority("ADMIN")
.antMatchers("/home").hasAuthority("USER").anyRequest()
.authenticated()
.and().csrf().disable()
.formLogin().loginPage("/login").failureUrl("/login?error=true")
.defaultSuccessUrl("/home")
.usernameParameter("email")
.passwordParameter("password")
.and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/").and().exceptionHandling()
.accessDeniedPage("/access-denied");

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}

@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**");
@Bean
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.
authorizeHttpRequests(requests ->
requests
.requestMatchers("/").permitAll()
.requestMatchers("/login").permitAll()
.requestMatchers("/registration").permitAll()
.requestMatchers("/admin/**").hasAuthority("ADMIN")
.requestMatchers("/home").hasAuthority("USER").anyRequest()
.authenticated()
).formLogin(login ->
login
.loginPage("/login")
.failureUrl("/login?error=true")
.defaultSuccessUrl("/home")
.usernameParameter("email")
.passwordParameter("password")
).logout(logout ->
logout
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")).exceptionHandling(handling -> handling
.accessDeniedPage("/access-denied"));
return http.build();
}
}
44 changes: 0 additions & 44 deletions src/main/java/br/ufrn/dct/apf/configuration/WebMvcConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class AbstractController {
private User overridenCurrentUser;

@Autowired
private UserService userService;
protected UserService userService;

protected void setUserAuth(ModelAndView modelAndView) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.Set;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/br/ufrn/dct/apf/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package br.ufrn.dct.apf.controller;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
Expand All @@ -23,7 +23,7 @@ public class LoginController extends AbstractController {

@Autowired
private UserService userService;

@Autowired
private ProjectService projectService;

Expand Down Expand Up @@ -89,10 +89,10 @@ public ModelAndView home() {
User user = getCurrentUser();

mv.addObject("projects", projectService.findByUserId(user.getId()));

return mv;
}

@GetMapping(path = "/dashboard")
public ModelAndView dashboard() {
ModelAndView mv = new ModelAndView("dashboard");
Expand All @@ -101,7 +101,7 @@ public ModelAndView dashboard() {
mv.addObject("projects", projectService.findByIsPrivateFalse());
mv.addObject("icounter", new IndicativeCount());
mv.addObject("ecounter", new EstimativeCount());

return mv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.Set;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -40,7 +40,7 @@ public class TransactionFunctionController extends AbstractController {
@GetMapping("/tf/add/{projectId}")
public ModelAndView add(TransactionFunctionDTO tf, @PathVariable("projectId") Long id) {
ModelAndView mv = new ModelAndView("tf/add");

Project project = projectService.findOne(id);
tf.setProject(project);
Set<UserStory> userStories = project.getUserStories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import javax.validation.Valid;
import jakarta.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -53,7 +53,7 @@ public ModelAndView add(UserStory us) {

return mv;
}

@GetMapping("/us/edit/{id}")
public ModelAndView edit(@PathVariable("id") Long id) {

Expand Down Expand Up @@ -82,9 +82,9 @@ public ModelAndView save(@Valid UserStory us, BindingResult result) {
}

User current = getCurrentUser();

Project project = null;

if (us.getProject() != null && us.getProject().getId() != null) {
project = projectService.findOne(us.getProject().getId());
} else {
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/br/ufrn/dct/apf/count/EstimativeCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import br.ufrn.dct.apf.model.TransactionFunction;
import br.ufrn.dct.apf.model.UserStory;
import br.ufrn.dct.apf.service.BusinessRuleException;
import br.ufrn.dct.apf.service.ProjectService;

public class EstimativeCount extends AbstractFunctionPointCount {

/**
* Logger.
*/
Expand All @@ -25,7 +24,7 @@ public int calculeFunctionPoint(Project project) throws BusinessRuleException {
int funcitionalSize = 0;
int dfSize = 0;
int tfSize = 0;

if (!dfs.isEmpty()) {
for (DataFunction dataFunction : dfs) {
int size = calculeFunctionPoint(dataFunction);
Expand All @@ -34,11 +33,11 @@ public int calculeFunctionPoint(Project project) throws BusinessRuleException {
}
funcitionalSize += dfSize;
}

if (!tfs.isEmpty()) {
for (TransactionFunction transFunction : tfs) {
int size = calculeFunctionPoint(transFunction);
tfSize += size;
int size = calculeFunctionPoint(transFunction);
tfSize += size;
logger.debug(project + " - " + transFunction + ": " + size + " PF");
}
funcitionalSize += tfSize;
Expand All @@ -55,7 +54,7 @@ public int calculeFunctionPoint(UserStory us) throws BusinessRuleException {
}
return i;
}

public int calculeFunctionPoint(DataFunction df) throws BusinessRuleException {
if (df != null && df.isILF()) {
return calculeFunctionPointILF(df);
Expand All @@ -65,7 +64,7 @@ public int calculeFunctionPoint(DataFunction df) throws BusinessRuleException {
throw new BusinessRuleException("error.count.indicative.datafunction.not.exists");
}
}

public int calculeFunctionPoint(TransactionFunction tf) throws BusinessRuleException {
if (tf != null && tf.isEI()) {
return calculeFunctionPointEI(tf);
Expand All @@ -77,23 +76,23 @@ public int calculeFunctionPoint(TransactionFunction tf) throws BusinessRuleExcep
throw new BusinessRuleException("error.count.indicative.datafunction.not.exists");
}
}

public int calculeFunctionPointILF(DataFunction df) {
return FunctionalSize.FUNCTION_POINT_ILF_LOW;
}

public int calculeFunctionPointEIF(DataFunction df) {
return FunctionalSize.FUNCTION_POINT_EIF_LOW;
}

public int calculeFunctionPointEI(TransactionFunction tf) {
return FunctionalSize.FUNCTION_POINT_EI_AVERAGE;
}

public int calculeFunctionPointEO(TransactionFunction tf) {
return FunctionalSize.FUNCTION_POINT_EO_AVERAGE;
}

public int calculeFunctionPointEQ(TransactionFunction tf) {
return FunctionalSize.FUNCTION_POINT_EQ_AVERAGE;
}
Expand Down
Loading

0 comments on commit 0a9ba96

Please sign in to comment.