Skip to content

Commit

Permalink
Custom form login (#53)
Browse files Browse the repository at this point in the history
* custom login

* login Status Codes

* removed from .dockerignore

* deleted dockerignore

---------

Co-authored-by: Sundarakrishnan N <[email protected]>
  • Loading branch information
ChiragJS and SundarakrishnanN authored Jun 5, 2024
1 parent 4838d96 commit 0e79b36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ out/
.vscode/

.env.prod
/src/main/resources/application-prod.properties

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public PasswordEncoder passwordEncoder() {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.formLogin(Customizer.withDefaults()).httpBasic(Customizer.withDefaults()).authorizeHttpRequests(SecurityConfiguration::getCustomizedHttpAuthorization).csrf(AbstractHttpConfigurer::disable)

http.formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer.failureForwardUrl("/loginStatus/failed").successForwardUrl("/loginStatus/success"))
.httpBasic(Customizer.withDefaults())
.authorizeHttpRequests(SecurityConfiguration::getCustomizedHttpAuthorization)
.csrf(AbstractHttpConfigurer::disable)
.cors(customizer->customizer.configurationSource(corsConfigurationSource()));

return http.build();
}

Expand All @@ -56,6 +59,7 @@ private static void getCustomizedHttpAuthorization(AuthorizeHttpRequestsConfigur
.requestMatchers("/role").hasRole("Admin")
.requestMatchers("/society").hasRole("Admin")
.requestMatchers("/").permitAll()
.requestMatchers("/loginStatus/**").permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
.anyRequest().authenticated();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.ieeervce.gatekeeper.controller;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@Controller
@RequestMapping("/loginStatus")
public class LoginStatusController {
@RequestMapping("/failed")
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
void loginFailed(){
return;
}
@RequestMapping("/success")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
void loginSuccess(){
return;
}
}

0 comments on commit 0e79b36

Please sign in to comment.