├── README.md ├── UI ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── src │ ├── redux │ │ ├── types.js │ │ ├── reducers │ │ │ ├── index.js │ │ │ └── auth.js │ │ ├── store.js │ │ └── authActions.js │ ├── setupTests.js │ ├── App.test.js │ ├── index.css │ ├── reportWebVitals.js │ ├── App.js │ ├── api │ │ └── authenticationService.js │ ├── App.css │ ├── index.js │ ├── pages │ │ ├── loginpage.css │ │ ├── dashboard │ │ │ └── dashboard.js │ │ └── LoginPage.js │ └── logo.svg ├── .gitignore ├── package.json └── README.md ├── backend ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── thecodeveal │ │ │ └── app │ │ │ ├── responses │ │ │ ├── LoginResponse.java │ │ │ └── UserInfo.java │ │ │ ├── requests │ │ │ └── AuthenticationRequest.java │ │ │ ├── repository │ │ │ └── UserDetailsRepository.java │ │ │ ├── controllers │ │ │ ├── AppController.java │ │ │ └── AuthenticationController.java │ │ │ ├── config │ │ │ ├── RestAuthenticationEntryPoint.java │ │ │ ├── JWTAuthenticationFilter.java │ │ │ ├── SecurityConfiguration.java │ │ │ └── JWTTokenHelper.java │ │ │ ├── services │ │ │ └── CustomUserService.java │ │ │ ├── entities │ │ │ ├── Authority.java │ │ │ └── User.java │ │ │ └── SpringSecurityDemoAppApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── thecodeveal │ │ └── app │ │ └── SpringSecurityDemoAppApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw └── .github └── workflows └── deploy.yml /README.md: -------------------------------------------------------------------------------- 1 | # Spring-Security-Auth-Demo Application + Reactjs 2 | -------------------------------------------------------------------------------- /UI/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /UI/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pardeep16/Spring-Security-Auth-Demo/HEAD/UI/public/favicon.ico -------------------------------------------------------------------------------- /UI/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pardeep16/Spring-Security-Auth-Demo/HEAD/UI/public/logo192.png -------------------------------------------------------------------------------- /UI/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pardeep16/Spring-Security-Auth-Demo/HEAD/UI/public/logo512.png -------------------------------------------------------------------------------- /UI/src/redux/types.js: -------------------------------------------------------------------------------- 1 | export const AUTH_REQ="AUTH_REQUEST"; 2 | export const AUTH_SUCCESS="AUTH_SUCCESS"; 3 | export const AUTH_FAILURE="AUTH_FAILUE"; -------------------------------------------------------------------------------- /UI/src/redux/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from "redux"; 2 | 3 | import auth from './auth'; 4 | 5 | export default combineReducers({ 6 | auth 7 | }) -------------------------------------------------------------------------------- /UI/src/redux/store.js: -------------------------------------------------------------------------------- 1 | import { createStore } from "redux"; 2 | import rootReducer from "./reducers"; 3 | 4 | const store =createStore(rootReducer); 5 | 6 | export default store; -------------------------------------------------------------------------------- /backend/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=${PORT:8080} 2 | spring.h2.console.enabled=true 3 | 4 | spring.datasource.url=jdbc:h2:mem:test 5 | 6 | jwt.auth.app=Spring-Security-App 7 | jwt.auth.secret_key=testkey#secret@12334 8 | jwt.auth.expires_in=3600 9 | -------------------------------------------------------------------------------- /UI/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /UI/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/responses/LoginResponse.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.responses; 2 | 3 | public class LoginResponse { 4 | 5 | private String token; 6 | 7 | public String getToken() { 8 | return token; 9 | } 10 | 11 | public void setToken(String token) { 12 | this.token = token; 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/test/java/com/thecodeveal/app/SpringSecurityDemoAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringSecurityDemoAppApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/requests/AuthenticationRequest.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.requests; 2 | 3 | public class AuthenticationRequest { 4 | 5 | private String userName; 6 | private String password; 7 | public String getUserName() { 8 | return userName; 9 | } 10 | 11 | public String getPassword() { 12 | return password; 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /UI/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /UI/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /UI/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/repository/UserDetailsRepository.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.thecodeveal.app.entities.User; 7 | 8 | 9 | @Repository 10 | public interface UserDetailsRepository extends JpaRepository { 11 | 12 | User findByUserName(String userName); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/controllers/AppController.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.controllers; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @RequestMapping("/") 9 | public class AppController { 10 | 11 | 12 | @GetMapping 13 | public String testApp() { 14 | return "Hello Spring Security!"; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /UI/src/redux/authActions.js: -------------------------------------------------------------------------------- 1 | import {AUTH_REQ,AUTH_SUCCESS,AUTH_FAILURE} from './types'; 2 | 3 | 4 | export const authenticate=()=>{ 5 | return { 6 | type:AUTH_REQ 7 | } 8 | } 9 | 10 | 11 | export const authSuccess= (content)=>{ 12 | localStorage.setItem('USER_KEY',content.token); 13 | return { 14 | type:AUTH_SUCCESS, 15 | payload:content 16 | } 17 | } 18 | 19 | export const authFailure=(error)=>{ 20 | return { 21 | type:AUTH_FAILURE, 22 | payload:error 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /UI/src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | import { 4 | BrowserRouter, 5 | Switch, 6 | Route, 7 | Link 8 | } from "react-router-dom"; 9 | import LoginPage from './pages/LoginPage'; 10 | import { Dashboard } from './pages/dashboard/dashboard'; 11 | 12 | 13 | function App() { 14 | return ( 15 | 16 | 17 | 18 | 19 | 20 | 21 | ); 22 | } 23 | 24 | export default App; 25 | -------------------------------------------------------------------------------- /UI/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /UI/src/api/authenticationService.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import axios from 'axios'; 3 | 4 | 5 | const getToken=()=>{ 6 | return localStorage.getItem('USER_KEY'); 7 | } 8 | 9 | export const userLogin=(authRequest)=>{ 10 | return axios({ 11 | 'method':'POST', 12 | 'url':`${process.env.hostUrl||'http://localhost:8080'}/api/v1/auth/login`, 13 | 'data':authRequest 14 | }) 15 | } 16 | 17 | export const fetchUserData=(authRequest)=>{ 18 | return axios({ 19 | method:'GET', 20 | url:`${process.env.hostUrl||'http://localhost:8080'}/api/v1/auth/userinfo`, 21 | headers:{ 22 | 'Authorization':'Bearer '+getToken() 23 | } 24 | }) 25 | } -------------------------------------------------------------------------------- /UI/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /UI/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | import 'bootstrap/dist/css/bootstrap.css'; 7 | import { Provider } from 'react-redux'; 8 | import store from './redux/store'; 9 | 10 | ReactDOM.render( 11 | 12 | 13 | 14 | 15 | , 16 | document.getElementById('root') 17 | ); 18 | 19 | // If you want to start measuring performance in your app, pass a function 20 | // to log results (for example: reportWebVitals(console.log)) 21 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 22 | reportWebVitals(); 23 | -------------------------------------------------------------------------------- /UI/src/redux/reducers/auth.js: -------------------------------------------------------------------------------- 1 | import {AUTH_REQ,AUTH_SUCCESS,AUTH_FAILURE} from '../types'; 2 | 3 | const initialState={ 4 | user:{}, 5 | error:'', 6 | loading:false 7 | }; 8 | 9 | 10 | 11 | const auth=(state=initialState,action)=>{ 12 | console.log("Reducer auth"); 13 | switch(action.type){ 14 | case AUTH_REQ: 15 | return {...state,error:'',loading:true}; 16 | 17 | case AUTH_SUCCESS: 18 | const data=action.payload; 19 | return {...state,error:'',loading:false,user:data}; 20 | 21 | case AUTH_FAILURE: 22 | const error=action.payload; 23 | return {...state,loading:false,error:error}; 24 | 25 | default: 26 | return state; 27 | } 28 | } 29 | 30 | 31 | export default auth; -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/config/RestAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.config; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import org.springframework.security.core.AuthenticationException; 10 | import org.springframework.security.web.AuthenticationEntryPoint; 11 | import org.springframework.stereotype.Component; 12 | 13 | 14 | @Component 15 | public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { 16 | 17 | @Override 18 | public void commence(HttpServletRequest request, HttpServletResponse response, 19 | AuthenticationException authException) throws IOException, ServletException { 20 | 21 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED,authException.getMessage()); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/responses/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.responses; 2 | 3 | public class UserInfo { 4 | 5 | private String firstName; 6 | private String lastName; 7 | private String userName; 8 | 9 | private Object roles; 10 | 11 | public String getFirstName() { 12 | return firstName; 13 | } 14 | 15 | public void setFirstName(String firstName) { 16 | this.firstName = firstName; 17 | } 18 | 19 | public String getLastName() { 20 | return lastName; 21 | } 22 | 23 | public void setLastName(String lastName) { 24 | this.lastName = lastName; 25 | } 26 | 27 | public String getUserName() { 28 | return userName; 29 | } 30 | 31 | public void setUserName(String userName) { 32 | this.userName = userName; 33 | } 34 | 35 | public Object getRoles() { 36 | return roles; 37 | } 38 | 39 | public void setRoles(Object roles) { 40 | this.roles = roles; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/services/CustomUserService.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.services; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.thecodeveal.app.entities.User; 10 | import com.thecodeveal.app.repository.UserDetailsRepository; 11 | 12 | 13 | @Service 14 | public class CustomUserService implements UserDetailsService { 15 | 16 | @Autowired 17 | UserDetailsRepository userDetailsRepository; 18 | 19 | @Override 20 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 21 | // TODO Auto-generated method stub 22 | 23 | User user=userDetailsRepository.findByUserName(username); 24 | 25 | if(null==user) { 26 | throw new UsernameNotFoundException("User Not Found with userName "+username); 27 | } 28 | return user; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /UI/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth-app-demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "axios": "^0.21.1", 10 | "bootstrap": "^4.6.0", 11 | "react": "^17.0.2", 12 | "react-bootstrap": "^1.5.2", 13 | "react-dom": "^17.0.2", 14 | "react-redux": "^7.2.4", 15 | "react-router-dom": "^5.2.0", 16 | "react-scripts": "4.0.3", 17 | "styled-components": "^5.2.3", 18 | "web-vitals": "^1.0.1" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": [ 28 | "react-app", 29 | "react-app/jest" 30 | ] 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /UI/src/pages/loginpage.css: -------------------------------------------------------------------------------- 1 | body.login-page { 2 | background-color: #f7f9fb; 3 | font-size: 14px; 4 | } 5 | 6 | 7 | 8 | .login-page .brand { 9 | width: 90px; 10 | height: 90px; 11 | overflow: hidden; 12 | border-radius: 50%; 13 | margin: 40px auto; 14 | box-shadow: 0 4px 8px rgba(0,0,0,.05); 15 | position: relative; 16 | } 17 | 18 | .login-page .brand img { 19 | width: 100%; 20 | } 21 | 22 | .login-page .card-wrapper { 23 | width: 400px; 24 | } 25 | 26 | .login-page .card { 27 | border-color: transparent; 28 | box-shadow: 0 4px 8px rgba(0,0,0,.05); 29 | } 30 | 31 | .login-page .card.fat { 32 | padding: 10px; 33 | margin-top: 100px; 34 | background-color: #f0f0f0; 35 | } 36 | 37 | .login-page .card .card-title { 38 | margin-bottom: 30px; 39 | } 40 | 41 | .login-page .form-control { 42 | border-width: 2.3px; 43 | } 44 | 45 | .login-page .form-group label { 46 | width: 100%; 47 | } 48 | 49 | .login-page .btn.btn-block { 50 | padding: 12px 10px; 51 | } 52 | 53 | .login-page .footer { 54 | margin: 40px 0; 55 | color: #888; 56 | text-align: center; 57 | } 58 | 59 | @media screen and (max-width: 425px) { 60 | .login-page .card-wrapper { 61 | width: 90%; 62 | margin: 0 auto; 63 | } 64 | } 65 | 66 | @media screen and (max-width: 320px) { 67 | .login-page .card.fat { 68 | padding: 0; 69 | } 70 | 71 | .login-page .card.fat .card-body { 72 | padding: 15px; 73 | } 74 | } -------------------------------------------------------------------------------- /UI/src/pages/dashboard/dashboard.js: -------------------------------------------------------------------------------- 1 | import React,{useState} from 'react'; 2 | import { Button, Container } from 'react-bootstrap'; 3 | import { useDispatch } from 'react-redux'; 4 | import styled from 'styled-components'; 5 | import {fetchUserData} from '../../api/authenticationService'; 6 | 7 | 8 | const MainWrapper=styled.div` 9 | padding-top:40px; 10 | `; 11 | 12 | export const Dashboard=(props)=>{ 13 | 14 | const dispatch=useDispatch(); 15 | const [loading,setLoading]=useState(false); 16 | const [data,setData]=useState({}); 17 | 18 | React.useEffect(()=>{ 19 | fetchUserData().then((response)=>{ 20 | setData(response.data); 21 | }).catch((e)=>{ 22 | localStorage.clear(); 23 | props.history.push('/'); 24 | }) 25 | },[]) 26 | 27 | const logOut=()=>{ 28 | 29 | localStorage.clear(); 30 | props.history.push('/'); 31 | 32 | } 33 | 34 | return ( 35 | 36 | 37 |

