Commit be8e971a authored by michael.simon's avatar michael.simon
Browse files

add job to delete expired authnrequests

parent 69e060f5
...@@ -14,4 +14,6 @@ import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity; ...@@ -14,4 +14,6 @@ import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity;
public interface SamlAuthnRequestDao extends BaseDao<SamlAuthnRequestEntity, Long> { public interface SamlAuthnRequestDao extends BaseDao<SamlAuthnRequestEntity, Long> {
void deleteInvalid();
} }
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
package edu.kit.scc.webreg.dao.jpa; package edu.kit.scc.webreg.dao.jpa;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named; import javax.inject.Named;
import javax.persistence.Query;
import edu.kit.scc.webreg.dao.SamlAuthnRequestDao; import edu.kit.scc.webreg.dao.SamlAuthnRequestDao;
import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity; import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity;
...@@ -24,6 +26,13 @@ public class JpaSamlAuthnRequestDao extends JpaBaseDao<SamlAuthnRequestEntity, L ...@@ -24,6 +26,13 @@ public class JpaSamlAuthnRequestDao extends JpaBaseDao<SamlAuthnRequestEntity, L
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override
public void deleteInvalid() {
Query query = em.createQuery("delete from SamlAuthnRequestEntity where validUntil <= :validUntil");
query.setParameter("validUntil", new Date());
query.executeUpdate();
}
@Override @Override
public Class<SamlAuthnRequestEntity> getEntityClass() { public Class<SamlAuthnRequestEntity> getEntityClass() {
return SamlAuthnRequestEntity.class; return SamlAuthnRequestEntity.class;
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.job;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.service.SamlAuthnRequestService;
public class ClearInvalidAuthnRequests extends AbstractExecutableJob {
private static final long serialVersionUID = 1L;
@Override
public void execute() {
Logger logger = LoggerFactory.getLogger(ClearInvalidAuthnRequests.class);
try {
logger.debug("Delete expired AuthnRequests");
InitialContext ic = new InitialContext();
SamlAuthnRequestService service = (SamlAuthnRequestService) ic.lookup("global/bwreg/bwreg-service/SamlAuthnRequestServiceImpl!edu.kit.scc.webreg.service.SamlAuthnRequest");
service.deleteInvalid();
logger.debug("Deletion done");
} catch (NamingException e) {
logger.warn("Could not delete expired AuthnRequests: {}", e);
}
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service;
import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity;
public interface SamlAuthnRequestService extends BaseService<SamlAuthnRequestEntity, Long> {
void deleteInvalid();
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.impl;
import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.SamlAuthnRequestDao;
import edu.kit.scc.webreg.entity.SamlAuthnRequestEntity;
import edu.kit.scc.webreg.service.SamlAuthnRequestService;
@Stateless
public class SamlAuthnRequestServiceImpl extends BaseServiceImpl<SamlAuthnRequestEntity, Long> implements SamlAuthnRequestService {
private static final long serialVersionUID = 1L;
@Inject
private SamlAuthnRequestDao dao;
@Override
public void deleteInvalid() {
dao.deleteInvalid();
}
@Override
protected BaseDao<SamlAuthnRequestEntity, Long> getDao() {
return dao;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment