Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate jwt with mtsj #334

Closed
wants to merge 830 commits into from
Closed

Integrate jwt with mtsj #334

wants to merge 830 commits into from

Conversation

vapadwal
Copy link
Member

@vapadwal vapadwal commented Apr 23, 2020

Few issues still in this PR

  1. currently storing the pkcs file in resources/config is not working security.keystore.location=classpath:config/keystore.pkcs

It works only if we store it to some file location in below format. Here we need to identify some path in mtsj server to store the file.(file:/pathtofile/file.pkcs)

throwing some weird exception

Caused by: java.io.IOException: insufficient data
at java.base/sun.security.util.DerInputBuffer.truncate(DerInputBuffer.java:134) ~[na:na]
at java.base/sun.security.util.DerInputStream.subStream(DerInputStream.java:160) ~[na:na]
at java.base/sun.security.util.DerInputStream.readVector(DerInputStream.java:421) ~[na:na]
at java.base/sun.security.util.DerInputStream.getSequence(DerInputStream.java:337) ~[na:na]
at java.base/sun.security.pkcs.ContentInfo.(ContentInfo.java:132) ~[na:na]
at java.base/sun.security.pkcs.ContentInfo.(ContentInfo.java:109) ~[na:na]
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2007) ~[na:na]
at java.base/sun.security.util.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:222) ~[na:na]
at java.base/java.security.KeyStore.load(KeyStore.java:1479) ~[na:na]
at com.devonfw.module.security.keystore.common.impl.KeyStoreAccessImpl.getKeyStore(KeyStoreAccessImpl.java:50)

@vapadwal
Copy link
Member Author

Sure but then the stuff does not go to the module but needs to be part of the docker build that combines the WAR with config+keystore.

yes then need to figure out the where to store this file with @dario-rodriguez

@hohwille
Copy link
Member

Did you put the keystore in core/src/main/resources/config/keystore.pkcs ?
If so the location is wrong:

security.keystore.location=classpath:config/keystore.pkcs

This works for tests inside the core module but in the end the core is bundled to a JAR file that then gets included inside the bootified JAR/WAR of the server module.
Maybe it can work if the keystore is put inside the server module.

@vapadwal
Copy link
Member Author

Did you put the keystore in core/src/main/resources/config/keystore.pkcs ?
If so the location is wrong:

security.keystore.location=classpath:config/keystore.pkcs

This works for tests inside the core module but in the end the core is bundled to a JAR file that then gets included inside the bootified JAR/WAR of the server module.
Maybe it can work if the keystore is put inside the server module.

opps this is new to me need to check

@vapadwal
Copy link
Member Author

Did you put the keystore in core/src/main/resources/config/keystore.pkcs ?
If so the location is wrong:

security.keystore.location=classpath:config/keystore.pkcs

This works for tests inside the core module but in the end the core is bundled to a JAR file that then gets included inside the bootified JAR/WAR of the server module.
Maybe it can work if the keystore is put inside the server module.

opps this is new to me need to check

Yes now it working when we put the keystore file inside mtsj\server\src\main\resources\keystore.pkcs

Now in local to work we need to run using java -jar mythaistar-bootified.war.

@vapadwal
Copy link
Member Author

This PR is for reference only should not be merger now. It still has issue with twofactorAuthentication.
Here now JwtAuthentication works. As it is tightly coupled with twofactorauthentication . twofactorauthentication is ignored

