Skip to content

Commit

Permalink
added login page and secured all other pages (#5, #6, #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
thombergs committed Jan 7, 2017
1 parent 729f490 commit d2e5da2
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ public class GitanizerSecurityConfiguration extends WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/actuator").hasAnyRole("ADMIN")
.anyRequest().permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/static/**/*").permitAll()
.anyRequest().hasAnyRole("USER")
.and()
.httpBasic();
.formLogin()
/**/.loginPage("/login")
/**/.loginProcessingUrl("/do-login")
/**/.passwordParameter("password")
/**/.usernameParameter("username");

http.csrf().disable();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("admin").roles("ADMIN");
.withUser("user").password("user").roles("USER")
.and()
.withUser("admin").password("admin").roles("USER", "ADMIN");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public ResourcesConfiguration(GitRepositoryResolver gitRepositoryResolver, Workd

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/bootstrap/**").addResourceLocations("classpath:/bootstrap/");
registry.addResourceHandler("/AdminLTE/**").addResourceLocations("classpath:/AdminLTE/");
registry.addResourceHandler("/jQuery/**").addResourceLocations("classpath:/jQuery/");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
registry.addResourceHandler("/codemirror/**").addResourceLocations("classpath:/codemirror/");
registry.addResourceHandler("/gitanizer/**").addResourceLocations("classpath:/gitanizer/");
registry.addResourceHandler("/clipboardjs/**").addResourceLocations("classpath:/clipboardjs/");
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/img/");
registry.addResourceHandler("/static/bootstrap/**").addResourceLocations("classpath:/bootstrap/");
registry.addResourceHandler("/static/AdminLTE/**").addResourceLocations("classpath:/AdminLTE/");
registry.addResourceHandler("/static/jQuery/**").addResourceLocations("classpath:/jQuery/");
registry.addResourceHandler("/static/templates/**").addResourceLocations("classpath:/templates/");
registry.addResourceHandler("/static/codemirror/**").addResourceLocations("classpath:/codemirror/");
registry.addResourceHandler("/static/gitanizer/**").addResourceLocations("classpath:/gitanizer/");
registry.addResourceHandler("/static/clipboardjs/**").addResourceLocations("classpath:/clipboardjs/");
registry.addResourceHandler("/static/img/**").addResourceLocations("classpath:/img/");
registry.addResourceHandler("/git/**/*")
.resourceChain(true)
.addResolver(gitRepositoryResolver);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.wickedsource.gitanizer.login;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class LoginController {

@GetMapping(value = "/login")
public String displayLoginPage() {
return "login";
}

}
16 changes: 8 additions & 8 deletions src/main/resources/templates/layouts/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<head>
<meta charset="UTF-8"/>
<title>Gitanizer</title>
<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap.min.css}"/>
<link rel="stylesheet"
th:href="@{https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css}"/>
<link rel="stylesheet" th:href="@{https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css}"/>
<link rel="stylesheet" th:href="@{/AdminLTE/css/AdminLTE.min.css}"/>
<link rel="stylesheet" th:href="@{/AdminLTE/css/skins/skin-red.min.css}"/>
<link rel="stylesheet" th:href="@{/gitanizer/css/gitanizer.css}"/>
<link rel="stylesheet" th:href="@{/static/AdminLTE/css/AdminLTE.min.css}"/>
<link rel="stylesheet" th:href="@{/static/AdminLTE/css/skins/skin-red.min.css}"/>
<link rel="stylesheet" th:href="@{/static/gitanizer/css/gitanizer.css}"/>
<th:block layout:fragment="css"></th:block>
</head>
<body class="hold-transition skin-red layout-top-nav">
Expand Down Expand Up @@ -54,10 +54,10 @@

</div>

<script th:src="@{/jQuery/jquery-2.2.3.min.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{/AdminLTE/js/app.min.js}"></script>
<script th:src="@{/clipboardjs/js/clipboard.min.js}"/>
<script th:src="@{/static/jQuery/jquery-2.2.3.min.js}"></script>
<script th:src="@{/static/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{/static/AdminLTE/js/app.min.js}"></script>
<script th:src="@{/static/clipboardjs/js/clipboard.min.js}"/>
<script language="javascript">
new Clipboard('.btn');
</script>
Expand Down
54 changes: 54 additions & 0 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>gitanizer login</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap.min.css}"/>
<link rel="stylesheet"
th:href="@{https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css}"/>
<link rel="stylesheet" th:href="@{https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css}"/>
<link rel="stylesheet" th:href="@{/static/AdminLTE/css/AdminLTE.min.css}"/>

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<i class="fa fa-code-fork"></i>
<a href="/"><b>git</b>anizer</a>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>

<form action="/do-login" method="post">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="User name" name="username"/>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password"/>
</div>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>

</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<script th:src="@{/static/jQuery/jquery-2.2.3.min.js}"></script>
<script th:src="@{/static/bootstrap/js/bootstrap.min.js}"></script>
</body>
</html>

0 comments on commit d2e5da2

Please sign in to comment.