提交 19180584 编写于 作者: M MaxKey

Cached App Details

上级 13102d53
......@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsCasDetails;
import org.maxkey.persistence.mapper.AppsCasDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
protected final static Cache<String, AppsCasDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsCasDetailsService() {
super(AppsCasDetailsMapper.class);
}
......@@ -37,7 +48,17 @@ public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
return (AppsCasDetailsMapper)super.getMapper();
}
public AppsCasDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsCasDetails getAppDetails(String id , boolean cached) {
AppsCasDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}
......@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsFormBasedDetails;
import org.maxkey.persistence.mapper.AppsFormBasedDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsFormBasedDetailsService extends JpaBaseService<AppsFormBasedDetails>{
protected final static Cache<String, AppsFormBasedDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsFormBasedDetailsService() {
super(AppsFormBasedDetailsMapper.class);
}
......@@ -37,7 +48,17 @@ public class AppsFormBasedDetailsService extends JpaBaseService<AppsFormBasedDe
return (AppsFormBasedDetailsMapper)super.getMapper();
}
public AppsFormBasedDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsFormBasedDetails getAppDetails(String id,boolean cached) {
AppsFormBasedDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}
......@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsJwtDetails;
import org.maxkey.persistence.mapper.AppsJwtDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsJwtDetailsService extends JpaBaseService<AppsJwtDetails>{
protected final static Cache<String, AppsJwtDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsJwtDetailsService() {
super(AppsJwtDetailsMapper.class);
}
......@@ -37,7 +48,17 @@ public class AppsJwtDetailsService extends JpaBaseService<AppsJwtDetails>{
return (AppsJwtDetailsMapper)super.getMapper();
}
public AppsJwtDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsJwtDetails getAppDetails(String id , boolean cached) {
AppsJwtDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}
......@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsSAML20Details;
import org.maxkey.persistence.mapper.AppsSaml20DetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsSaml20DetailsService extends JpaBaseService<AppsSAML20Details>{
protected final static Cache<String, AppsSAML20Details> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsSaml20DetailsService() {
super(AppsSaml20DetailsMapper.class);
}
......@@ -37,7 +48,17 @@ public class AppsSaml20DetailsService extends JpaBaseService<AppsSAML20Details>
return (AppsSaml20DetailsMapper)super.getMapper();
}
public AppsSAML20Details getAppDetails(String id){
return getMapper().getAppDetails(id);
public AppsSAML20Details getAppDetails(String id , boolean cached){
AppsSAML20Details details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}
......@@ -17,14 +17,25 @@
package org.maxkey.persistence.service;
import java.util.concurrent.TimeUnit;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.entity.apps.AppsTokenBasedDetails;
import org.maxkey.persistence.mapper.AppsTokenBasedDetailsMapper;
import org.springframework.stereotype.Repository;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@Repository
public class AppsTokenBasedDetailsService extends JpaBaseService<AppsTokenBasedDetails>{
protected final static Cache<String, AppsTokenBasedDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
.build();
public AppsTokenBasedDetailsService() {
super(AppsTokenBasedDetailsMapper.class);
}
......@@ -37,7 +48,17 @@ public class AppsTokenBasedDetailsService extends JpaBaseService<AppsTokenBased
return (AppsTokenBasedDetailsMapper)super.getMapper();
}
public AppsTokenBasedDetails getAppDetails(String id) {
return getMapper().getAppDetails(id);
public AppsTokenBasedDetails getAppDetails(String id , boolean cached) {
AppsTokenBasedDetails details = null;
if(cached) {
details = detailsCache.getIfPresent(id);
if(details == null) {
details = getMapper().getAppDetails(id);
detailsCache.put(id, details);
}
}else {
details = getMapper().getAppDetails(id);
}
return details;
}
}
......@@ -63,10 +63,9 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
HttpServletResponse response,
@RequestParam(value=CasConstants.PARAMETER.SERVICE,required=false) String casService){
AppsCasDetails casDetails=casDetailsService.getAppDetails(casService);
AppsCasDetails casDetails=casDetailsService.getAppDetails(casService , true);
return buildCasModelAndView(request,response,casDetails,casService);
}
@Operation(summary = "CAS页面跳转应用ID认证接口", description = "传递参数应用ID",method="GET")
......@@ -76,7 +75,7 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
HttpServletResponse response,
@PathVariable("id") String id){
AppsCasDetails casDetails=casDetailsService.getAppDetails(id);
AppsCasDetails casDetails=casDetailsService.getAppDetails(id , true);
return buildCasModelAndView(request,response,casDetails,casDetails.getCallbackUrl());
}
......
......@@ -91,8 +91,8 @@ public class CasRestV1Endpoint extends CasBaseAuthorizeEndpoint{
String location = applicationConfig.getServerPrefix()+CasConstants.ENDPOINT.ENDPOINT_REST_TICKET_V1 +"/" + ticket;
HttpHeaders headers = new HttpHeaders();
headers.add("location", location);
_logger.trace("ticket "+ticket);
_logger.trace("location "+location);
_logger.trace("ticket {}" , ticket);
_logger.trace("location {}" , location);
return new ResponseEntity<>("Location: " + location, headers ,HttpStatus.CREATED);
} catch (final AuthenticationException e) {
......@@ -121,10 +121,10 @@ public class CasRestV1Endpoint extends CasBaseAuthorizeEndpoint{
TicketGrantingTicketImpl ticketGrantingTicketImpl =
(TicketGrantingTicketImpl) casTicketGrantingTicketServices.get(ticketGrantingTicket);
AppsCasDetails casDetails=casDetailsService.getAppDetails(casService);
AppsCasDetails casDetails=casDetailsService.getAppDetails(casService , true);
ServiceTicketImpl serviceTicket=new ServiceTicketImpl(ticketGrantingTicketImpl.getAuthentication(),casDetails);
String ticket=ticketServices.createTicket(serviceTicket);
String ticket = ticketServices.createTicket(serviceTicket);
return new ResponseEntity<>(ticket, HttpStatus.OK);
} catch (Exception e) {
......
......@@ -64,7 +64,7 @@ public class FormBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
HttpServletRequest request,
@PathVariable("id") String id){
AppsFormBasedDetails formBasedDetails = formBasedDetailsService.getAppDetails(id);
AppsFormBasedDetails formBasedDetails = formBasedDetailsService.getAppDetails(id , true);
_logger.debug("formBasedDetails {}",formBasedDetails);
Apps application = getApp(id);
formBasedDetails.setAdapter(application.getAdapter());
......
......@@ -79,7 +79,7 @@ public class JwtAuthorizeEndpoint extends AuthorizeBaseEndpoint{
@PathVariable("id") String id){
ModelAndView modelAndView=new ModelAndView();
Apps application = getApp(id);
AppsJwtDetails jwtDetails = jwtDetailsService.getAppDetails(id);
AppsJwtDetails jwtDetails = jwtDetailsService.getAppDetails(id , true);
_logger.debug(""+jwtDetails);
jwtDetails.setAdapter(application.getAdapter());
jwtDetails.setIsAdapter(application.getIsAdapter());
......@@ -146,7 +146,7 @@ public class JwtAuthorizeEndpoint extends AuthorizeBaseEndpoint{
HttpServletResponse response,
@PathVariable("appid") String appId,
@PathVariable("mediaType") String mediaType) {
AppsJwtDetails jwtDetails = jwtDetailsService.getAppDetails(appId);
AppsJwtDetails jwtDetails = jwtDetailsService.getAppDetails(appId , true);
if(jwtDetails != null) {
String jwkSetString = "";
if(!jwtDetails.getSignature().equalsIgnoreCase("none")) {
......
......@@ -58,7 +58,7 @@ public class JdbcClientDetailsService implements ClientDetailsService, ClientReg
private static final Log logger = LogFactory.getLog(JdbcClientDetailsService.class);
protected final static Cache<String, ClientDetails> clientDetailsCache =
protected final static Cache<String, ClientDetails> detailsCache =
Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.maximumSize(200000)
......@@ -127,19 +127,27 @@ public class JdbcClientDetailsService implements ClientDetailsService, ClientReg
public ClientDetails loadClientByClientId(String clientId,boolean cached) {
// cache in memory
ClientDetails details = null;
if(cached) {
details = clientDetailsCache.getIfPresent(clientId);
}
if(details == null) {
try {
details = jdbcTemplate.queryForObject(selectClientDetailsSql, new ClientDetailsRowMapper(), clientId);
if(cached) {
clientDetailsCache.put(clientId, details);
}
} catch (EmptyResultDataAccessException e) {
throw new NoSuchClientException("No client with requested id: " + clientId);
}
ClientDetails details = null;
try {
if(cached) {
details = detailsCache.getIfPresent(clientId);
if(details == null) {
details = jdbcTemplate.queryForObject(
selectClientDetailsSql,
new ClientDetailsRowMapper(),
clientId
);
detailsCache.put(clientId, details);
}
}else {
details = jdbcTemplate.queryForObject(
selectClientDetailsSql,
new ClientDetailsRowMapper(),
clientId
);
}
} catch (EmptyResultDataAccessException e) {
throw new NoSuchClientException("No client with requested id: " + clientId);
}
return details;
}
......@@ -157,7 +165,7 @@ public class JdbcClientDetailsService implements ClientDetailsService, ClientReg
if (count != 1) {
throw new NoSuchClientException("No client found with id = " + clientDetails.getClientId());
}
clientDetailsCache.invalidate(clientDetails.getClientId());
detailsCache.invalidate(clientDetails.getClientId());
}
public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
......
......@@ -92,7 +92,7 @@ public class IdpInitEndpoint {
HttpServletResponse response,
@PathVariable("appid") String appId)throws Exception {
logger.debug("SAML IDP init , app id is "+appId);
AppsSAML20Details saml20Details = saml20DetailsService.getAppDetails(appId);
AppsSAML20Details saml20Details = saml20DetailsService.getAppDetails(appId , true);
WebContext.setAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP, saml20Details);
if (saml20Details == null) {
logger.error("samlId[" + appId + "] Error .");
......
......@@ -113,7 +113,7 @@ public class SingleSignOnEndpoint {
}
public void extractSaml20Detail(ExtractBindingAdapter extractBindingAdapter,String samlId) throws Exception{
AppsSAML20Details saml20Details = saml20DetailsService.getAppDetails(samlId);
AppsSAML20Details saml20Details = saml20DetailsService.getAppDetails(samlId , true);
WebContext.setAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP, saml20Details);
if (saml20Details == null) {
logger.error("Request SAML APPID [" + samlId + "] is not exist .");
......
......@@ -71,7 +71,7 @@ public class TokenBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
AppsTokenBasedDetails tokenBasedDetails=null;
tokenBasedDetails=tokenBasedDetailsService.getAppDetails(id);
tokenBasedDetails=tokenBasedDetailsService.getAppDetails(id , true);
_logger.debug(""+tokenBasedDetails);
Apps application= getApp(id);
......
......@@ -46,11 +46,11 @@ public class AccountsStrategyJob implements Job , Serializable {
@Override
public void execute(JobExecutionContext context){
if(jobStatus == JOBSTATUS.RUNNING) {
_logger.info("DynamicGroupsJob is in running . " );
_logger.info("Accounts Strategy job is in running . " );
return;
}
_logger.debug("DynamicGroupsJob is running ... " );
_logger.debug("Accounts Strategy job is running ... " );
jobStatus = JOBSTATUS.RUNNING;
try {
if(accountsService == null) {
......@@ -58,15 +58,16 @@ public class AccountsStrategyJob implements Job , Serializable {
(AccountsService) context.getMergedJobDataMap().get("service");
}else {
accountsService.refreshAllByStrategy();
Thread.sleep(10 *1000);
//10 minutes
Thread.sleep(10 * 1000);
}
_logger.debug("DynamicGroupsJob is success " );
_logger.debug("Accounts Strategy job is success " );
}catch(Exception e) {
_logger.error("Exception " ,e);
jobStatus = JOBSTATUS.STOP;
}
jobStatus = JOBSTATUS.FINISHED;
_logger.debug("DynamicGroupsJob is finished . " );
_logger.debug("Accounts Strategy job is finished . " );
}
......
......@@ -74,7 +74,7 @@ public class CasDetailsController extends BaseAppContorller {
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("apps/cas/appUpdate");
AppsCasDetails casDetails=casDetailsService.getAppDetails(id);
AppsCasDetails casDetails=casDetailsService.getAppDetails(id , false);
super.decoderSecret(casDetails);
WebContext.setAttribute(casDetails.getId(), casDetails.getIcon());
......
......@@ -77,7 +77,7 @@ public class FormBasedDetailsController extends BaseAppContorller {
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("apps/formbased/appUpdate");
AppsFormBasedDetails formBasedDetails=formBasedDetailsService.getAppDetails(id);
AppsFormBasedDetails formBasedDetails=formBasedDetailsService.getAppDetails(id , false);
decoderSecret(formBasedDetails);
decoderSharedPassword(formBasedDetails);
WebContext.setAttribute(formBasedDetails.getId(), formBasedDetails.getIcon());
......
......@@ -77,7 +77,7 @@ public class JwtDetailsController extends BaseAppContorller {
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("apps/jwt/appUpdate");
AppsJwtDetails jwtDetails=jwtDetailsService.getAppDetails(id);
AppsJwtDetails jwtDetails=jwtDetailsService.getAppDetails(id , false);
decoderSecret(jwtDetails);
WebContext.setAttribute(jwtDetails.getId(), jwtDetails.getIcon());
......
......@@ -104,7 +104,7 @@ public class SAML20DetailsController extends BaseAppContorller {
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("apps/saml20/appUpdate");
AppsSAML20Details saml20Details=saml20DetailsService.getAppDetails(id);
AppsSAML20Details saml20Details=saml20DetailsService.getAppDetails(id , false);
decoderSecret(saml20Details);
WebContext.setAttribute(saml20Details.getId(), saml20Details.getIcon());
modelAndView.addObject("model",saml20Details);
......
......@@ -79,7 +79,7 @@ public class TokenBasedDetailsController extends BaseAppContorller {
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("apps/tokenbased/appUpdate");
AppsTokenBasedDetails tokenBasedDetails=tokenBasedDetailsService.getAppDetails(id);
AppsTokenBasedDetails tokenBasedDetails=tokenBasedDetailsService.getAppDetails(id , false);
decoderSecret(tokenBasedDetails);
String algorithmKey=passwordReciprocal.decoder(tokenBasedDetails.getAlgorithmKey());
tokenBasedDetails.setAlgorithmKey(algorithmKey);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册