Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
		
						commit
						ec4938d57e
					
				
					 5 changed files with 36 additions and 12 deletions
				
			
		|  | @ -14,8 +14,14 @@ import java.util.Map; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| 
 | 
 | ||||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  | import org.springframework.context.event.EventListener; | ||||||
|  | import org.springframework.scheduling.annotation.Async; | ||||||
| 
 | 
 | ||||||
|  | import ch.ethz.seb.sebserver.SEBServerInitEvent; | ||||||
| import ch.ethz.seb.sebserver.gbl.Constants; | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.async.AsyncServiceSpringConfig; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction; | import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction.InstructionType; | import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction.InstructionType; | ||||||
| import ch.ethz.seb.sebserver.gbl.util.Result; | import ch.ethz.seb.sebserver.gbl.util.Result; | ||||||
|  | @ -27,11 +33,31 @@ import ch.ethz.seb.sebserver.webservice.WebserviceInfo; | ||||||
|  * If there is an instruction in the queue for a specified SEB Client. */ |  * If there is an instruction in the queue for a specified SEB Client. */ | ||||||
| public interface SEBClientInstructionService { | public interface SEBClientInstructionService { | ||||||
| 
 | 
 | ||||||
|  |     static final Logger log = LoggerFactory.getLogger(SEBClientInstructionService.class); | ||||||
|  | 
 | ||||||
|     /** Get the underling WebserviceInfo |     /** Get the underling WebserviceInfo | ||||||
|      * |      * | ||||||
|      * @return the underling WebserviceInfo */ |      * @return the underling WebserviceInfo */ | ||||||
|     WebserviceInfo getWebserviceInfo(); |     WebserviceInfo getWebserviceInfo(); | ||||||
| 
 | 
 | ||||||
|  |     /** This is called from the SEB Server initializer to initialize this service. | ||||||
|  |      * Do not use this directly. */ | ||||||
|  |     @EventListener(SEBServerInitEvent.class) | ||||||
|  |     void init(); | ||||||
|  | 
 | ||||||
|  |     /** Used to register a SEB client instruction for one or more active client connections | ||||||
|  |      * within an other background thread. This is none-blocking. | ||||||
|  |      * | ||||||
|  |      * @param clientInstruction the ClientInstruction instance to register | ||||||
|  |      * @return A Result refer to a void marker or to an error if happened */ | ||||||
|  |     @Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME) | ||||||
|  |     default void registerInstructionAsync(final ClientInstruction clientInstruction) { | ||||||
|  |         registerInstruction(clientInstruction, false) | ||||||
|  |                 .onError(error -> log.error("Failed to register client instruction asynchronously: {}", | ||||||
|  |                         clientInstruction, | ||||||
|  |                         error)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** Used to register a SEB client instruction for one or more active client connections |     /** Used to register a SEB client instruction for one or more active client connections | ||||||
|      * |      * | ||||||
|      * @param clientInstruction the ClientInstruction instance to register |      * @param clientInstruction the ClientInstruction instance to register | ||||||
|  |  | ||||||
|  | @ -22,11 +22,9 @@ import org.joda.time.DateTimeZone; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
| import org.springframework.context.annotation.Lazy; | import org.springframework.context.annotation.Lazy; | ||||||
| import org.springframework.context.event.EventListener; |  | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.SEBServerInit; | import ch.ethz.seb.sebserver.SEBServerInit; | ||||||
| import ch.ethz.seb.sebserver.SEBServerInitEvent; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.Constants; | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.JSONMapper; | import ch.ethz.seb.sebserver.gbl.api.JSONMapper; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; | import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||||||
|  | @ -80,7 +78,7 @@ public class SEBClientInstructionServiceImpl implements SEBClientInstructionServ | ||||||
|         return this.webserviceInfo; |         return this.webserviceInfo; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @EventListener(SEBServerInitEvent.class) |     @Override | ||||||
|     public void init() { |     public void init() { | ||||||
|         SEBServerInit.INIT_LOGGER.info("------>"); |         SEBServerInit.INIT_LOGGER.info("------>"); | ||||||
|         SEBServerInit.INIT_LOGGER.info("------> Run SEBInstructionService..."); |         SEBServerInit.INIT_LOGGER.info("------> Run SEBInstructionService..."); | ||||||
|  |  | ||||||
|  | @ -222,7 +222,7 @@ public class ExamMonitoringController { | ||||||
|             @Valid @RequestBody final ClientInstruction clientInstruction) { |             @Valid @RequestBody final ClientInstruction clientInstruction) { | ||||||
| 
 | 
 | ||||||
|         checkPrivileges(institutionId, examId); |         checkPrivileges(institutionId, examId); | ||||||
|         this.sebClientInstructionService.registerInstruction(clientInstruction); |         this.sebClientInstructionService.registerInstructionAsync(clientInstruction); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|  |  | ||||||
|  | @ -50,10 +50,6 @@ public class CachableJdbcTokenStore implements TokenStore { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     @Cacheable( |  | ||||||
|             cacheNames = CACHE_NAME, |  | ||||||
|             key = "#token", |  | ||||||
|             unless = "#result == null") |  | ||||||
|     public OAuth2Authentication readAuthentication(final OAuth2AccessToken token) { |     public OAuth2Authentication readAuthentication(final OAuth2AccessToken token) { | ||||||
|         if (log.isDebugEnabled()) { |         if (log.isDebugEnabled()) { | ||||||
|             log.debug("Read authentication from persistent and cache if available"); |             log.debug("Read authentication from persistent and cache if available"); | ||||||
|  | @ -68,6 +64,10 @@ public class CachableJdbcTokenStore implements TokenStore { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  |     @Cacheable( | ||||||
|  |             cacheNames = CACHE_NAME, | ||||||
|  |             key = "#tokenValue", | ||||||
|  |             unless = "#result == null") | ||||||
|     public OAuth2AccessToken readAccessToken(final String tokenValue) { |     public OAuth2AccessToken readAccessToken(final String tokenValue) { | ||||||
|         return this.jdbcTokenStore.readAccessToken(tokenValue); |         return this.jdbcTokenStore.readAccessToken(tokenValue); | ||||||
|     } |     } | ||||||
|  | @ -75,7 +75,7 @@ public class CachableJdbcTokenStore implements TokenStore { | ||||||
|     @Override |     @Override | ||||||
|     @CacheEvict( |     @CacheEvict( | ||||||
|             cacheNames = CACHE_NAME, |             cacheNames = CACHE_NAME, | ||||||
|             key = "#token") |             key = "#token.getValue()") | ||||||
|     public void removeAccessToken(final OAuth2AccessToken token) { |     public void removeAccessToken(final OAuth2AccessToken token) { | ||||||
|         if (log.isDebugEnabled()) { |         if (log.isDebugEnabled()) { | ||||||
|             log.debug("Evict token from cache and remove it also from persistent store"); |             log.debug("Evict token from cache and remove it also from persistent store"); | ||||||
|  |  | ||||||
|  | @ -61,10 +61,10 @@ | ||||||
|     </cache> |     </cache> | ||||||
|      |      | ||||||
|     <cache alias="ACCESS_TOKEN_STORE_CACHE"> |     <cache alias="ACCESS_TOKEN_STORE_CACHE"> | ||||||
|         <key-type>org.springframework.security.oauth2.common.OAuth2AccessToken</key-type> |         <key-type>java.lang.String</key-type> | ||||||
|         <value-type>org.springframework.security.oauth2.provider.OAuth2Authentication</value-type> |         <value-type>org.springframework.security.oauth2.common.OAuth2AccessToken</value-type> | ||||||
|         <expiry> |         <expiry> | ||||||
|             <ttl unit="hours">24</ttl> |             <ttl unit="hours">1</ttl> | ||||||
|         </expiry> |         </expiry> | ||||||
|         <resources> |         <resources> | ||||||
|             <heap unit="entries">100</heap> |             <heap unit="entries">100</heap> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Damian Büchel
						Damian Büchel