Skip to content

Commit ddffb5b

Browse files
committed
Initial Commit
1 parent e1b78b2 commit ddffb5b

File tree

8 files changed

+184
-3
lines changed

8 files changed

+184
-3
lines changed

pom.xml

+31
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@
5757
<scope>provided</scope>
5858
</dependency>
5959

60+
<dependency>
61+
<groupId>com.amazonaws</groupId>
62+
<artifactId>aws-java-sdk-ses</artifactId>
63+
<version>1.11.362</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-engine</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>com.h2database</groupId>
74+
<artifactId>h2</artifactId>
75+
<scope>runtime</scope>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>io.springfox</groupId>
80+
<artifactId>springfox-swagger2</artifactId>
81+
<version>2.9.2</version>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>io.springfox</groupId>
86+
<artifactId>springfox-swagger-ui</artifactId>
87+
<version>2.9.2</version>
88+
</dependency>
89+
90+
6091
<dependency>
6192
<groupId>org.springframework.boot</groupId>
6293
<artifactId>spring-boot-starter-test</artifactId>

src/main/java/com/webservice/mobile/app/MobileAppWebServicesApplication.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.webservice.mobile.app;
22

3+
4+
/*
5+
This RestAPI is Created By Raj Singha.
6+
For testing and documentation run the app using docker
7+
and visit --> http://localhost:8080/mobile-app-ws/swagger-ui.html
8+
9+
*/
10+
11+
312
import com.webservice.mobile.app.security.AppProperties;
413
import org.springframework.boot.SpringApplication;
514
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -12,7 +21,6 @@
1221
public class MobileAppWebServicesApplication extends SpringBootServletInitializer {
1322

1423
public static void main(String[] args) {
15-
1624
SpringApplication.run(MobileAppWebServicesApplication.class, args);
1725
}
1826

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.webservice.mobile.app;
2+
3+
4+
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import springfox.documentation.builders.PathSelectors;
9+
import springfox.documentation.builders.RequestHandlerSelectors;
10+
import springfox.documentation.service.ApiInfo;
11+
import springfox.documentation.service.Contact;
12+
import springfox.documentation.service.VendorExtension;
13+
import springfox.documentation.spi.DocumentationType;
14+
import springfox.documentation.spring.web.plugins.Docket;
15+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
16+
17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
import java.util.HashSet;
20+
import java.util.List;
21+
22+
23+
@Configuration
24+
@EnableSwagger2
25+
public class SwaggerConfig {
26+
27+
Contact contact = new Contact(
28+
"Raj Singha",
29+
"https://rajsingha.codes",
30+
31+
);
32+
33+
List<VendorExtension> vendorExtensions = new ArrayList<>();
34+
35+
ApiInfo apiInfo = new ApiInfo(
36+
"Mobile App WebService - RESTful Web Service Documentation ",
37+
"This pages documents Mobile App WebService RESTful Web Service Endpoints",
38+
"1.0",null,
39+
contact,
40+
"Apache 2.0",
41+
"http://www.apache.org/licenses/LICENSE-2.0",
42+
vendorExtensions);
43+
44+
@Bean
45+
public Docket apiDocket(){
46+
Docket docket = new Docket(DocumentationType.SWAGGER_2)
47+
.protocols(new HashSet<>(Arrays.asList("HTTP","HTTPs")))
48+
.apiInfo(apiInfo)
49+
.select()
50+
.apis(RequestHandlerSelectors.basePackage("com.webservice.mobile.app"))
51+
.paths(PathSelectors.any())
52+
.build();
53+
return docket;
54+
}
55+
}

src/main/java/com/webservice/mobile/app/security/WebSecurity.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public WebSecurity(UserService userService, BCryptPasswordEncoder bCryptPassword
2424
protected void configure(HttpSecurity httpSecurity)throws Exception{
2525
httpSecurity.csrf().disable().authorizeRequests()
2626
.antMatchers(HttpMethod.POST,SecurityConstants.SIGN_UP_URL)
27-
.permitAll().anyRequest().authenticated()
27+
.permitAll()
28+
.antMatchers("/v2/api-docs","/configuration/**","/swagger*/**","/webjars/**")
29+
.permitAll()
30+
.anyRequest()
31+
.authenticated()
2832
.and()
2933
.addFilter(getAuthenticationFilter())
3034
.addFilter(new AuthorizationFilter(authenticationManager()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.webservice.mobile.app.ui.controller;
2+
3+
4+
import com.webservice.mobile.app.ui.model.request.LoginRequestModel;
5+
import io.swagger.annotations.ApiOperation;
6+
import io.swagger.annotations.ApiResponse;
7+
import io.swagger.annotations.ApiResponses;
8+
import io.swagger.annotations.ResponseHeader;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
public class AuthenticationController {
15+
16+
17+
@ApiOperation("User Login")
18+
@ApiResponses(value = {
19+
@ApiResponse(code = 200,
20+
message = "Response Headers",
21+
responseHeaders = {
22+
@ResponseHeader(name = "authorization",
23+
description = "Bearer<JWT value her>",
24+
response = String.class),
25+
@ResponseHeader(name = "userId",
26+
description = "<Public user id value here>",
27+
response = String.class)
28+
})
29+
})
30+
@PostMapping("/users/login")
31+
public void theFakeLogin(@RequestBody LoginRequestModel loginRequestModel){
32+
throw new IllegalStateException("This method should not be called." +
33+
"This method is implemented by Spring Security");
34+
35+
}
36+
37+
}

src/main/java/com/webservice/mobile/app/ui/controller/UserController.java

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import com.webservice.mobile.app.ui.model.response.OperationStatusModel;
99
import com.webservice.mobile.app.ui.model.response.RequestOperationStatus;
1010
import com.webservice.mobile.app.ui.model.response.UserRest;
11+
import io.swagger.annotations.ApiImplicitParam;
12+
import io.swagger.annotations.ApiImplicitParams;
13+
import io.swagger.annotations.ApiOperation;
1114
import org.springframework.beans.BeanUtils;
1215
import org.springframework.beans.factory.annotation.Autowired;
1316
import org.springframework.http.MediaType;
@@ -23,6 +26,9 @@ public class UserController {
2326
@Autowired
2427
UserService userService;
2528

29+
@ApiOperation(value = "The Get User Details Web Service Endpoint",
30+
notes = "This Web Service Endpoint returns User Details. User public user id in URL path." +
31+
"For Example: /user/<User Id here>")
2632
@GetMapping(path = "/{id}", produces = {MediaType.APPLICATION_XML_VALUE,
2733
MediaType.APPLICATION_JSON_VALUE})
2834
public UserRest getUser(@PathVariable String id){
@@ -88,6 +94,11 @@ public OperationStatusModel deleteUser(@PathVariable String id){
8894
return returnValue;
8995
}
9096

97+
@ApiImplicitParams({
98+
@ApiImplicitParam(name ="authorization",
99+
value ="${userController.authorizationHeader.description}",
100+
paramType = "header")
101+
})
91102
@GetMapping(produces = {MediaType.APPLICATION_XML_VALUE,
92103
MediaType.APPLICATION_JSON_VALUE})
93104
public List<UserRest> getUsers(@RequestParam(value = "page",defaultValue = "0")int page,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.webservice.mobile.app.ui.model.request;
2+
3+
public class LoginRequestModel {
4+
private String email;
5+
private String password;
6+
7+
public String getEmail() {
8+
return email;
9+
}
10+
11+
public void setEmail(String email) {
12+
this.email = email;
13+
}
14+
15+
public String getPassword() {
16+
return password;
17+
}
18+
19+
public void setPassword(String password) {
20+
this.password = password;
21+
}
22+
}

src/main/resources/application.properties

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
# This RestAPI is Created By Raj Singha.
3+
# For testing and documentation run the app using docker
4+
# and visit --> http://localhost:8080/mobile-app-ws/swagger-ui.html
5+
6+
7+
18
#database admin
29
spring.datasource.username=raj
310
#database pass
@@ -9,4 +16,10 @@ spring.jpa.hibernate.ddl-auto=update
916
#token secret resource
1017
tokenSecret = jf9i4jgu83nfl0;
1118
#root url
12-
server.servlet.context-path=/mobile-app-ws
19+
server.servlet.context-path=/mobile-app-ws
20+
server.port=8080
21+
spring.h2.console.enabled=true
22+
23+
userController.authorizationHeader.description=Bearer JWT Token
24+
25+

0 commit comments

Comments
 (0)