Hello {data && `${data.firstName} ${data.lastName}`}

38 |

39 | {data && data.roles && data.roles.filter(value => value.roleCode==='ADMIN').length>0 && } 40 |

41 | 42 | 43 |
44 |
45 | ) 46 | } -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/entities/Authority.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.entities; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | import org.springframework.security.core.GrantedAuthority; 11 | 12 | @Table(name = "AUTH_AUTHORITY") 13 | @Entity 14 | public class Authority implements GrantedAuthority { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | 20 | @Column(name = "ROLE_CODE") 21 | private String roleCode; 22 | 23 | @Column(name = "ROLE_DESCRIPTION") 24 | private String roleDescription; 25 | 26 | 27 | 28 | @Override 29 | public String getAuthority() { 30 | // TODO Auto-generated method stub 31 | return roleCode; 32 | } 33 | 34 | 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | 41 | 42 | public void setId(Long id) { 43 | this.id = id; 44 | } 45 | 46 | 47 | 48 | public String getRoleCode() { 49 | return roleCode; 50 | } 51 | 52 | 53 | 54 | public void setRoleCode(String roleCode) { 55 | this.roleCode = roleCode; 56 | } 57 | 58 | 59 | 60 | public String getRoleDescription() { 61 | return roleDescription; 62 | } 63 | 64 | 65 | 66 | public void setRoleDescription(String roleDescription) { 67 | this.roleDescription = roleDescription; 68 | } 69 | 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /UI/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/SpringSecurityDemoAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | 13 | import com.thecodeveal.app.entities.Authority; 14 | import com.thecodeveal.app.entities.User; 15 | import com.thecodeveal.app.repository.UserDetailsRepository; 16 | 17 | @SpringBootApplication 18 | public class SpringSecurityDemoAppApplication { 19 | 20 | @Autowired 21 | private PasswordEncoder passwordEncoder; 22 | 23 | @Autowired 24 | private UserDetailsRepository userDetailsRepository; 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(SpringSecurityDemoAppApplication.class, args); 28 | } 29 | 30 | @PostConstruct 31 | protected void init() { 32 | 33 | List authorityList=new ArrayList<>(); 34 | 35 | authorityList.add(createAuthority("USER","User role")); 36 | //authorityList.add(createAuthority("ADMIN","Admin role")); 37 | 38 | User user=new User(); 39 | 40 | user.setUserName("pardeep161"); 41 | user.setFirstName("Pardeep"); 42 | user.setLastName("K"); 43 | 44 | user.setPassword(passwordEncoder.encode("pardeep@123")); 45 | user.setEnabled(true); 46 | user.setAuthorities(authorityList); 47 | 48 | userDetailsRepository.save(user); 49 | 50 | 51 | 52 | } 53 | 54 | 55 | private Authority createAuthority(String roleCode,String roleDescription) { 56 | Authority authority=new Authority(); 57 | authority.setRoleCode(roleCode); 58 | authority.setRoleDescription(roleDescription); 59 | return authority; 60 | } 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: Deploy Service 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | # push: 9 | # branches: [ main ] 10 | # pull_request: 11 | # branches: [ main ] 12 | workflow_dispatch: 13 | inputs: 14 | job_name: 15 | description: 'Deploy Application' 16 | required: true 17 | default: 'build_deploy' 18 | 19 | defaults: 20 | run: 21 | working-directory: backend 22 | 23 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 24 | jobs: 25 | # This workflow contains a single job called "build" 26 | build_deploy: 27 | # The type of runner that the job will run on 28 | runs-on: ubuntu-latest 29 | defaults: 30 | run: 31 | working-directory: backend 32 | 33 | # Steps represent a sequence of tasks that will be executed as part of the job 34 | steps: 35 | - uses: actions/checkout@v2 36 | - name: Set up JDK 1.8 37 | uses: actions/setup-java@v1 38 | with: 39 | java-version: 1.8 40 | - name: Install and Build 🔧 41 | run: 42 | mvn clean install 43 | # - name: Install Heroku 44 | # run: sudo snap install --classic heroku 45 | # - name: Herku Login 46 | # run: | 47 | # cat > ~/.netrc < 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.4.5 10 | 11 | 12 | com.thecodeveal 13 | spring-security-demo-app 14 | 0.0.1-SNAPSHOT 15 | spring-security-demo-app 16 | Demo project for Spring Boot 17 | 18 | 1.8 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-jpa 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-security 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | com.h2database 36 | h2 37 | runtime 38 | 39 | 40 | 41 | io.jsonwebtoken 42 | jjwt 43 | 0.9.1 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | org.springframework.security 52 | spring-security-test 53 | test 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/config/JWTAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.config; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 11 | import org.springframework.security.core.context.SecurityContextHolder; 12 | import org.springframework.security.core.userdetails.UserDetails; 13 | import org.springframework.security.core.userdetails.UserDetailsService; 14 | import org.springframework.security.web.authentication.WebAuthenticationDetails; 15 | import org.springframework.web.filter.OncePerRequestFilter; 16 | 17 | public class JWTAuthenticationFilter extends OncePerRequestFilter { 18 | 19 | private UserDetailsService userDetailsService; 20 | private JWTTokenHelper jwtTokenHelper; 21 | 22 | public JWTAuthenticationFilter(UserDetailsService userDetailsService,JWTTokenHelper jwtTokenHelper) { 23 | this.userDetailsService=userDetailsService; 24 | this.jwtTokenHelper=jwtTokenHelper; 25 | 26 | } 27 | 28 | @Override 29 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 30 | throws ServletException, IOException { 31 | 32 | 33 | String authToken=jwtTokenHelper.getToken(request); 34 | 35 | if(null!=authToken) { 36 | 37 | String userName=jwtTokenHelper.getUsernameFromToken(authToken); 38 | 39 | if(null!=userName) { 40 | 41 | UserDetails userDetails=userDetailsService.loadUserByUsername(userName); 42 | 43 | if(jwtTokenHelper.validateToken(authToken, userDetails)) { 44 | 45 | UsernamePasswordAuthenticationToken authentication=new UsernamePasswordAuthenticationToken(userDetails, null,userDetails.getAuthorities()); 46 | authentication.setDetails(new WebAuthenticationDetails(request)); 47 | 48 | SecurityContextHolder.getContext().setAuthentication(authentication); 49 | 50 | 51 | 52 | } 53 | 54 | } 55 | 56 | } 57 | 58 | filterChain.doFilter(request, response); 59 | 60 | 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /UI/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/config/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.HttpMethod; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.security.config.http.SessionCreationPolicy; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | import org.springframework.security.web.AuthenticationEntryPoint; 16 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 17 | 18 | import com.thecodeveal.app.services.CustomUserService; 19 | 20 | @Configuration 21 | @EnableWebSecurity 22 | public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 23 | 24 | @Autowired 25 | private CustomUserService userService; 26 | 27 | @Autowired 28 | private JWTTokenHelper jWTTokenHelper; 29 | 30 | @Autowired 31 | private AuthenticationEntryPoint authenticationEntryPoint; 32 | 33 | @Override 34 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 35 | 36 | auth.inMemoryAuthentication().withUser("Pardeep").password(passwordEncoder().encode("test@123")) 37 | .authorities("USER", "ADMIN"); 38 | 39 | auth.userDetailsService(userService).passwordEncoder(passwordEncoder()); 40 | 41 | } 42 | 43 | @Bean 44 | public PasswordEncoder passwordEncoder() { 45 | return new BCryptPasswordEncoder(); 46 | } 47 | 48 | @Bean 49 | @Override 50 | public AuthenticationManager authenticationManagerBean() throws Exception { 51 | return super.authenticationManagerBean(); 52 | } 53 | 54 | @Override 55 | protected void configure(HttpSecurity http) throws Exception { 56 | 57 | http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling() 58 | .authenticationEntryPoint(authenticationEntryPoint).and() 59 | .authorizeRequests((request) -> request.antMatchers("/h2-console/**", "/api/v1/auth/login").permitAll() 60 | .antMatchers(HttpMethod.OPTIONS, "/**").permitAll().anyRequest().authenticated()) 61 | .addFilterBefore(new JWTAuthenticationFilter(userService, jWTTokenHelper), 62 | UsernamePasswordAuthenticationFilter.class); 63 | 64 | http.csrf().disable().cors().and().headers().frameOptions().disable(); 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/controllers/AuthenticationController.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.controllers; 2 | 3 | import java.security.NoSuchAlgorithmException; 4 | import java.security.Principal; 5 | import java.security.spec.InvalidKeySpecException; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.security.authentication.AuthenticationManager; 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 11 | import org.springframework.security.core.Authentication; 12 | import org.springframework.security.core.context.SecurityContextHolder; 13 | import org.springframework.security.core.userdetails.UserDetailsService; 14 | import org.springframework.web.bind.annotation.CrossOrigin; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import com.thecodeveal.app.config.JWTTokenHelper; 22 | import com.thecodeveal.app.entities.User; 23 | import com.thecodeveal.app.requests.AuthenticationRequest; 24 | import com.thecodeveal.app.responses.LoginResponse; 25 | import com.thecodeveal.app.responses.UserInfo; 26 | 27 | @RestController 28 | @RequestMapping("/api/v1") 29 | @CrossOrigin 30 | public class AuthenticationController { 31 | 32 | @Autowired 33 | private AuthenticationManager authenticationManager; 34 | 35 | @Autowired 36 | JWTTokenHelper jWTTokenHelper; 37 | 38 | @Autowired 39 | private UserDetailsService userDetailsService; 40 | 41 | @PostMapping("/auth/login") 42 | public ResponseEntity login(@RequestBody AuthenticationRequest authenticationRequest) throws InvalidKeySpecException, NoSuchAlgorithmException { 43 | 44 | final Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken( 45 | authenticationRequest.getUserName(), authenticationRequest.getPassword())); 46 | 47 | SecurityContextHolder.getContext().setAuthentication(authentication); 48 | 49 | User user=(User)authentication.getPrincipal(); 50 | String jwtToken=jWTTokenHelper.generateToken(user.getUsername()); 51 | 52 | LoginResponse response=new LoginResponse(); 53 | response.setToken(jwtToken); 54 | 55 | 56 | return ResponseEntity.ok(response); 57 | } 58 | 59 | @GetMapping("/auth/userinfo") 60 | public ResponseEntity getUserInfo(Principal user){ 61 | User userObj=(User) userDetailsService.loadUserByUsername(user.getName()); 62 | 63 | UserInfo userInfo=new UserInfo(); 64 | userInfo.setFirstName(userObj.getFirstName()); 65 | userInfo.setLastName(userObj.getLastName()); 66 | userInfo.setRoles(userObj.getAuthorities().toArray()); 67 | 68 | 69 | return ResponseEntity.ok(userInfo); 70 | 71 | 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /UI/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/config/JWTTokenHelper.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.config; 2 | 3 | 4 | import java.security.NoSuchAlgorithmException; 5 | import java.security.spec.InvalidKeySpecException; 6 | import java.util.Date; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | import org.springframework.beans.factory.annotation.Value; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.stereotype.Component; 13 | 14 | import io.jsonwebtoken.Claims; 15 | import io.jsonwebtoken.Jwts; 16 | import io.jsonwebtoken.SignatureAlgorithm; 17 | 18 | @Component 19 | public class JWTTokenHelper { 20 | 21 | 22 | @Value("${jwt.auth.app}") 23 | private String appName; 24 | 25 | @Value("${jwt.auth.secret_key}") 26 | private String secretKey; 27 | 28 | @Value("${jwt.auth.expires_in}") 29 | private int expiresIn; 30 | 31 | private SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.HS256; 32 | 33 | 34 | 35 | private Claims getAllClaimsFromToken(String token) { 36 | Claims claims; 37 | try { 38 | claims = Jwts.parser() 39 | .setSigningKey(secretKey) 40 | .parseClaimsJws(token) 41 | .getBody(); 42 | } catch (Exception e) { 43 | claims = null; 44 | } 45 | return claims; 46 | } 47 | 48 | 49 | public String getUsernameFromToken(String token) { 50 | String username; 51 | try { 52 | final Claims claims = this.getAllClaimsFromToken(token); 53 | username = claims.getSubject(); 54 | } catch (Exception e) { 55 | username = null; 56 | } 57 | return username; 58 | } 59 | 60 | public String generateToken(String username) throws InvalidKeySpecException, NoSuchAlgorithmException { 61 | 62 | return Jwts.builder() 63 | .setIssuer( appName ) 64 | .setSubject(username) 65 | .setIssuedAt(new Date()) 66 | .setExpiration(generateExpirationDate()) 67 | .signWith( SIGNATURE_ALGORITHM, secretKey ) 68 | .compact(); 69 | } 70 | 71 | private Date generateExpirationDate() { 72 | return new Date(new Date().getTime() + expiresIn * 1000); 73 | } 74 | 75 | public Boolean validateToken(String token, UserDetails userDetails) { 76 | final String username = getUsernameFromToken(token); 77 | return ( 78 | username != null && 79 | username.equals(userDetails.getUsername()) && 80 | !isTokenExpired(token) 81 | ); 82 | } 83 | 84 | public boolean isTokenExpired(String token) { 85 | Date expireDate=getExpirationDate(token); 86 | return expireDate.before(new Date()); 87 | } 88 | 89 | 90 | private Date getExpirationDate(String token) { 91 | Date expireDate; 92 | try { 93 | final Claims claims = this.getAllClaimsFromToken(token); 94 | expireDate = claims.getExpiration(); 95 | } catch (Exception e) { 96 | expireDate = null; 97 | } 98 | return expireDate; 99 | } 100 | 101 | 102 | public Date getIssuedAtDateFromToken(String token) { 103 | Date issueAt; 104 | try { 105 | final Claims claims = this.getAllClaimsFromToken(token); 106 | issueAt = claims.getIssuedAt(); 107 | } catch (Exception e) { 108 | issueAt = null; 109 | } 110 | return issueAt; 111 | } 112 | 113 | public String getToken( HttpServletRequest request ) { 114 | 115 | String authHeader = getAuthHeaderFromHeader( request ); 116 | if ( authHeader != null && authHeader.startsWith("Bearer ")) { 117 | return authHeader.substring(7); 118 | } 119 | 120 | return null; 121 | } 122 | 123 | public String getAuthHeaderFromHeader( HttpServletRequest request ) { 124 | return request.getHeader("Authorization"); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /backend/src/main/java/com/thecodeveal/app/entities/User.java: -------------------------------------------------------------------------------- 1 | package com.thecodeveal.app.entities; 2 | 3 | import java.util.Collection; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import javax.persistence.CascadeType; 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.FetchType; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.GenerationType; 13 | import javax.persistence.Id; 14 | import javax.persistence.JoinColumn; 15 | import javax.persistence.JoinTable; 16 | import javax.persistence.ManyToMany; 17 | import javax.persistence.Table; 18 | 19 | import org.springframework.security.core.GrantedAuthority; 20 | import org.springframework.security.core.userdetails.UserDetails; 21 | 22 | @Table(name = "AUTH_USER_DETAILS") 23 | @Entity 24 | public class User implements UserDetails { 25 | 26 | @Id 27 | @GeneratedValue(strategy = GenerationType.IDENTITY) 28 | private long id; 29 | 30 | @Column(name = "USER_NAME", unique = true) 31 | private String userName; 32 | 33 | @Column(name = "USER_KEY") 34 | private String password; 35 | 36 | 37 | @Column(name = "CREATED_ON") 38 | private Date createdAt; 39 | 40 | @Column(name = "UPDATED_ON") 41 | private Date updatedAt; 42 | 43 | @Column(name = "first_name") 44 | private String firstName; 45 | 46 | @Column(name = "last_name") 47 | private String lastName; 48 | 49 | @Column(name = "email") 50 | private String email; 51 | 52 | @Column(name = "phone_number") 53 | private String phoneNumber; 54 | 55 | @Column(name = "enabled") 56 | private boolean enabled=true; 57 | 58 | 59 | @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER) 60 | @JoinTable(name = "AUTH_USER_AUTHORITY", joinColumns = @JoinColumn(referencedColumnName = "id"),inverseJoinColumns = @JoinColumn(referencedColumnName ="id")) 61 | private List authorities; 62 | 63 | @Override 64 | public Collection getAuthorities() { 65 | // TODO Auto-generated method stub 66 | return authorities; 67 | } 68 | 69 | @Override 70 | public String getPassword() { 71 | // TODO Auto-generated method stub 72 | return this.password; 73 | } 74 | 75 | @Override 76 | public String getUsername() { 77 | // TODO Auto-generated method stub 78 | return this.userName; 79 | } 80 | 81 | @Override 82 | public boolean isAccountNonExpired() { 83 | // TODO Auto-generated method stub 84 | return this.enabled; 85 | } 86 | 87 | @Override 88 | public boolean isAccountNonLocked() { 89 | // TODO Auto-generated method stub 90 | return this.enabled; 91 | } 92 | 93 | @Override 94 | public boolean isCredentialsNonExpired() { 95 | // TODO Auto-generated method stub 96 | return this.enabled; 97 | } 98 | 99 | @Override 100 | public boolean isEnabled() { 101 | // TODO Auto-generated method stub 102 | return this.enabled; 103 | } 104 | 105 | public long getId() { 106 | return id; 107 | } 108 | 109 | public void setId(long id) { 110 | this.id = id; 111 | } 112 | 113 | public String getUserName() { 114 | return userName; 115 | } 116 | 117 | public void setUserName(String userName) { 118 | this.userName = userName; 119 | } 120 | 121 | public Date getCreatedAt() { 122 | return createdAt; 123 | } 124 | 125 | public void setCreatedAt(Date createdAt) { 126 | this.createdAt = createdAt; 127 | } 128 | 129 | public Date getUpdatedAt() { 130 | return updatedAt; 131 | } 132 | 133 | public void setUpdatedAt(Date updatedAt) { 134 | this.updatedAt = updatedAt; 135 | } 136 | 137 | public String getFirstName() { 138 | return firstName; 139 | } 140 | 141 | public void setFirstName(String firstName) { 142 | this.firstName = firstName; 143 | } 144 | 145 | public String getLastName() { 146 | return lastName; 147 | } 148 | 149 | public void setLastName(String lastName) { 150 | this.lastName = lastName; 151 | } 152 | 153 | public String getEmail() { 154 | return email; 155 | } 156 | 157 | public void setEmail(String email) { 158 | this.email = email; 159 | } 160 | 161 | public String getPhoneNumber() { 162 | return phoneNumber; 163 | } 164 | 165 | public void setPhoneNumber(String phoneNumber) { 166 | this.phoneNumber = phoneNumber; 167 | } 168 | 169 | public void setPassword(String password) { 170 | this.password = password; 171 | } 172 | 173 | public void setAuthorities(List authorities) { 174 | this.authorities = authorities; 175 | } 176 | 177 | public void setEnabled(boolean enabled) { 178 | this.enabled = enabled; 179 | } 180 | 181 | 182 | 183 | } 184 | -------------------------------------------------------------------------------- /UI/src/pages/LoginPage.js: -------------------------------------------------------------------------------- 1 | import react,{useState} from 'react'; 2 | import { connect } from 'react-redux'; 3 | import { authenticate, authFailure, authSuccess } from '../redux/authActions'; 4 | import './loginpage.css'; 5 | import {userLogin} from '../api/authenticationService'; 6 | import {Alert,Spinner} from 'react-bootstrap'; 7 | 8 | const LoginPage=({loading,error,...props})=>{ 9 | 10 | 11 | const [values, setValues] = useState({ 12 | userName: '', 13 | password: '' 14 | }); 15 | 16 | const handleSubmit=(evt)=>{ 17 | evt.preventDefault(); 18 | props.authenticate(); 19 | 20 | userLogin(values).then((response)=>{ 21 | 22 | console.log("response",response); 23 | if(response.status===200){ 24 | props.setUser(response.data); 25 | props.history.push('/dashboard'); 26 | } 27 | else{ 28 | props.loginFailure('Something Wrong!Please Try Again'); 29 | } 30 | 31 | 32 | }).catch((err)=>{ 33 | 34 | if(err && err.response){ 35 | 36 | switch(err.response.status){ 37 | case 401: 38 | console.log("401 status"); 39 | props.loginFailure("Authentication Failed.Bad Credentials"); 40 | break; 41 | default: 42 | props.loginFailure('Something Wrong!Please Try Again'); 43 | 44 | } 45 | 46 | } 47 | else{ 48 | props.loginFailure('Something Wrong!Please Try Again'); 49 | } 50 | 51 | 52 | 53 | 54 | }); 55 | //console.log("Loading again",loading); 56 | 57 | 58 | } 59 | 60 | const handleChange = (e) => { 61 | e.persist(); 62 | setValues(values => ({ 63 | ...values, 64 | [e.target.name]: e.target.value 65 | })); 66 | }; 67 | 68 | console.log("Loading ",loading); 69 | 70 | return ( 71 |
72 | 73 | 74 | 75 |
76 |
77 | 78 |
79 |
80 | 81 |
82 |
83 |

Login

84 | 85 |
86 |
87 | 88 | 89 | 90 |
91 | UserId is invalid 92 |
93 | 94 | 95 | 96 |
97 | 98 |
99 | 104 | 105 |
106 | Password is required 107 |
108 |
109 | 110 |
111 |
112 | 113 | 114 |
115 |
116 | 117 | 118 |
119 | 137 |
138 |
139 | { error && 140 | 141 | {error} 142 | 143 | 144 | } 145 | 146 | 147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 | ) 155 | 156 | 157 | 158 | } 159 | 160 | const mapStateToProps=({auth})=>{ 161 | console.log("state ",auth) 162 | return { 163 | loading:auth.loading, 164 | error:auth.error 165 | }} 166 | 167 | 168 | const mapDispatchToProps=(dispatch)=>{ 169 | 170 | return { 171 | authenticate :()=> dispatch(authenticate()), 172 | setUser:(data)=> dispatch(authSuccess(data)), 173 | loginFailure:(message)=>dispatch(authFailure(message)) 174 | } 175 | } 176 | 177 | 178 | export default connect(mapStateToProps,mapDispatchToProps)(LoginPage); -------------------------------------------------------------------------------- /backend/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /backend/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | --------------------------------------------------------------------------------