Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajsingha committed Apr 27, 2020
1 parent e1b78b2 commit ddffb5b
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 3 deletions.
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<version>1.11.362</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.webservice.mobile.app;


/*
This RestAPI is Created By Raj Singha.
For testing and documentation run the app using docker
and visit --> http://localhost:8080/mobile-app-ws/swagger-ui.html
*/


import com.webservice.mobile.app.security.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -12,7 +21,6 @@
public class MobileAppWebServicesApplication extends SpringBootServletInitializer {

public static void main(String[] args) {

SpringApplication.run(MobileAppWebServicesApplication.class, args);
}

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/webservice/mobile/app/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.webservice.mobile.app;




import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;


@Configuration
@EnableSwagger2
public class SwaggerConfig {

Contact contact = new Contact(
"Raj Singha",
"https://rajsingha.codes",
"[email protected]"
);

List<VendorExtension> vendorExtensions = new ArrayList<>();

ApiInfo apiInfo = new ApiInfo(
"Mobile App WebService - RESTful Web Service Documentation ",
"This pages documents Mobile App WebService RESTful Web Service Endpoints",
"1.0",null,
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
vendorExtensions);

@Bean
public Docket apiDocket(){
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.protocols(new HashSet<>(Arrays.asList("HTTP","HTTPs")))
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.webservice.mobile.app"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public WebSecurity(UserService userService, BCryptPasswordEncoder bCryptPassword
protected void configure(HttpSecurity httpSecurity)throws Exception{
httpSecurity.csrf().disable().authorizeRequests()
.antMatchers(HttpMethod.POST,SecurityConstants.SIGN_UP_URL)
.permitAll().anyRequest().authenticated()
.permitAll()
.antMatchers("/v2/api-docs","/configuration/**","/swagger*/**","/webjars/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.addFilter(getAuthenticationFilter())
.addFilter(new AuthorizationFilter(authenticationManager()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.webservice.mobile.app.ui.controller;


import com.webservice.mobile.app.ui.model.request.LoginRequestModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthenticationController {


@ApiOperation("User Login")
@ApiResponses(value = {
@ApiResponse(code = 200,
message = "Response Headers",
responseHeaders = {
@ResponseHeader(name = "authorization",
description = "Bearer<JWT value her>",
response = String.class),
@ResponseHeader(name = "userId",
description = "<Public user id value here>",
response = String.class)
})
})
@PostMapping("/users/login")
public void theFakeLogin(@RequestBody LoginRequestModel loginRequestModel){
throw new IllegalStateException("This method should not be called." +
"This method is implemented by Spring Security");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import com.webservice.mobile.app.ui.model.response.OperationStatusModel;
import com.webservice.mobile.app.ui.model.response.RequestOperationStatus;
import com.webservice.mobile.app.ui.model.response.UserRest;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
Expand All @@ -23,6 +26,9 @@ public class UserController {
@Autowired
UserService userService;

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

@ApiImplicitParams({
@ApiImplicitParam(name ="authorization",
value ="${userController.authorizationHeader.description}",
paramType = "header")
})
@GetMapping(produces = {MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE})
public List<UserRest> getUsers(@RequestParam(value = "page",defaultValue = "0")int page,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.webservice.mobile.app.ui.model.request;

public class LoginRequestModel {
private String email;
private String password;

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
15 changes: 14 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

# This RestAPI is Created By Raj Singha.
# For testing and documentation run the app using docker
# and visit --> http://localhost:8080/mobile-app-ws/swagger-ui.html



#database admin
spring.datasource.username=raj
#database pass
Expand All @@ -9,4 +16,10 @@ spring.jpa.hibernate.ddl-auto=update
#token secret resource
tokenSecret = jf9i4jgu83nfl0;
#root url
server.servlet.context-path=/mobile-app-ws
server.servlet.context-path=/mobile-app-ws
server.port=8080
spring.h2.console.enabled=true

userController.authorizationHeader.description=Bearer JWT Token


0 comments on commit ddffb5b

Please sign in to comment.