Skip to content

Commit

Permalink
Merge pull request #60 from OpsMx/OP-3853-Customize-Gate-Login-Form
Browse files Browse the repository at this point in the history
Op 3853 customize gate login form
  • Loading branch information
Pranav-b-7 authored Nov 20, 2020
2 parents 084e489 + 5de0de7 commit 7739b3f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gate-core/gate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
api "org.springframework.boot:spring-boot-starter-web"
api "org.springframework.boot:spring-boot-starter-actuator"
api "org.springframework.boot:spring-boot-starter-security"

api "org.springframework.boot:spring-boot-starter-thymeleaf"
api "com.squareup.retrofit:retrofit"

implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.builders.WebSecurity
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.core.Authentication
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler
import org.springframework.stereotype.Component
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import javax.servlet.Filter
import javax.servlet.ServletException
Expand Down Expand Up @@ -99,6 +99,7 @@ class AuthConfig {
.antMatchers(HttpMethod.POST, '/notifications/callbacks/**').permitAll()
.antMatchers('/health').permitAll()
.antMatchers('/**').authenticated()

if (fiatSessionFilterEnabled) {
Filter fiatSessionFilter = new FiatSessionFilter(
fiatSessionFilterEnabled,
Expand All @@ -108,6 +109,10 @@ class AuthConfig {
http.addFilterBefore(fiatSessionFilter, AnonymousAuthenticationFilter.class)
}

http.formLogin()
.loginPage("/login")
.permitAll()

http.logout()
.logoutUrl("/auth/logout")
.logoutSuccessHandler(permissionRevokingLogoutSuccessHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.handler.HandlerMappingIntrospector
import retrofit.RetrofitError
Expand Down Expand Up @@ -68,6 +69,8 @@ public class GateWebConfig implements WebMvcConfigurer {
@Value('${rate-limit.learning:true}')
Boolean rateLimitLearningMode



@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(
Expand Down Expand Up @@ -138,4 +141,8 @@ public class GateWebConfig implements WebMvcConfigurer {
void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false)
}

public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login")
}
}
87 changes: 87 additions & 0 deletions gate-web/src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>OES Login - Please sign in</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link href="https://getbootstrap.com/docs/4.0/examples/signin/signin.css" rel="stylesheet"
crossorigin="anonymous" />
</head>

<body>
<div class="container">
<div class="border-box">
<div class="align-center">
<img class="d-inline-block align-middle mr-2" id="myimgnew" src='https://www.opsmx.com/images/logo.png' width="120">
</div>
<form class="form-signin signin-form" th:action="@{/login}" method="post">
<h2 class="form-signin-heading signin-title">Sign In</h2>
<div th:if="${param.error}" class="d-inline-block align-middle mr-2 error-message">
Invalid username and password.
</div>
<div th:if="${param.logout}" class="d-inline-block align-middle mr-2 info-message">
You have been logged out.
</div>
<p>
<label for="username" class="sr-only">username</label>
<input type="text" id="username" name="username" class="form-control" placeholder="username" required autofocus>
</p>
<p>
<label for="password" class="sr-only">password</label>
<input type="password" id="password" name="password" class="form-control" placeholder="password" required>
</p>
<button class="btn btn-lg btn-primary btn-block" type="submit">sign in</button>
</form>
</div>
</div>

<style>
.align-center {
margin: auto;
width: 50%;
padding: 2%;
text-align: center;
}

.error-message {
margin: auto;
color: red;
padding: 3%;
text-align: center;
}

.info-message {
margin: auto;
color: #469494;
padding: 3%;
text-align: center;
}

.signin-form {

}

.signin-title {
text-align: center;
font-size: 28px;
padding: 3% 0;
}

.border-box {
border: 1px solid #bfbbbb;
border-radius: 10px;
width: 35%;
padding: 3% 0;
background: #fbfbfb;
margin: auto;
}
</style>
</body>

</html>

0 comments on commit 7739b3f

Please sign in to comment.