Skip to content

Commit

Permalink
+ Adds CSRF Controller
Browse files Browse the repository at this point in the history
+ Adds k8s Service
- Ignore/Skip Config Controllers from Swagger
* Fixes Swagger UI rendering
  • Loading branch information
naeemark committed Aug 23, 2020
1 parent 9427879 commit 974ca30
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .kubesail/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: jwt-auth-service
namespace: naeemark
selfLink: /api/v1/namespaces/naeemark/services/jwt-auth-service
uid: 953dec39-7ef5-4b05-9ac0-199230d85704
resourceVersion: "722169120"
creationTimestamp: 2020-08-21T06:18:42Z
labels:
app: myapp
spec:
ports:
- protocol: TCP
port: 8080
targetPort: http-ports
selector:
app: jwt-auth-service
clusterIP: 10.2.34.218
type: ClusterIP
sessionAffinity: None
status:
loadBalancer: {}
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/naeemark/jas/JwtAuthServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
Expand All @@ -25,4 +27,18 @@ public Docket api() {
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}

@Bean
public WebMvcConfigurer webMvcConfigurer()
{
return new WebMvcConfigurer()
{
@Override
public void addResourceHandlers( ResourceHandlerRegistry registry )
{
registry.addResourceHandler( "swagger-ui.html" ).addResourceLocations( "classpath:/META-INF/resources/" );
registry.addResourceHandler( "/webjars/**" ).addResourceLocations( "classpath:/META-INF/resources/webjars/" );
}
};
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/naeemark/jas/config/CSRFController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.naeemark.jas.config;

import org.springframework.http.ResponseEntity;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
* Created by Naeem <naeemark@gmail.com>.
* Required to fix 404 error on swagger-ui console
* <p>
* Created on: 2020-08-24
*/
@ApiIgnore
@Controller
public class CSRFController {
@RequestMapping(value = "/csrf", method = GET, produces = "application/json;charset=UTF-8")
public ResponseEntity<CsrfToken> getToken(final HttpServletRequest request) {
return ResponseEntity.ok().body(new HttpSessionCsrfTokenRepository().generateToken(request));
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/naeemark/jas/config/RootController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.naeemark.jas.config;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
* Created by Naeem <naeemark@gmail.com>.
* Required to fix 404 error on swagger-ui console
* <p>
* Created on: 2020-08-24
*/
@ApiIgnore
@RestController
@RequestMapping("/")
public class RootController {
@GetMapping
public ResponseEntity<String> getToken(final HttpServletRequest request) {
return ResponseEntity.ok().body("");
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/naeemark/jas/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Created by Naeem <naeemark@gmail.com>.
Expand All @@ -12,7 +12,7 @@
*/
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
Expand Down

0 comments on commit 974ca30

Please sign in to comment.