Expires change to Seconds
This commit is contained in:
@@ -74,7 +74,7 @@ public class AppsJwtDetails extends Apps {
|
||||
@Column
|
||||
private String signatureKey;
|
||||
@Column
|
||||
private String expires;
|
||||
private Integer expires;
|
||||
@Column
|
||||
private String instId;
|
||||
|
||||
@@ -207,12 +207,12 @@ public class AppsJwtDetails extends Apps {
|
||||
}
|
||||
|
||||
|
||||
public String getExpires() {
|
||||
public Integer getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
|
||||
public void setExpires(String expires) {
|
||||
public void setExpires(Integer expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class AppsTokenBasedDetails extends Apps {
|
||||
@Column
|
||||
private String algorithmKey;
|
||||
@Column
|
||||
private String expires;
|
||||
private Integer expires;
|
||||
@Column
|
||||
private String instId;
|
||||
|
||||
@@ -130,12 +130,12 @@ public class AppsTokenBasedDetails extends Apps {
|
||||
}
|
||||
|
||||
|
||||
public String getExpires() {
|
||||
public Integer getExpires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
|
||||
public void setExpires(String expires) {
|
||||
public void setExpires(Integer expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,8 +119,8 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
HttpServletResponse response){
|
||||
AppsCasDetails casDetails = (AppsCasDetails)WebContext.getAttribute(CasConstants.PARAMETER.ENDPOINT_CAS_DETAILS);
|
||||
ServiceTicketImpl serviceTicket = new ServiceTicketImpl(WebContext.getAuthentication(),casDetails);
|
||||
|
||||
String ticket = ticketServices.createTicket(serviceTicket);
|
||||
|
||||
String ticket = ticketServices.createTicket(serviceTicket,casDetails.getExpires());
|
||||
|
||||
StringBuffer callbackUrl = new StringBuffer(casDetails.getCallbackUrl());
|
||||
if(casDetails.getCallbackUrl().indexOf("?")==-1) {
|
||||
|
||||
@@ -54,6 +54,35 @@ public abstract class RandomServiceTicketServices implements TicketServices {
|
||||
return ticketId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTicket(Ticket ticket, int validitySeconds) {
|
||||
|
||||
//String code = generator.generate();
|
||||
/*
|
||||
* replace with uuid random code
|
||||
* add by Crystal.Sea
|
||||
*/
|
||||
//String ticket = UUID.randomUUID().toString();
|
||||
String ticketId = "";
|
||||
if(ticket.getClass().getSimpleName().equalsIgnoreCase("ServiceTicketImpl")){
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.SERVICE_TICKET_PREFIX);
|
||||
}else if(ticket.getClass().getSimpleName().equalsIgnoreCase("ProxyTicketImpl")){
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.PROXY_TICKET_PREFIX);
|
||||
}else if(ticket.getClass().getSimpleName().equalsIgnoreCase("TicketGrantingTicketImpl")){
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.TICKET_GRANTING_TICKET_PREFIX);
|
||||
}else if(ticket.getClass().getSimpleName().equalsIgnoreCase("ProxyGrantingTicketImpl")){
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.PROXY_GRANTING_TICKET_PREFIX);
|
||||
}else if(ticket.getClass().getSimpleName().equalsIgnoreCase("ProxyGrantingTicketIOUImpl")){
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.PROXY_GRANTING_TICKET_IOU_PREFIX);
|
||||
return ticketId;
|
||||
}else {
|
||||
ticketId = generator.getNewTicketId(CasConstants.PREFIX.SERVICE_TICKET_PREFIX);
|
||||
}
|
||||
|
||||
store(ticketId, ticket,validitySeconds);
|
||||
return ticketId;
|
||||
}
|
||||
|
||||
public Ticket consumeTicket(String ticketId) throws Exception{
|
||||
Ticket ticket = this.remove(ticketId);
|
||||
if (ticket == null) {
|
||||
|
||||
@@ -26,6 +26,8 @@ public interface TicketServices {
|
||||
* @return The generated code.
|
||||
*/
|
||||
String createTicket(Ticket ticket);
|
||||
|
||||
String createTicket(Ticket ticket , int validitySeconds);
|
||||
|
||||
/**
|
||||
* Consume a authorization code.
|
||||
@@ -38,6 +40,8 @@ public interface TicketServices {
|
||||
throws Exception;
|
||||
|
||||
public void store(String ticketId, Ticket ticket);
|
||||
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds);
|
||||
|
||||
public Ticket remove(String ticket);
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ public class InMemoryProxyGrantingTicketServices extends RandomServiceTicketServ
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
store(ticketId, ticket , 60 * 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
casTicketStore.put(ticketId, ticket);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,13 @@ public class RedisProxyGrantingTicketServices extends RandomServiceTicketService
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
store(ticketId,ticket,serviceTicketValiditySeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
RedisConnection conn=connectionFactory.getConnection();
|
||||
conn.setexObject(PREFIX+ticketId, serviceTicketValiditySeconds, ticket);
|
||||
conn.setexObject(PREFIX+ticketId, validitySeconds, ticket);
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ public class InMemoryTicketServices extends RandomServiceTicketServices {
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
store(ticketId, ticket, 60 * 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
casTicketStore.put(ticketId, ticket);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,15 @@ public class RedisTicketServices extends RandomServiceTicketServices {
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
store(ticketId,ticket,serviceTicketValiditySeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
RedisConnection conn=connectionFactory.getConnection();
|
||||
conn.setexObject(prefixTicketId(ticketId), serviceTicketValiditySeconds, ticket);
|
||||
conn.setexObject(prefixTicketId(ticketId), validitySeconds, ticket);
|
||||
conn.close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,13 @@ public class InMemoryTicketGrantingTicketServices extends RandomServiceTicketSer
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
casTicketGrantingTicketStore.put(ticketId, ticket);
|
||||
store(ticketId, ticket , 60 * 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
casTicketGrantingTicketStore.put(ticketId, ticket);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,8 +51,13 @@ public class RedisTicketGrantingTicketServices extends RandomServiceTicketServic
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket) {
|
||||
store(ticketId, ticket, serviceTicketValiditySeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(String ticketId, Ticket ticket, int validitySeconds) {
|
||||
RedisConnection conn=connectionFactory.getConnection();
|
||||
conn.setexObject(PREFIX+ticketId, serviceTicketValiditySeconds, ticket);
|
||||
conn.setexObject(PREFIX+ticketId, validitySeconds, ticket);
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class JwtAdapter extends AbstractAuthorizeAdapter {
|
||||
@Override
|
||||
public Object generateInfo() {
|
||||
DateTime currentDateTime = DateTime.now();
|
||||
Date expirationTime = currentDateTime.plusMinutes(Integer.parseInt(jwtDetails.getExpires())).toDate();
|
||||
Date expirationTime = currentDateTime.plusSeconds(jwtDetails.getExpires()).toDate();
|
||||
_logger.debug("expiration Time : {}" , expirationTime);
|
||||
String subject = getValueByUserAttr(userInfo,jwtDetails.getSubject());
|
||||
_logger.trace("jwt subject : {}" , subject);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class JwtAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
|
||||
Cookie cookie= new Cookie(jwtDetails.getJwtName(),adapter.serialize());
|
||||
|
||||
Integer maxAge = Integer.parseInt(jwtDetails.getExpires()) * 60;
|
||||
Integer maxAge = jwtDetails.getExpires();
|
||||
_logger.debug("Cookie Max Age : {} seconds." , maxAge);
|
||||
cookie.setMaxAge(maxAge);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TokenBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
|
||||
Cookie cookie= new Cookie(tokenBasedDetails.getCookieName(),adapter.serialize());
|
||||
|
||||
Integer maxAge=Integer.parseInt(tokenBasedDetails.getExpires()) * 60;
|
||||
Integer maxAge = tokenBasedDetails.getExpires();
|
||||
_logger.debug("Cookie Max Age : {} seconds.",maxAge);
|
||||
cookie.setMaxAge(maxAge);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.maxkey.authz.token.endpoint.adapter;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.entity.apps.AppsTokenBasedDetails;
|
||||
import org.maxkey.util.DateUtils;
|
||||
@@ -78,15 +79,14 @@ public class TokenBasedDefaultAdapter extends AbstractAuthorizeAdapter {
|
||||
* use UTC date time format
|
||||
* current date plus expires minute
|
||||
*/
|
||||
Integer expiresLong=Integer.parseInt(details.getExpires());
|
||||
Date currentDate=new Date();
|
||||
Date expiresDate=DateUtils.addMinutes(currentDate,expiresLong);
|
||||
String expiresString=DateUtils.toUtc(expiresDate);
|
||||
_logger.debug("UTC Local current date : "+DateUtils.toUtcLocal(currentDate));
|
||||
_logger.debug("UTC current Date : "+DateUtils.toUtc(currentDate));
|
||||
_logger.debug("UTC expires Date : "+DateUtils.toUtc(expiresDate));
|
||||
DateTime currentDateTime = DateTime.now();
|
||||
Date expirationTime = currentDateTime.plusSeconds(details.getExpires()).toDate();
|
||||
String expiresString = DateUtils.toUtc(expirationTime);
|
||||
_logger.debug("UTC Local current date : "+DateUtils.toUtcLocal(currentDateTime.toDate()));
|
||||
_logger.debug("UTC current Date : "+DateUtils.toUtc(currentDateTime));
|
||||
_logger.debug("UTC expires Date : "+DateUtils.toUtc(currentDateTime));
|
||||
|
||||
beanMap.put("at", DateUtils.toUtc(currentDate));
|
||||
beanMap.put("at", DateUtils.toUtc(currentDateTime));
|
||||
|
||||
beanMap.put("expires", expiresString);
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ $(function(){
|
||||
<th style="width:15%;"><@locale code="apps.cas.expires"/></th>
|
||||
<td style="width:35%;">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="3" required="" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="180" required="" />
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -83,7 +83,7 @@ $(function(){
|
||||
<td style="width:35%;">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="${model.expires}" required="30" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -78,8 +78,8 @@
|
||||
<th ><@locale code="apps.jwt.expires" /></th>
|
||||
<td >
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="1" required="" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="180" required="" />
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<td >
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="${model.expires!}" required="" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -83,8 +83,8 @@
|
||||
<th><@locale code="apps.tokenbased.expires" /></th>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="1" required="" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="180" required="" />
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="expires" name="expires" title="" value="${model.expires}" required="" />
|
||||
<span class="input-group-text">Minutes</span>
|
||||
<span class="input-group-text">Seconds</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user