Guest User

Untitled

a guest
Jun 28th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. import org.apache.catalina.filters.RequestDumperFilter;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.context.annotation.Profile;
  7. import org.springframework.core.annotation.Order;
  8. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  9. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  10. import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
  13. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  14.  
  15. @SpringBootApplication
  16. @EnableAuthorizationServer
  17. @RestController
  18. public class AuthorizationApplication {
  19.  
  20. public static void main(String[] args) {
  21. SpringApplication.run(AuthorizationApplication.class, args);
  22. }
  23.  
  24.  
  25. @Configuration
  26. static class MvcConfig extends WebMvcConfigurerAdapter {
  27. @Override
  28. public void addViewControllers(ViewControllerRegistry registry) {
  29. registry.addViewController("login").setViewName("login");
  30. registry.addViewController("/").setViewName("index");
  31. }
  32. }
  33.  
  34. @Configuration
  35. @Order(-20)
  36. static class LoginConfig extends WebSecurityConfigurerAdapter {
  37. @Override
  38. protected void configure(HttpSecurity http) throws Exception {
  39. http
  40. .formLogin().loginPage("/login").permitAll()
  41. .and()
  42. .requestMatchers()
  43. .antMatchers("/", "/login", "/oauth/authorize", "/oauth/confirm_access")
  44. .and()
  45. .authorizeRequests()
  46. .anyRequest().authenticated();
  47. }
  48. }
  49.  
  50. @Profile("!cloud")
  51. @Bean
  52. RequestDumperFilter requestDumperFilter() {
  53. return new RequestDumperFilter();
  54. }
  55.  
  56. }
  57.  
  58. import React, { Component } from 'react';
  59.  
  60. class Login extends React.Component {
  61. constructor(props) {
  62. super(props);
  63. this.state = {
  64. username: '',
  65. password: ''
  66. };
  67.  
  68. this.handleChange = this.handleChange.bind(this);
  69. this.handleSubmit = this.handleSubmit.bind(this);
  70. }
  71.  
  72. handleChange(event) {
  73. this.setState({ [event.target.name]: event.target.value });
  74. }
  75.  
  76. handleSubmit(event) {
  77. alert('A name was submitted: ' + this.state.username);
  78. event.preventDefault();
  79. }
  80.  
  81. render() {
  82. return (
  83. <form action='login' method='post' onSubmit={this.handleSubmit}>
  84. <label>
  85. Username:
  86. <input type="text" name="username" value={this.state.username} onChange={this.handleChange} />
  87. </label><br />
  88. <label>
  89. Password:
  90. <input type="password" name="password" value={this.state.password} onChange={this.handleChange} />
  91. </label><br />
  92. <input type="submit" value="Submit" />
  93. </form>
  94. );
  95. }
  96. }
  97. export default Login
Add Comment
Please, Sign In to add comment