mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 20:50:14 +08:00
Cached App Details
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user