SlideShare ist ein Scribd-Unternehmen logo
1 von 26
VULPES TRIBES BACKEND
OUR TEAM PROJECT AT GFA/HÚLI
08. 02. 2019
OUR TEAM HAS FOUR MEMBERS
JIŘINA KOPSOVÁ
• https://github.com/Kopsova/
• www.linkedin.com/in/jirinakopsova
PETER KOŽUCH
• https://github.com/PeterXMR
• www.linkedin.com/in/PeterKozuch
VOJTĚCH BLUDSKÝ
• https://github.com/Organt
• www.linkedin.com/in/vojtech-
bludsky
JIŘÍ SOUŠEK
• https://github.com/jsousek
• https://www.linkedin.com/in/jirisous
ek/
WE ALREADY SPEND 7 WEEKS WORKING ON
OUR APP
WHICH IS BEAUTIFUL :
SINCE IT IS A RESTFUL APPLICATION

LIST OF TECHNOLOGIES USED IN THE
PROJECT
• SPRING BOOT
• HIBERNATE
• ORACLE MYSQL
• FLYWAY DB MIGRATION
• JWT TOKEN AUTHENTICATION
• BCRYPT PW ENCRYPTION
• JUNIT
• MOCKITO TEST FRAMEWORK
• MOCK MVC
• JENKINS CI
• HEROKU DEPLOYMENT
• POSTMAN
WE ALREADY HAVE
• 54 CLASSES IN 5 PACKAGES
• 19 TESTS CLASSES WITH 53 TESTS
REQUESTS ARE PROCESSED WITH 7
CONTROLLERS
19 MODELS WITH DEPENDECIES
MAPPED AS ENTITIES FOR MYSQL DATABASE
SOME METHODS IN OUR PROJECT ARE
ELEGANT AND SIMPLE
public int getSumOfBuildingLevels(Kingdom kingdom, String buildingType) {
return kingdom.getBuildings().stream()
.filter(b -> b.getType().equals(buildingType))
.mapToInt(Building::getLevel)
.sum();
}
SOME COULD USE SOME REFACTORING OR
SIMPLIFICATION 
public List<ResourcesModel> resourceDisplayandUpdate(String username) {
Kingdom kingdomFromDB = kingdomService.verifyKingdom(username);
List<ResourcesModel> rmListFromDB = kingdomFromDB.getResourcesModel();
List<String>buildingTypes = Arrays.asList("mine","farm");
for (int i = 0; i < 2; i++) {
long OriginalUpdatedAt = rmListFromDB.get(i).getUpdatedAt();
String buildingType = buildingTypes.get(i);
long timeDiff = timeDifferenceInMinIn(OriginalUpdatedAt, System.currentTimeMillis());
long sumRes = getSumOfBuildingLevels(kingdomFromDB, buildingType);
rmListFromDB.get(i).setAmount(rmListFromDB.get(i).getAmount() + (timeDiff * sumRes));
rmListFromDB.get(i).setUpdatedAt(getCurrentTimestamp().getTime());
rmListFromDB.get(i).setGenerated(timeDiff * sumRes);
resourceRepository.save(rmListFromDB.get(i));
}
return rmListFromDB;
}
WHERE TO FIND OUR APP
URL:
https://vulpes-tribes-backend.herokuapp.com
GitHub Repository:
https://github.com/green-fox-academy/vulpes-
tribes-backend
BUT MOST OF ALL, IT
WORKS
👍
AS VOJTA WILL DEMONSTRATE IN POSTMAN
JWT TOKEN
AUTHENTICATION
JIŘINA KOPSOVA
public class SecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/kingdom/**", "/user/**").authenticated()
.antMatchers("/").permitAll()
.and()
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
.exceptionHandling().authenticationEntryPoint(forbiddenExceptionHandler);
}
{
"username": "adamgyulavari",
"password": "abc123"
}
Player loggs in with username and password:
} else if
(userTRepository.findTribesUserByUsername(tribesUser.getUsername()).get().getPasswo
rd().equals(tribesUser.getPassword())) {
TribesUser user =
userTRepository.findTribesUserByUsername(tribesUser.getUsername()).get();
user.setLoggedIn(true);
userTRepository.save(user);
return new ResponseEntity(
new
OKstatus(JWTService.createToken(tribesUser.getUsername())),HttpStatus.OK);
@PostMapping(value = "/login")
public ResponseEntity loginUser(@RequestBody TribesUser tribesUser) {
UserRestController
public class JWTService {
public static String createToken (String username){
String jwtToken = JWT.create()
.withSubject(username)
.withExpiresAt(new
Date(System.currentTimeMillis() + EXPIRATION_TIME))
.sign(HMAC512(SecurityConstants.SECRET.getBytes()))
;
return jwtToken;
}
Method createToken
USER IS LOGGED IN SUCCESSFULLY.
JWT TOKEN IS CREATED.
{ "status": "ok",
"tribes_token":
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZGFtZ3l1bGF2YXJpIiwiZX
hwIjoxNTQ5Mjc2NzQ1fQ.xYiud2OUo8TycTUt3nueW-
ULDEDA_sAc_fyi0joMUjb2uUF_1SfvhoC7zbU9uWNWHHuPO-zbxXiY1BkWJQ-
fmg "
}
To access secured endpoint, JWT token must be present in the header of each
HTTP request.
SECURITY IS HANDLED BY
JWTAUTHORISATIONFILTER
IT IS NOT NECESSARY TO SECURE EVERY
SINGLE ENDPOINT SEPARATELY.
public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
public JWTAuthorizationFilter(AuthenticationManager authManager) {
super(authManager);
}
@Override
protected void doFilterInternal(HttpServletRequest req,
HttpServletResponse res,
FilterChain chain) throws IOException, ServletException {
String header = req.getHeader(HEADER_STRING);
if (header == null) {
chain.doFilter(req, res);
return;
}
try {
UsernamePasswordAuthenticationToken authentication = getAuthentication(req);
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(req, res);
}catch (JWTDecodeException e ){
JWTService.invalidTokenResponce(res);
}
}
DATABASE MIGRATION
PETER KOŽUCH
WE ARE USING
FLYWAY
• TO HANDLE OUR
DATABASES MIGRATIONS
WHY WE HAVE DATABASE MIGRATIONS IN
OUR APP
• WE CAN HAVE SEVERAL VERSIONS OF OUR DATABASE
• WE CAN FILL DATABASE WITH DATA IN A CONTROLLED MANNER
• WE DO NOT NEED DROP DATABASE AT HEROKU IF DATABASE
STRUCTURE HAS BEEN CHANGED
TABLE OF OUR MIGRATIONS

Weitere ähnliche Inhalte

Ähnlich wie Vulpes tribes backend final

Azure Mobile Services .NET Backend
Azure Mobile Services .NET BackendAzure Mobile Services .NET Backend
Azure Mobile Services .NET BackendShiju Varghese
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
Drive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerDrive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerVodqaBLR
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Matt Raible
 
Retrofit Android by Chris Ollenburg
Retrofit Android by Chris OllenburgRetrofit Android by Chris Ollenburg
Retrofit Android by Chris OllenburgTrey Robinson
 
Centralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREdayCentralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREdayAndrew Kirkpatrick
 
Centralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gatewayCentralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gatewayAndrew Kirkpatrick
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Matt Raible
 
Authenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIsAuthenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIsJimmy Guerrero
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityJoris Kuipers
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APIKevin Hakanson
 
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET CoreNETFest
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioCaesar Chi
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsSimo Ahava
 
Foundations of a Social Application Platform
Foundations of a Social Application PlatformFoundations of a Social Application Platform
Foundations of a Social Application PlatformJonathan LeBlanc
 
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020AWSKRUG - AWS한국사용자모임
 

Ähnlich wie Vulpes tribes backend final (20)

Azure Mobile Services .NET Backend
Azure Mobile Services .NET BackendAzure Mobile Services .NET Backend
Azure Mobile Services .NET Backend
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Physical web
Physical webPhysical web
Physical web
 
Drive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerDrive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteer
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
Retrofit Android by Chris Ollenburg
Retrofit Android by Chris OllenburgRetrofit Android by Chris Ollenburg
Retrofit Android by Chris Ollenburg
 
Centralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREdayCentralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREday
 
Centralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gatewayCentralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gateway
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Authenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIsAuthenticating and Securing Node.js APIs
Authenticating and Securing Node.js APIs
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring Security
 
Securing TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography API
 
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
 
Foundations of a Social Application Platform
Foundations of a Social Application PlatformFoundations of a Social Application Platform
Foundations of a Social Application Platform
 
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
 

Kürzlich hochgeladen

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Kürzlich hochgeladen (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

Vulpes tribes backend final

  • 1. VULPES TRIBES BACKEND OUR TEAM PROJECT AT GFA/HÚLI 08. 02. 2019
  • 2. OUR TEAM HAS FOUR MEMBERS JIŘINA KOPSOVÁ • https://github.com/Kopsova/ • www.linkedin.com/in/jirinakopsova PETER KOŽUCH • https://github.com/PeterXMR • www.linkedin.com/in/PeterKozuch VOJTĚCH BLUDSKÝ • https://github.com/Organt • www.linkedin.com/in/vojtech- bludsky JIŘÍ SOUŠEK • https://github.com/jsousek • https://www.linkedin.com/in/jirisous ek/
  • 3. WE ALREADY SPEND 7 WEEKS WORKING ON OUR APP WHICH IS BEAUTIFUL : SINCE IT IS A RESTFUL APPLICATION 
  • 4. LIST OF TECHNOLOGIES USED IN THE PROJECT • SPRING BOOT • HIBERNATE • ORACLE MYSQL • FLYWAY DB MIGRATION • JWT TOKEN AUTHENTICATION • BCRYPT PW ENCRYPTION • JUNIT • MOCKITO TEST FRAMEWORK • MOCK MVC • JENKINS CI • HEROKU DEPLOYMENT • POSTMAN
  • 5. WE ALREADY HAVE • 54 CLASSES IN 5 PACKAGES • 19 TESTS CLASSES WITH 53 TESTS
  • 6.
  • 7. REQUESTS ARE PROCESSED WITH 7 CONTROLLERS
  • 8. 19 MODELS WITH DEPENDECIES
  • 9. MAPPED AS ENTITIES FOR MYSQL DATABASE
  • 10.
  • 11. SOME METHODS IN OUR PROJECT ARE ELEGANT AND SIMPLE public int getSumOfBuildingLevels(Kingdom kingdom, String buildingType) { return kingdom.getBuildings().stream() .filter(b -> b.getType().equals(buildingType)) .mapToInt(Building::getLevel) .sum(); }
  • 12. SOME COULD USE SOME REFACTORING OR SIMPLIFICATION  public List<ResourcesModel> resourceDisplayandUpdate(String username) { Kingdom kingdomFromDB = kingdomService.verifyKingdom(username); List<ResourcesModel> rmListFromDB = kingdomFromDB.getResourcesModel(); List<String>buildingTypes = Arrays.asList("mine","farm"); for (int i = 0; i < 2; i++) { long OriginalUpdatedAt = rmListFromDB.get(i).getUpdatedAt(); String buildingType = buildingTypes.get(i); long timeDiff = timeDifferenceInMinIn(OriginalUpdatedAt, System.currentTimeMillis()); long sumRes = getSumOfBuildingLevels(kingdomFromDB, buildingType); rmListFromDB.get(i).setAmount(rmListFromDB.get(i).getAmount() + (timeDiff * sumRes)); rmListFromDB.get(i).setUpdatedAt(getCurrentTimestamp().getTime()); rmListFromDB.get(i).setGenerated(timeDiff * sumRes); resourceRepository.save(rmListFromDB.get(i)); } return rmListFromDB; }
  • 13. WHERE TO FIND OUR APP URL: https://vulpes-tribes-backend.herokuapp.com GitHub Repository: https://github.com/green-fox-academy/vulpes- tribes-backend
  • 14. BUT MOST OF ALL, IT WORKS 👍 AS VOJTA WILL DEMONSTRATE IN POSTMAN
  • 16. public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeRequests() .antMatchers("/kingdom/**", "/user/**").authenticated() .antMatchers("/").permitAll() .and() .addFilter(new JWTAuthorizationFilter(authenticationManager())) .exceptionHandling().authenticationEntryPoint(forbiddenExceptionHandler); }
  • 17. { "username": "adamgyulavari", "password": "abc123" } Player loggs in with username and password:
  • 18. } else if (userTRepository.findTribesUserByUsername(tribesUser.getUsername()).get().getPasswo rd().equals(tribesUser.getPassword())) { TribesUser user = userTRepository.findTribesUserByUsername(tribesUser.getUsername()).get(); user.setLoggedIn(true); userTRepository.save(user); return new ResponseEntity( new OKstatus(JWTService.createToken(tribesUser.getUsername())),HttpStatus.OK); @PostMapping(value = "/login") public ResponseEntity loginUser(@RequestBody TribesUser tribesUser) { UserRestController
  • 19. public class JWTService { public static String createToken (String username){ String jwtToken = JWT.create() .withSubject(username) .withExpiresAt(new Date(System.currentTimeMillis() + EXPIRATION_TIME)) .sign(HMAC512(SecurityConstants.SECRET.getBytes())) ; return jwtToken; } Method createToken
  • 20. USER IS LOGGED IN SUCCESSFULLY. JWT TOKEN IS CREATED. { "status": "ok", "tribes_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZGFtZ3l1bGF2YXJpIiwiZX hwIjoxNTQ5Mjc2NzQ1fQ.xYiud2OUo8TycTUt3nueW- ULDEDA_sAc_fyi0joMUjb2uUF_1SfvhoC7zbU9uWNWHHuPO-zbxXiY1BkWJQ- fmg " } To access secured endpoint, JWT token must be present in the header of each HTTP request.
  • 21. SECURITY IS HANDLED BY JWTAUTHORISATIONFILTER IT IS NOT NECESSARY TO SECURE EVERY SINGLE ENDPOINT SEPARATELY.
  • 22. public class JWTAuthorizationFilter extends BasicAuthenticationFilter { public JWTAuthorizationFilter(AuthenticationManager authManager) { super(authManager); } @Override protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { String header = req.getHeader(HEADER_STRING); if (header == null) { chain.doFilter(req, res); return; } try { UsernamePasswordAuthenticationToken authentication = getAuthentication(req); SecurityContextHolder.getContext().setAuthentication(authentication); chain.doFilter(req, res); }catch (JWTDecodeException e ){ JWTService.invalidTokenResponce(res); } }
  • 24. WE ARE USING FLYWAY • TO HANDLE OUR DATABASES MIGRATIONS
  • 25. WHY WE HAVE DATABASE MIGRATIONS IN OUR APP • WE CAN HAVE SEVERAL VERSIONS OF OUR DATABASE • WE CAN FILL DATABASE WITH DATA IN A CONTROLLED MANNER • WE DO NOT NEED DROP DATABASE AT HEROKU IF DATABASE STRUCTURE HAS BEEN CHANGED
  • 26. TABLE OF OUR MIGRATIONS