Skip to content

Commit

Permalink
Merge pull request #32 from indiana-university/LMSA-8524_swaggerize
Browse files Browse the repository at this point in the history
LMSA-8524 - did the work
  • Loading branch information
dsobiera authored May 24, 2024
2 parents 13d2898 + 37c70d8 commit 523e1e5
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<lms-embedded-services.version>5.2.35</lms-embedded-services.version>
<lms-team-spring-boot-it12>5.4.7</lms-team-spring-boot-it12>
<select2.version>4.0.13</select2.version>
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
<springdoc-openapi-ui.version>1.8.0</springdoc-openapi-ui.version>
<spring-cloud.version>2021.0.9</spring-cloud.version>
<tinymce.version>7.0.1</tinymce.version>
<webjars-locator.version>0.52</webjars-locator.version>
Expand Down Expand Up @@ -168,11 +168,21 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<!-- Tool specific dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package edu.iu.uits.lms.multiclassmessenger.config;

/*-
* #%L
* lms-canvas-multiclassmessenger
* %%
* Copyright (C) 2015 - 2024 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration("MulticlassMessengerDbConfig")
@EnableJpaRepositories(
entityManagerFactoryRef = "MulticlassMessengerEntityMgrFactory",
transactionManagerRef = "MulticlassMessengerTransactionMgr",
basePackages = {"edu.iu.uits.lms.multiclassmessenger.repositories"})

@EnableTransactionManagement
public class PostgresDBConfig {

@Primary
@Bean(name = "MulticlassMessengerDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().build();
}

@Bean(name = "MulticlassMessengerEntityMgrFactory")
@Primary
public LocalContainerEntityManagerFactoryBean multiclassMessengerEntityMgrFactory(
final EntityManagerFactoryBuilder builder,
@Qualifier("MulticlassMessengerDataSource") final DataSource dataSource) {
// dynamically setting up the hibernate properties for each of the datasource.
final Map<String, String> properties = new HashMap<>();
return builder
.dataSource(dataSource)
.properties(properties)
.packages("edu.iu.uits.lms.multiclassmessenger.model")
.build();
}

@Bean(name = "MulticlassMessengerTransactionMgr")
@Primary
public PlatformTransactionManager multiclassMessengerTransactionMgr(
@Qualifier("MulticlassMessengerEntityMgrFactory") final EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import static edu.iu.uits.lms.lti.LTIConstants.BASE_USER_ROLE;
import static edu.iu.uits.lms.lti.LTIConstants.JWKS_CONFIG_URI;
import static edu.iu.uits.lms.lti.LTIConstants.WELL_KNOWN_ALL;

@EnableWebSecurity
public class SecurityConfig {
Expand All @@ -64,9 +65,11 @@ protected void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers(JWKS_CONFIG_URI, "/**/config.json", "/annc/**", "/msg/**")
.antMatchers(WELL_KNOWN_ALL, "/api/**")
.and()
.authorizeRequests()
.antMatchers(JWKS_CONFIG_URI, "/**/config.json").permitAll()
.antMatchers(WELL_KNOWN_ALL, "/api/**").permitAll()
.antMatchers("/**").hasRole(BASE_USER_ROLE)
.withObjectPostProcessor(new LmsFilterSecurityInterceptorObjectPostProcessor())
.and()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package edu.iu.uits.lms.multiclassmessenger.config;

/*-
* #%L
* lms-canvas-multiclassmessenger
* %%
* Copyright (C) 2015 - 2024 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.security.OAuthFlow;
import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.OAuthScope;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("swagger")
@Configuration
@OpenAPIDefinition(info = @Info(title = "Multiclass Messenger REST Endpoints", version = "${multiclassmessenger.version}"),
security = @SecurityRequirement(name = "security_auth_multiclassmessenger"))
@SecurityScheme(name = "security_auth_multiclassmessenger", type = SecuritySchemeType.OAUTH2,
flows = @OAuthFlows(authorizationCode = @OAuthFlow(
authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}",
scopes = {@OAuthScope(name = "lms:rest")},
tokenUrl = "${springdoc.oAuthFlow.tokenUrl}")))
public class SwaggerConfig {
@Bean
public GroupedOpenApi groupedOpenApi() {
return GroupedOpenApi.builder()
.group("multiclassmessenger")
.packagesToScan("edu.iu.uits.lms.multiclassmessenger.rest")
.build();
}
}
12 changes: 11 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,19 @@ spring:
config:
activate.on-profile: swagger
springdoc:
api-docs:
enabled: true
path: /api/v3/api-docs
cache.disabled: true
packagesToScan: edu.iu.uits.lms.multiclassmessenger.rest
swagger-ui:
enabled: false
disable-swagger-default-url: true
path: /api/swagger-ui.html
# Setting supportedSubmitMethods to an empty list is what turns off the "try it out" button
# supportedSubmitMethods:
oauth:
clientId: ${oauth.tokenprovider.clientId}
oAuthFlow:
authorizationUrl: ${oauth.tokenprovider.url}/oauth/authorize
tokenUrl: ${oauth.tokenprovider.accessTokenUri}
tokenUrl: ${oauth.tokenprovider.accessTokenUri}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package edu.iu.uits.lms.multiclassmessenger.swagger;

/*-
* #%L
* lms-canvas-multiclassmessenger
* %%
* Copyright (C) 2015 - 2024 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import edu.iu.uits.lms.lti.swagger.AbstractSwaggerCustomTest;
import edu.iu.uits.lms.multiclassmessenger.WebApplication;
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class})
public class SwaggerCustomTest extends AbstractSwaggerCustomTest {

@Override
protected List<String> getEmbeddedSwaggerToolPaths() {
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package edu.iu.uits.lms.multiclassmessenger.swagger;

/*-
* #%L
* lms-canvas-multiclassmessenger
* %%
* Copyright (C) 2015 - 2024 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import edu.iu.uits.lms.lti.swagger.AbstractSwaggerDisabledTest;
import edu.iu.uits.lms.multiclassmessenger.WebApplication;
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class})
public class SwaggerDisabledTest extends AbstractSwaggerDisabledTest {

@Override
protected List<String> getEmbeddedSwaggerToolPaths() {
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package edu.iu.uits.lms.multiclassmessenger.swagger;

/*-
* #%L
* lms-canvas-multiclassmessenger
* %%
* Copyright (C) 2015 - 2024 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import edu.iu.uits.lms.lti.swagger.AbstractSwaggerEmbeddedToolTest;
import edu.iu.uits.lms.multiclassmessenger.WebApplication;
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class})
public class SwaggerEmbeddedToolTest extends AbstractSwaggerEmbeddedToolTest {

@Override
protected List<String> getEmbeddedSwaggerToolPaths() {
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths());
}
}
Loading

0 comments on commit 523e1e5

Please sign in to comment.