basic auth 🐷
This commit is contained in:
parent
f959016e8f
commit
6fe46ab346
25
.idea/workspace.xml
generated
25
.idea/workspace.xml
generated
@ -4,15 +4,11 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="bugfix">
|
<list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="add endpoints">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Entry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Entry.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/EmployeeRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/EmployeeRepository.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/service/EmployeeService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/EmployeeService.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -22,8 +18,8 @@
|
|||||||
<component name="FileTemplateManagerImpl">
|
<component name="FileTemplateManagerImpl">
|
||||||
<option name="RECENT_TEMPLATES">
|
<option name="RECENT_TEMPLATES">
|
||||||
<list>
|
<list>
|
||||||
<option value="Class" />
|
|
||||||
<option value="Interface" />
|
<option value="Interface" />
|
||||||
|
<option value="Class" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
@ -187,7 +183,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1740045412863</updated>
|
<updated>1740045412863</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="12" />
|
<task id="LOCAL-00012" summary="add endpoints">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1740049179417</created>
|
||||||
|
<option name="number" value="00012" />
|
||||||
|
<option name="presentableId" value="LOCAL-00012" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1740049179417</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="13" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
@ -202,7 +206,8 @@
|
|||||||
<MESSAGE value="fix secure" />
|
<MESSAGE value="fix secure" />
|
||||||
<MESSAGE value="add Entiries table and bugfix" />
|
<MESSAGE value="add Entiries table and bugfix" />
|
||||||
<MESSAGE value="bugfix" />
|
<MESSAGE value="bugfix" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="bugfix" />
|
<MESSAGE value="add endpoints" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="add endpoints" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
6
pom.xml
6
pom.xml
@ -33,6 +33,12 @@
|
|||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope> <!-- Indicates that this dependency is only required for the test phase -->
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.thymeleaf.extras</groupId>
|
<groupId>org.thymeleaf.extras</groupId>
|
||||||
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
|
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
|
||||||
|
@ -39,15 +39,6 @@ public class AuthController {
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class LoginBody {
|
private static class LoginBody {
|
||||||
private String login;
|
private String login;
|
||||||
private String password;
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogin() {
|
public String getLogin() {
|
||||||
return login;
|
return login;
|
||||||
@ -67,17 +58,7 @@ public class AuthController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/api/login/")
|
@PostMapping("/api/login/")
|
||||||
private RoleResponse login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
|
private RoleResponse login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
|
||||||
|
|
||||||
Employee employee = employeeRepository.getByLogin(loginBody.login).get();
|
Employee employee = employeeRepository.getByLogin(loginBody.login).get();
|
||||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
|
||||||
authorities.add(new SimpleGrantedAuthority(employee.getRole()));
|
|
||||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
|
|
||||||
loginBody.getLogin(), loginBody.getPassword(), authorities);
|
|
||||||
Authentication authentication = authenticationManager.authenticate(authRequest);
|
|
||||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
|
||||||
securityContext.setAuthentication(authentication);
|
|
||||||
HttpSession session = request.getSession(true);
|
|
||||||
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
|
|
||||||
RoleResponse response = new RoleResponse();
|
RoleResponse response = new RoleResponse();
|
||||||
response.setRole(employee.getRole());
|
response.setRole(employee.getRole());
|
||||||
return response;
|
return response;
|
||||||
|
@ -85,6 +85,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.and()
|
.and()
|
||||||
.formLogin().permitAll()
|
.formLogin().permitAll()
|
||||||
.and()
|
.and()
|
||||||
.logout().permitAll();
|
.logout().permitAll()
|
||||||
|
.and().httpBasic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user