redfroggy / angular-spring-hmac Goto Github PK
View Code? Open in Web Editor NEWSpring and Angular security with HMAC and Cookie based JWT
Spring and Angular security with HMAC and Cookie based JWT
JWT expiration date is not verified
Use angular2-jwt library or handling JWT
https://www.npmjs.com/package/angular2-jwt
Add csrf token protection with jwt
While trying to run the application using "mvn spring-boot:run" I`m getting an issue. Below please find part of the exception message
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [fr/redfroggy/hmac/configuration/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error Reading Migration File: class path resource [liquibase/master.xml] cannot be resolved to URL because it does not exist
Any help will be appreciated. Thanks in advance.
Hello, I've tried to run your application via spring-boot:run and got following:
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-hmac 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.3.2.RELEASE:run (default-cli) @ spring-hmac >>>
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:exec (exec-npm-install) @ spring-hmac ---
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
npm WARN package.json springHmac@ No description
npm WARN package.json springHmac@ No repository field.
npm WARN package.json springHmac@ No README data
npm WARN package.json springHmac@ No license field.
(node:7784) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\dev\\soft\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.6.0
npm ERR! npm v2.13.3
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer @angular/[email protected] wants [email protected]
npm ERR! peerinvalid Peer @angular/[email protected] wants [email protected]
npm ERR! peerinvalid Peer @angular/[email protected] wants [email protected]
npm ERR! Please include the following file with any support request:
npm ERR! C:\dev\webapps\angular2\angular-spring-hmac-angular2\angular-spring-hmac-angular2\src\main\webapp\npm-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.779s
[INFO] Finished at: Tue Nov 22 01:06:42 CET 2016
[INFO] Final Memory: 11M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (exec-npm-install) on project spring-hmac: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Use angular-jwt library for handling JWT
https://github.com/auth0/angular-jwt
First of all i want to thank you for this great tuto.
However when i started including this code into my project (front end: angular2, back-end: spring-boot, spring-mvc, spring-data, hibernate) i've recieved some issues like:
Also i want to know how to redirect each user to the specified layout using this code
This is such a great tutorial and an incredibly good place to start. When i was implementing this code on my project, i realized the the Digest Auth will always fail for file uploads. This is basically because of the method for calculating the server digest does not take into account files(wrappedRequest.getBody).
I would appreciate your contribution on this.
Hello Michael. Thanks for sharing, this project helped me a lot.
I'm studying Spring Security with your project. I tried to change the username, then log in with that changed name. The application returns Access Denied.
As a self challenge, I tried to fix it. I do not know if it is the right solution. Please, see below.
In the authenticate method of the AuthenticationService class I override the lines 55 through 57 by tokenAuthentication(loginDTO.getLogin(), loginDTO.getPassword());
The called method is
public void tokenAuthentication(String username, String password){
UserDetails details = userDetailsService.loadUserByUsername(username);
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(details, password, details.getAuthorities());
if(password.equals(details.getPassword())) {
SecurityContextHolder.getContext().setAuthentication(authToken);
} else {
authenticationManager.authenticate(authToken);
}
}
I would like your opinion if this is an appropriate solution. Thanks in advance.
I used the angular2 branch from this project and splitted it into angular project and spring boot project. Same code which works with in repo doesn't work after splitting the project. Angular code is not able to read any tokens.
I am using angular 4.0.2
```
"@angular/animations": "^4.0.2",
"@angular/common": "^4.0.2",
"@angular/compiler": "^4.0.2",
"@angular/core": "^4.0.2",
"@angular/forms": "^4.0.2",
"@angular/http": "^4.0.2",
"@angular/platform-browser": "^4.0.2",
"@angular/platform-browser-dynamic": "^4.0.2",
"@angular/platform-server": "^4.0.2",
"@angular/router": "^4.0.2",
"@angular/upgrade": "^4.0.2",
"angular-utf8-base64": "0.0.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"crypto-js": "^3.1.9-1",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"ntypescript": "^1.201609302242.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.1.0",
"systemjs": "^0.20.12",
"underscore": "^1.8.3",
"zone.js": "^0.8.4"
first of all thank you for your work !.
I have a concern in the client code, why is not validating the server response jwt in the mapResponse function ... is there any limitation in jwt ?.
regards
Hi Michael
Please help
What I did?
git clone https://github.com/RedFroggy/angular-spring-hmac.git
cd angular-spring-hmac
mvn spring-boot:run
and the following error showed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [fr/redfroggy/hmac/configuration/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error Reading Migration File: class path resource [liquibase/master.xml] cannot be resolved to URL because it does not exist
Hi, how to fix below error to run up this great demo?
`
➜ angular-spring-hmac git:(master) cd src/main/webapp
➜ webapp git:(master) npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
added 29 packages in 5.751s
➜ webapp git:(master) ✗ cd -
~/angular-spring-hmac
➜ angular-spring-hmac git:(master) ✗ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-hmac 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:exec (exec-npm-install) @ spring-hmac ---
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
up to date in 0.33s
[INFO]
[INFO] --- exec-maven-plugin:1.5.0:exec (exec-npm-run-tsc) @ spring-hmac ---
[email protected] build /Users/yin/angular-spring-hmac/src/main/webapp
ntsc -p ../../../
app/account/account.ts(1,1): error TS6053: File '/Users/yin/angular-spring-hmac/typings/lodash/lodash.d.ts' not found.
app/account/account.ts(10,13): error TS2304: Cannot find name ''.
app/security/securityToken.ts(5,9): error TS2304: Cannot find name ''.
app/utils/hmac-http-client.ts(40,63): error TS2304: Cannot find name 'CryptoJS'.
app/utils/hmac-http-client.ts(42,63): error TS2304: Cannot find name 'CryptoJS'.
app/utils/hmac-http-client.ts(44,63): error TS2304: Cannot find name 'CryptoJS'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: ntsc -p ../../../
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/yin/.npm/_logs/2017-09-27T23_45_42_478Z-debug.log
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.594 s
[INFO] Finished at: 2017-09-28T07:45:42+08:00
[INFO] Final Memory: 18M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (exec-npm-run-tsc) on project spring-hmac: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
`
I am using the same repo code with angular 4.0.0 .
I am facing problem in app.module.ts.
Getting this error:
vendor.bundle.js:57784 Uncaught Error: Can't resolve all parameters for useFactory: (?, ?, ?). at syntaxError (http://localhost:4200/vendor.bundle.js:44710:34) [<root>] at CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:57558:35) [<root>] at CompileMetadataResolver._getFactoryMetadata (http://localhost:4200/vendor.bundle.js:57438:51) [<root>] at CompileMetadataResolver.getProviderMetadata (http://localhost:4200/vendor.bundle.js:57709:43) [<root>] at http://localhost:4200/vendor.bundle.js:57629:49 [<root>] at Array.forEach (native) [<root>] at CompileMetadataResolver._getProvidersMetadata (http://localhost:4200/vendor.bundle.js:57592:19) [<root>] at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:57248:50) [<root>] at JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:68285:64) [<root>] at JitCompiler._compileModuleAndComponents (http://localhost:4200/vendor.bundle.js:68244:52) [<root>] at JitCompiler.compileModuleAsync (http://localhost:4200/vendor.bundle.js:68206:21) [<root>] at PlatformRef_._bootstrapModuleWithZone (http://localhost:4200/vendor.bundle.js:5239:25) [<root>] at PlatformRef_.bootstrapModule (http://localhost:4200/vendor.bundle.js:5225:21) [<root>] at Object.128 (http://localhost:4200/main.bundle.js:33:124) [<root>]
When i remove providers content it is working fine. How?
@NgModule({
imports: [ HttpModule, RouterModule, BrowserModule, AccountModule, LoginModule, UserModule, UtilsModule, RoutesModule ],
declarations: [ AppComponent, Header ],
bootstrap: [ AppComponent, Header ],
providers: [
{provide: LocationStrategy, useClass: HashLocationStrategy},
{
provide: Http,
useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions, accountEventService: AccountEventsService) => {
return new HmacHttpClient(xhrBackend, requestOptions, accountEventService);
},
deps: [XHRBackend, RequestOptions, AccountEventsService],
multi: false
}]
})'
After removing the providers i got this error:
ERROR ReferenceError: _ is not defined at new SecurityToken (securityToken.ts:5) at HmacHttpClient.webpackJsonp.285.HmacHttpClient.mapResponse (hmac-http-client.ts:65) at SafeSubscriber._next (hmac-http-client.ts:100) at SafeSubscriber.__tryOrUnsub (Subscriber.js:236) at SafeSubscriber.next (Subscriber.js:185) at Subscriber._next (Subscriber.js:125) at Subscriber.next (Subscriber.js:89) at XMLHttpRequest.onLoad (http.es5.js:1205) at ZoneDelegate.invokeTask (zone.js:398) at Object.onInvokeTask (core.es5.js:4116) at ZoneDelegate.invokeTask (zone.js:397) at Zone.runTask (zone.js:165) at XMLHttpRequest.ZoneTask.invoke (zone.js:460) defaultErrorLogger @ core.es5.js:1084 ErrorHandler.handleError @ core.es5.js:1144 next @ core.es5.js:4754 schedulerFn @ core.es5.js:3828 SafeSubscriber.__tryOrUnsub @ Subscriber.js:236 SafeSubscriber.next @ Subscriber.js:185 Subscriber._next @ Subscriber.js:125 Subscriber.next @ Subscriber.js:89 Subject.next @ Subject.js:55 EventEmitter.emit @ core.es5.js:3814 NgZone.triggerError @ core.es5.js:4185 onHandleError @ core.es5.js:4146 ZoneDelegate.handleError @ zone.js:369 Zone.runTask @ zone.js:168 ZoneTask.invoke @ zone.js:460
Bonjour ,
en essayant d’intégrer le projet dans un Spring MVC j'ai ça cote client :
secret null hmac-http-client.ts:45
hmac message null
et j'ai pas de sysout cote serveur sur la classe HmacSecurityFilter .
Merci d'avance .
Store JWT as a cookie with options secure and httpOnly
Hi
Could you please help migrating your project to angular 2 rc.1 ?
I must to say that I loved your security angular2 and springboot aproach and I am going to use it.
At the moment I am testing your another project called "angular 2 dynamic form"
Congratulations,
Hi, This is a great project. I have learn a lot from this project. but i am new to angular. So,
Please remove all deprecated API for angular 5.
I am new that's why requested the update.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.