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

Authorization code issue #281

Merged
merged 7 commits into from
Jul 4, 2018
Merged

Authorization code issue #281

merged 7 commits into from
Jul 4, 2018

Conversation

nivemaham
Copy link
Collaborator

@nivemaham nivemaham commented Jul 3, 2018

Authorization-code flow didn't work with Postgres as database so far. It happened due to hard-coded queries that have case sensitive values. These have to be escaped with quotes for postgres.
As a fix a PostgresApprovalStore is added with same implementation, but escaped queries.
We have to keep the JdbcApprovalStore as well to support database other than postgres (e.g. H2)

  • Adds a custom PhysicalNamingStrategy and PostgresApprovalStore

TODO
Re-factor PostgresApprovalStore to simplify the implementation.

Fixes #279

@@ -4,4 +4,4 @@ aRMT;res_ManagementPortal,res_gateway;secret;MEASUREMENT.CREATE,SUBJECT.UPDATE,S
THINC-IT;res_ManagementPortal,res_gateway;secret;MEASUREMENT.CREATE,SUBJECT.UPDATE,SUBJECT.READ,PROJECT.READ,SOURCETYPE.READ,SOURCE.READ,SOURCETYPE.READ,SOURCEDATA.READ,USER.READ,ROLE.READ;refresh_token,authorization_code;;;43200;7948800;{"dynamic_registration": true};
radar_restapi;res_ManagementPortal;secret;SUBJECT.READ,PROJECT.READ,SOURCE.READ,SOURCETYPE.READ;client_credentials;;;43200;259200;{};
radar_redcap_integrator;res_ManagementPortal;secret;PROJECT.READ,SUBJECT.CREATE,SUBJECT.READ,SUBJECT.UPDATE;client_credentials;;;43200;259200;{};
radar_dashboard;res_ManagementPortal,res_RestApi;secret;SUBJECT.READ,PROJECT.READ,SOURCE.READ,SOURCETYPE.READ;client_credentials;;;43200;259200;{};
radar_dashboard;res_ManagementPortal,res_RestApi;secret;SUBJECT.READ,PROJECT.READ,SOURCE.READ,SOURCETYPE.READ;authorization_code;;;43200;259200;{};
Copy link
Contributor

Choose a reason for hiding this comment

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

Refresh token here would also be useful

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;

public class RadarPhysicalNamingStrategy extends SpringPhysicalNamingStrategy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps PostgresPhysicalNamingStrategy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or CaseSensitivePhysicalNamingStrategy

@@ -174,7 +181,11 @@ protected AuthorizationCodeServices authorizationCodeServices() {

@Bean
public ApprovalStore approvalStore() {
return new JdbcApprovalStore(dataSource);
if (jpaProperties.getDatabase().equals(POSTGRESQL)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the new ApprovalStore also works for H2, perhaps rename it to SanitizedJdbcApprovalStore And remove this if/else branch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't. That's why the if else was added later on. H2 doesn't like quotes.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's unfortunate... Would using hibernate solve that? Or would that be too large of a refactor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My guess would be not large. Currently, we do not have entities maintained by hibernate in for oauth related tables or in other words, we only have the database schema given by spring added. The rest are handled by spring-security-oauth. I assume having a local entity shouldn't effect the rest. Maybe a separate PR would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, a separate PR seems fine.

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;

public class RadarPhysicalNamingStrategy extends SpringPhysicalNamingStrategy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Or CaseSensitivePhysicalNamingStrategy

@nivemaham nivemaham merged commit ac96244 into dev Jul 4, 2018
@nivemaham nivemaham deleted the authorization-code-issue branch July 6, 2018 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants