Implemented OAuth2 request access token with authorization code grant.
Change-Id: Ia3c427316748876db65373b31ea453bb71f9448b
diff --git a/full/src/main/resources/db/new-sqlite/V1.4__oauth2_tables.sql b/full/src/main/resources/db/new-sqlite/V1.4__oauth2_tables.sql
index c055f4d..28a5de2 100644
--- a/full/src/main/resources/db/new-sqlite/V1.4__oauth2_tables.sql
+++ b/full/src/main/resources/db/new-sqlite/V1.4__oauth2_tables.sql
@@ -16,3 +16,55 @@
CREATE UNIQUE INDEX client_id_index on oauth2_client(id);
CREATE UNIQUE INDEX client_url_index on oauth2_client(url_hashcode);
+
+CREATE TABLE IF NOT EXISTS oauth2_authorization (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ code VARCHAR(250) NOT NULL,
+ client_id VARCHAR(100) NOT NULL,
+ user_id VARCHAR(100) NOT NULL,
+ redirect_uri TEXT DEFAULT NULL,
+ created_date timestamp DEFAULT (datetime('now','localtime')),
+ is_revoked BOOLEAN DEFAULT 0,
+ total_attempts INTEGER DEFAULT 0,
+ FOREIGN KEY (client_id)
+ REFERENCES oauth2_client(id)
+);
+
+CREATE UNIQUE INDEX authorization_index on oauth2_authorization(code, client_id);
+
+CREATE TABLE IF NOT EXISTS oauth2_access_scope (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name VARCHAR(200) NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS oauth2_authorization_scope (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ authorization_id INTEGER NOT NULL,
+ scope_id INTEGER NOT NULL,
+ FOREIGN KEY (authorization_id)
+ REFERENCES oauth2_authorization(id),
+ FOREIGN KEY (scope_id)
+ REFERENCES access_scope(id)
+);
+
+CREATE UNIQUE INDEX authorization_scope_index on
+ oauth2_authorization_scope(authorization_id, scope_id);
+
+CREATE TRIGGER insert_created_date AFTER INSERT ON oauth2_authorization
+ BEGIN
+ UPDATE oauth2_authorization
+ SET created_date = DATETIME('now', 'localtime')
+ WHERE rowid = new.rowid;
+ END;
+
+CREATE TABLE IF NOT EXISTS oauth2_access_token (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ token VARCHAR(300) NOT NULL,
+ authorization_id INTEGER DEFAULT NULL,
+ created_date timestamp DEFAULT (datetime('now','localtime')),
+ is_revoked BOOLEAN DEFAULT 0,
+ total_attempts INTEGER DEFAULT 0,
+ FOREIGN KEY (authorization_id)
+ REFERENCES oauth2_authorization(id)
+);
+
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index 57f65ae..955d197 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -122,7 +122,12 @@
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="dataSource" ref="sqliteDataSource" />
- <property name="packagesToScan" value="de.ids_mannheim.korap.entity" />
+ <property name="packagesToScan">
+ <array>
+ <value>de.ids_mannheim.korap.entity</value>
+ <value>de.ids_mannheim.korap.oauth2.entity</value>
+ </array>
+ </property>
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
@@ -170,7 +175,7 @@
<constructor-arg value="http,https" />
</bean>
<bean id="httpsValidator" class="org.apache.commons.validator.routines.UrlValidator">
- <constructor-arg value="https"/>
+ <constructor-arg value="https" />
</bean>
<bean id="kustvakt_rewrite" class="de.ids_mannheim.korap.rewrite.FullRewriteHandler">
@@ -184,12 +189,12 @@
<bean id="kustvaktResponseHandler" class="de.ids_mannheim.korap.web.KustvaktExceptionHandler">
<constructor-arg index="0" name="iface" ref="kustvakt_auditing" />
</bean>
-
+
<!-- OAuth -->
<bean id="oauth2ResponseHandler" class="de.ids_mannheim.korap.web.OAuth2ResponseHandler">
<constructor-arg index="0" name="iface" ref="kustvakt_auditing" />
</bean>
-
+
<bean id="mdGenerator" class="org.apache.oltu.oauth2.as.issuer.MD5Generator">
</bean>
<bean id="oauthIssuer" class="org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl">
@@ -208,8 +213,7 @@
<constructor-arg ref="kustvakt_db" />
</bean>
- <bean name="kustvakt_encryption"
- class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
+ <bean name="kustvakt_encryption" class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
<constructor-arg ref="kustvakt_config" />
</bean>
@@ -218,9 +222,6 @@
<constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
ref="kustvakt_config" /> </bean> -->
- <bean id="client_auth"
- class="de.ids_mannheim.korap.authentication.OAuth2ClientAuthentication" />
-
<bean id="ldap_auth" class="de.ids_mannheim.korap.authentication.LdapAuth3">
<constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
ref="kustvakt_config" />