maihacke and others added 4 commits April 27, 2020 16:46
…in devo… (devonfw#321)

* Implement example batches with modified devon-batch (see devonfw#190 in devon4j)

* Cleanup and documentation. Introduce job parameter for input/output file.

* Implemented batch start/stop scheme which works with spring batch alone.
No own implementation for launchers are required.

* Remove batch disabling in core project

* Remove unused super class for tests

* Include example batch for restarts

* Document start of this batch with H2 auto-server-mode

* Fix exit code handling & exiting for web and batch

* Implement example for authentication

see devonfw/devon4j#90

* just start travis built, no code changes

* Provide Javadoc

* Upgrade to devon4j 2020.04.001
Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great update of MTSJ, looks very good in general.
I left some feedback for improvement. Could you check if you can quickly address the suggested improvements and then we can merge this.

@@ -17,6 +17,7 @@ export class HttpRequestInterceptorService implements HttpInterceptor {
return this.store.select(fromAuth.getToken).pipe(
first(),
flatMap((token) => {
token = token.replace('Bearer', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indendation ;)

@@ -63,6 +63,10 @@
<artifactId>devon4j-jpa</artifactId>
</dependency> -->

<dependency>
<groupId>com.devonfw.java.starters</groupId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indendation

Comment on lines 133 to 136
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoundn't jjwt now come via devon4j jwt module and MTSJ only use this indirectly so this dependency is not needed anymore?


UserDetailsClientTo userDetails = new UserDetailsClientTo();

Authentication auth = this.jwtAuthenticator.authenticate(jwt.replace(JwtConstants.TOKEN_PREFIX, ""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aint this a duplicated authentication? what is the purpose of this service in MTSJ?
IMHO this is to retrieve UserDetailsClientTo via REST service on the client. If so the existing authentication filter should be used and the UserDetailsClientTo should be created from the spring-security Authentication rather than again authenticating.

@@ -39,7 +43,7 @@
@Path("/currentuser/")
public UserDetailsClientTo getCurrentUserDetails(@Context HttpServletRequest request) {

return TokenAuthenticationService.getUserdetailsFromToken(request.getHeader("Authorization"));
return this.tokenManagementService.getUserdetailsFromTokenJwt(request.getHeader("Authorization"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly what I guesses. IMHO does not make so much sense...
Compare this to the original implementation of this service that should still work even it never knew about JWT.

@vapadwal
Copy link
Member Author

I have fix the review comments , but still there is problem with twofactorauthentication and this need some more time to fix

@vapadwal vapadwal changed the title WIP:integrate jwt with mtsj Integrate jwt with mtsj May 10, 2020
@vapadwal
Copy link
Member Author

Fixed 2Fa related error

Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good progress on JWT support but IMHO still needs some rework.
@suprishi may you take over and redo with an updated PR replacing this one?

java/mtsj/core/pom.xml Show resolved Hide resolved
Comment on lines 38 to 48
public class TokenAuthenticationService {

/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(TokenAuthenticationService.class);

@Inject
private KeyStoreAccess keyStoreAccess;

@Inject
private JwtConfigProperties jwtConfig;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still wondering why this class is still needed after all.

Copy link
Member

@ravicm2 ravicm2 Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class has been used in multiple classes like AdvancedDaoAuthenticationProvider calls method getRolesFromName, PreLoginFilter and TwoFactorFilter uses constant variable OTP. @hohwille

Comment on lines +35 to +36
private JwtCreator jwtCreator;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO 2FA should be independent of or alternative to JWT:

  • Typically there is a login process for human authentication. For advanced security that process may require a second factor (2FA)
  • a valid JWT is however a result of a successful authentication and prevents further need for authentication so it replaces the authentication process.

So in the end this still does not make sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can see in the PR , it is used to get the token from the Authentication and pass it as header to the HttpServletRequest. So, should i remove this part? @hohwille

Copy link
Member

@markusschuh markusschuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO the JWT should be returned to the browser after successful login as part of a JSON structure inside the response body - instead within the "Authorization" header. At least for me this seems to be the most often used method, especially in case of OpenID Connect. I am not aware, there were a standard for this JWT transfer to browser in a pure "JWT auth" architecture, though. So there is not only one right implementation for this.

Nevertheless: The meaning of the Authorization header is not defined, when it is used within the response - so if really a response header should be used for the transfer, that should be better a header name with leading "X-".
Due to that also the return of the "Bearer " prefix (currently within the Authentication header in response to /login) seem superfluous to me. This has no real meaning (since Authorization header in response has no meaning). That might also the reason, the "Bearer" was added again on Angular side (so the resulting header has the "Bearer " twice) - again this addition on browser side is the most often usage for JWT use, I have seen so far in other implementations.

@sjimenez77 sjimenez77 force-pushed the develop branch 2 times, most recently from c98d581 to 2783216 Compare October 22, 2020 11:36
@CLAassistant
Copy link

CLAassistant commented Jan 13, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
5 out of 6 committers have signed the CLA.

✅ sjimenez77
✅ dario-rodriguez
✅ maihacke
✅ vapadwal
✅ derochs
❌ marochs


marochs seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@stale
Copy link

stale bot commented Sep 7, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

1 similar comment
@stale
Copy link

stale bot commented Oct 7, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 7, 2022
@stale stale bot closed this Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.