diff --git a/src/main/java/at/ac/uibk/gitsearch/config/SecurityConfiguration.java b/src/main/java/at/ac/uibk/gitsearch/config/SecurityConfiguration.java index ceacaee2190b91741352ce4a16cf542337d48e11..d427cdf15d6c6b42d1bb3859dca50d4fb3dbd1f1 100644 --- a/src/main/java/at/ac/uibk/gitsearch/config/SecurityConfiguration.java +++ b/src/main/java/at/ac/uibk/gitsearch/config/SecurityConfiguration.java @@ -130,6 +130,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .ignoringAntMatchers("/api/search/**") // Allowing search even without CSRF Token + .ignoringAntMatchers("/api/pluginIF/**") // Allowing plugin Access. security is checked by token .and() .authenticationProvider(customJWTauthenticationProvider()) .addFilterBefore(corsFilter, CsrfFilter.class) @@ -156,6 +157,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .authorizeRequests() .antMatchers("/oauth2/**").permitAll() .antMatchers("/api/search/**").permitAll() // search is always allowed, may return more data, if authenticated + .antMatchers("/api/pluginIF/**").permitAll() // plugins calls are always allowed, security by tokens .antMatchers("/api/authenticate").permitAll() .antMatchers("/api/refreshToken").permitAll() .antMatchers("/api/register").denyAll() diff --git a/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java b/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java new file mode 100644 index 0000000000000000000000000000000000000000..8980f5dfe76127584784aeadf400383078d617eb --- /dev/null +++ b/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java @@ -0,0 +1,136 @@ +package at.ac.uibk.gitsearch.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * Service for exercise/course search results + * <p> + */ +@Service +public class ShoppingBasketService { + + public static class ShoppingBasket { + private UserInfo userInfo; + private ExerciseInfo[] exerciseInfo; + + + public ShoppingBasket(UserInfo userInfo, ExerciseInfo[] exerciseInfo) { + super(); + this.userInfo = userInfo; + this.exerciseInfo = exerciseInfo; + } + /** + * @return the userInfo + */ + public UserInfo getUserInfo() { + return userInfo; + } + /** + * @param userInfo the userInfo to set + */ + public void setUserInfo(UserInfo userInfo) { + this.userInfo = userInfo; + } + /** + * @return the exerciseInfo + */ + public ExerciseInfo[] getExerciseInfo() { + return exerciseInfo; + } + /** + * @param exerciseInfo the exerciseInfo to set + */ + public void setExerciseInfo(ExerciseInfo[] exerciseInfo) { + this.exerciseInfo = exerciseInfo; + } + } + public static class UserInfo { + String email; + + public UserInfo(String email) { + super(); + this.email = email; + } + + /** + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * @param email the email to set + */ + public void setEmail(String email) { + this.email = email; + } + } + + public static class ExerciseInfo { + private String gitLabURI; + private int gitLabProjectId; + private String title; + + public ExerciseInfo(String title, int gitLabProjectId, String gitLabURI) { + super(); + this.title = title; + this.setGitLabProjectId(gitLabProjectId); + this.gitLabURI = gitLabURI; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the gitLabURI + */ + public String getGitLabURI() { + return gitLabURI; + } + + /** + * @param gitLabURI the gitLabURI to set + */ + public void setGitLabURI(String gitLabURI) { + this.gitLabURI = gitLabURI; + } + + public int getGitLabProjectId() { + return gitLabProjectId; + } + + public void setGitLabProjectId(int gitLabProjectId) { + this.gitLabProjectId = gitLabProjectId; + } + + } + + private final Logger log = LoggerFactory.getLogger(ShoppingBasketService.class); + + + public ShoppingBasketService() { + + } + + public ShoppingBasket getBasket(String basketToken) { + final UserInfo userInfo = new UserInfo("Michael.Breu@uibk.ac.at"); + final ExerciseInfo exerciseInfo = new ExerciseInfo("JUnit Quality Tests Exercise", 3, "https://sharing.codeability-austria.uibk.ac.at/sharing/university-innsbruck/java/general/junit-quality-tests-exercise.git"); + final ShoppingBasket shoppingBasket = new ShoppingBasket(userInfo, new ExerciseInfo[] {exerciseInfo}); + return shoppingBasket; + } + +} diff --git a/src/main/java/at/ac/uibk/gitsearch/web/rest/PluginInterfaceResource.java b/src/main/java/at/ac/uibk/gitsearch/web/rest/PluginInterfaceResource.java new file mode 100644 index 0000000000000000000000000000000000000000..7392267b4666e35ed91e01d7eec51e5b6395dfe1 --- /dev/null +++ b/src/main/java/at/ac/uibk/gitsearch/web/rest/PluginInterfaceResource.java @@ -0,0 +1,45 @@ +package at.ac.uibk.gitsearch.web.rest; + +import java.io.IOException; + +import javax.websocket.server.PathParam; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import at.ac.uibk.gitsearch.es.model.DocumentInfo; +import at.ac.uibk.gitsearch.service.ShoppingBasketService; +import at.ac.uibk.gitsearch.service.ShoppingBasketService.ShoppingBasket; + +/** + * REST controller for managing {@link DocumentInfo}. + */ +@RestController +@RequestMapping("/api") +@Transactional +public class PluginInterfaceResource { + + private final Logger log = LoggerFactory.getLogger(PluginInterfaceResource.class); + + @Autowired + private ShoppingBasketService basketService; + /** + * {@code SEARCH /search/page-details} : search for the searchResults corresponding + * to the query. + * + * @param query the query of the searchResult search. + * @return the result of the search. + */ + @GetMapping("/pluginIF/getBasket/{basketToken}") + public ShoppingBasket + searchPageDetails(@PathParam("basketToken") String basketToken) throws IOException { + log.debug("REST request for basket {}", basketToken); + return basketService.getBasket(basketToken); + } + +}