Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
reg-app
Regapp
Commits
8fa2fc19
Commit
8fa2fc19
authored
Feb 18, 2021
by
michael.simon
Browse files
Add job to delete old login infos from database
parent
0498147f
Changes
5
Hide whitespace changes
Inline
Side-by-side
bwreg-jpa/src/main/java/edu/kit/scc/webreg/dao/UserLoginInfoDao.java
View file @
8fa2fc19
...
...
@@ -22,5 +22,7 @@ public interface UserLoginInfoDao extends BaseDao<UserLoginInfoEntity, Long> {
List
<
UserLoginInfoEntity
>
findByRegistry
(
Long
registryId
);
UserLoginInfoEntity
findLastByRegistryAndMethod
(
Long
registryId
,
UserLoginMethod
method
);
void
deleteLoginInfo
(
long
millis
);
}
bwreg-jpa/src/main/java/edu/kit/scc/webreg/dao/jpa/JpaUserLoginInfoDao.java
View file @
8fa2fc19
...
...
@@ -10,10 +10,12 @@
******************************************************************************/
package
edu.kit.scc.webreg.dao.jpa
;
import
java.util.Date
;
import
java.util.List
;
import
javax.enterprise.context.ApplicationScoped
;
import
javax.inject.Named
;
import
javax.persistence.Query
;
import
edu.kit.scc.webreg.dao.UserLoginInfoDao
;
import
edu.kit.scc.webreg.entity.UserLoginInfoEntity
;
...
...
@@ -55,6 +57,13 @@ public class JpaUserLoginInfoDao extends JpaBaseDao<UserLoginInfoEntity, Long> i
}
}
@Override
public
void
deleteLoginInfo
(
long
millis
)
{
Query
query
=
em
.
createQuery
(
"delete from UserLoginInfoEntity where loginDate <= :loginDate"
);
query
.
setParameter
(
"loginDate"
,
new
Date
(
System
.
currentTimeMillis
()
-
millis
));
query
.
executeUpdate
();
}
@Override
public
Class
<
UserLoginInfoEntity
>
getEntityClass
()
{
return
UserLoginInfoEntity
.
class
;
...
...
bwreg-service/src/main/java/edu/kit/scc/webreg/job/ClearExpiredLoginInfo.java
0 → 100644
View file @
8fa2fc19
/*******************************************************************************
* 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.UserLoginInfoService
;
public
class
ClearExpiredLoginInfo
extends
AbstractExecutableJob
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
public
void
execute
()
{
Logger
logger
=
LoggerFactory
.
getLogger
(
ClearExpiredLoginInfo
.
class
);
try
{
logger
.
debug
(
"Delete expired Login Infos"
);
long
purgeMillis
;
if
(!
getJobStore
().
containsKey
(
"purge_millis"
))
{
purgeMillis
=
7776000000L
;
// 90 days default
}
else
{
purgeMillis
=
Long
.
parseLong
(
getJobStore
().
get
(
"purge_millis"
));
}
InitialContext
ic
=
new
InitialContext
();
UserLoginInfoService
service
=
(
UserLoginInfoService
)
ic
.
lookup
(
"global/bwreg/bwreg-service/UserLoginInfoServiceImpl!edu.kit.scc.webreg.service.UserLoginInfoService"
);
service
.
deleteLoginInfo
(
purgeMillis
);
logger
.
debug
(
"Deletion done"
);
}
catch
(
NamingException
e
)
{
logger
.
warn
(
"Could not delete Login Infos: {}"
,
e
);
}
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/UserLoginInfoService.java
0 → 100644
View file @
8fa2fc19
/*******************************************************************************
* 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.UserLoginInfoEntity
;
public
interface
UserLoginInfoService
extends
BaseService
<
UserLoginInfoEntity
,
Long
>
{
void
deleteLoginInfo
(
long
millis
);
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/impl/UserLoginInfoServiceImpl.java
0 → 100644
View file @
8fa2fc19
package
edu.kit.scc.webreg.service.impl
;
import
javax.ejb.Stateless
;
import
javax.inject.Inject
;
import
org.slf4j.Logger
;
import
edu.kit.scc.webreg.dao.BaseDao
;
import
edu.kit.scc.webreg.dao.UserLoginInfoDao
;
import
edu.kit.scc.webreg.entity.UserLoginInfoEntity
;
import
edu.kit.scc.webreg.service.UserLoginInfoService
;
@Stateless
public
class
UserLoginInfoServiceImpl
extends
BaseServiceImpl
<
UserLoginInfoEntity
,
Long
>
implements
UserLoginInfoService
{
private
static
final
long
serialVersionUID
=
1L
;
@Inject
private
Logger
logger
;
@Inject
private
UserLoginInfoDao
dao
;
@Override
public
void
deleteLoginInfo
(
long
millis
)
{
Long
start
=
System
.
currentTimeMillis
();
dao
.
deleteLoginInfo
(
millis
);
logger
.
info
(
"Deleting old User Login Infos took {} ms"
,
(
System
.
currentTimeMillis
()
-
start
));
}
@Override
protected
BaseDao
<
UserLoginInfoEntity
,
Long
>
getDao
()
{
return
dao
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment