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
a6cefa0c
Commit
a6cefa0c
authored
Mar 03, 2021
by
michael.simon
Browse files
Add attribute query endpoints
Add endpoints with user lookup by generic and attribute store
parent
a1a30cd1
Changes
7
Hide whitespace changes
Inline
Side-by-side
bwreg-jpa/src/main/java/edu/kit/scc/webreg/dao/UserDao.java
View file @
a6cefa0c
...
...
@@ -34,4 +34,6 @@ public interface UserDao extends BaseDao<UserEntity, Long> {
List
<
UserEntity
>
findMissingIdentity
();
List
<
UserEntity
>
findByIdentity
(
IdentityEntity
identity
);
List
<
UserEntity
>
findScheduledUsers
(
Integer
limit
);
List
<
UserEntity
>
findByAttribute
(
String
key
,
String
value
);
List
<
UserEntity
>
findByGeneric
(
String
key
,
String
value
);
}
bwreg-jpa/src/main/java/edu/kit/scc/webreg/dao/jpa/JpaUserDao.java
View file @
a6cefa0c
...
...
@@ -20,9 +20,11 @@ import javax.persistence.NoResultException;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.JoinType
;
import
javax.persistence.criteria.MapJoin
;
import
javax.persistence.criteria.Root
;
import
edu.kit.scc.webreg.dao.UserDao
;
import
edu.kit.scc.webreg.entity.ExternalUserEntity
;
import
edu.kit.scc.webreg.entity.GroupEntity
;
import
edu.kit.scc.webreg.entity.UserEntity
;
import
edu.kit.scc.webreg.entity.UserEntity_
;
...
...
@@ -74,6 +76,37 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
.
setParameter
(
"key"
,
key
).
setMaxResults
(
limit
).
getResultList
();
}
@Override
public
List
<
UserEntity
>
findByAttribute
(
String
key
,
String
value
)
{
CriteriaBuilder
builder
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
UserEntity
>
criteria
=
builder
.
createQuery
(
UserEntity
.
class
);
Root
<
UserEntity
>
root
=
criteria
.
from
(
UserEntity
.
class
);
criteria
.
select
(
root
);
MapJoin
<
ExternalUserEntity
,
String
,
String
>
mapJoin
=
root
.
joinMap
(
"attributeStore"
);
criteria
.
where
(
builder
.
and
(
builder
.
equal
(
mapJoin
.
key
(),
key
),
builder
.
equal
(
mapJoin
.
value
(),
value
))
);
return
em
.
createQuery
(
criteria
).
getResultList
();
}
@Override
public
List
<
UserEntity
>
findByGeneric
(
String
key
,
String
value
)
{
CriteriaBuilder
builder
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
UserEntity
>
criteria
=
builder
.
createQuery
(
UserEntity
.
class
);
Root
<
UserEntity
>
root
=
criteria
.
from
(
UserEntity
.
class
);
criteria
.
select
(
root
);
MapJoin
<
ExternalUserEntity
,
String
,
String
>
mapJoin
=
root
.
joinMap
(
"genericStore"
);
criteria
.
where
(
builder
.
and
(
builder
.
equal
(
mapJoin
.
key
(),
key
),
builder
.
equal
(
mapJoin
.
value
()
,
value
))
);
return
em
.
createQuery
(
criteria
).
getResultList
();
}
@Override
@SuppressWarnings
({
"unchecked"
})
public
List
<
UserEntity
>
findLegacyUsers
()
{
...
...
bwreg-service/src/main/java/edu/kit/scc/webreg/exc/UserNotUniqueException.java
0 → 100644
View file @
a6cefa0c
/*******************************************************************************
* 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.exc
;
public
class
UserNotUniqueException
extends
RestInterfaceException
{
private
static
final
long
serialVersionUID
=
1L
;
public
UserNotUniqueException
(
String
message
)
{
super
(
message
);
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/UserUpdateService.java
View file @
a6cefa0c
...
...
@@ -22,5 +22,11 @@ public interface UserUpdateService {
Map
<
String
,
String
>
updateUser
(
Long
uidNumber
,
String
serviceShortName
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
;
Map
<
String
,
String
>
updateUserByGenericStore
(
String
key
,
String
value
,
String
serviceShortName
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
;
Map
<
String
,
String
>
updateUserByAttributeStore
(
String
key
,
String
value
,
String
serviceShortName
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
;
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/impl/UserUpdateServiceImpl.java
View file @
a6cefa0c
...
...
@@ -32,6 +32,7 @@ import edu.kit.scc.webreg.exc.NoRegistryFoundException;
import
edu.kit.scc.webreg.exc.NoServiceFoundException
;
import
edu.kit.scc.webreg.exc.NoUserFoundException
;
import
edu.kit.scc.webreg.exc.RestInterfaceException
;
import
edu.kit.scc.webreg.exc.UserNotUniqueException
;
import
edu.kit.scc.webreg.exc.UserUpdateException
;
import
edu.kit.scc.webreg.exc.UserUpdateFailedException
;
import
edu.kit.scc.webreg.service.UserUpdateService
;
...
...
@@ -163,6 +164,58 @@ public class UserUpdateServiceImpl implements UserUpdateService, Serializable {
}
}
@Override
public
Map
<
String
,
String
>
updateUserByGenericStore
(
String
key
,
String
value
,
String
serviceShortName
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
{
List
<
UserEntity
>
userList
=
userDao
.
findByGeneric
(
key
,
value
);
if
(
userList
.
size
()
>
1
)
{
throw
new
UserNotUniqueException
(
"Found more than one user for key,value"
);
}
else
if
(
userList
.
size
()
==
0
)
{
throw
new
NoUserFoundException
(
"No user found for key,value"
);
}
UserEntity
user
=
userList
.
get
(
0
);
ServiceEntity
service
=
findService
(
serviceShortName
);
if
(
service
==
null
)
throw
new
NoServiceFoundException
(
"no such service"
);
RegistryEntity
registry
=
findRegistry
(
user
,
service
);
if
(
registry
==
null
)
throw
new
NoRegistryFoundException
(
"user not registered for service"
);
return
update
(
user
,
service
,
registry
,
localHostName
,
executor
);
}
@Override
public
Map
<
String
,
String
>
updateUserByAttributeStore
(
String
key
,
String
value
,
String
serviceShortName
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
{
List
<
UserEntity
>
userList
=
userDao
.
findByAttribute
(
key
,
value
);
if
(
userList
.
size
()
>
1
)
{
throw
new
UserNotUniqueException
(
"Found more than one user for key,value"
);
}
else
if
(
userList
.
size
()
==
0
)
{
throw
new
NoUserFoundException
(
"No user found for key,value"
);
}
UserEntity
user
=
userList
.
get
(
0
);
ServiceEntity
service
=
findService
(
serviceShortName
);
if
(
service
==
null
)
throw
new
NoServiceFoundException
(
"no such service"
);
RegistryEntity
registry
=
findRegistry
(
user
,
service
);
if
(
registry
==
null
)
throw
new
NoRegistryFoundException
(
"user not registered for service"
);
return
update
(
user
,
service
,
registry
,
localHostName
,
executor
);
}
@Override
public
Map
<
String
,
String
>
updateUser
(
Long
regId
,
String
localHostName
,
String
executor
)
throws
IOException
,
RestInterfaceException
{
...
...
bwreg-webapp/src/main/java/edu/kit/scc/webreg/rest/AttributeQueryController.java
View file @
a6cefa0c
...
...
@@ -19,7 +19,10 @@ import java.util.ResourceBundle;
import
javax.inject.Inject
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.FormParam
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
...
...
@@ -80,6 +83,44 @@ public class AttributeQueryController {
return
userUpdateService
.
updateUser
(
regId
,
request
.
getServerName
(),
"rest-/attrq/regid/"
+
regId
);
}
@GET
@Path
(
"/generic/{service}/{key}/{value}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Map
<
String
,
String
>
attributeQueryByGeneric
(
@PathParam
(
"key"
)
String
key
,
@PathParam
(
"value"
)
String
value
,
@PathParam
(
"service"
)
String
serviceShortName
,
@Context
HttpServletRequest
request
)
throws
IOException
,
ServletException
,
RestInterfaceException
{
return
userUpdateService
.
updateUserByGenericStore
(
key
,
value
,
serviceShortName
,
request
.
getServerName
(),
"rest-/attrq/generic/"
+
serviceShortName
+
"/"
+
key
+
"/"
+
value
);
}
@POST
@Path
(
"/generic-post/{service}"
)
@Consumes
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Map
<
String
,
String
>
attributeQueryByGenericPost
(
@FormParam
(
"key"
)
String
key
,
@FormParam
(
"value"
)
String
value
,
@PathParam
(
"service"
)
String
serviceShortName
,
@Context
HttpServletRequest
request
)
throws
IOException
,
ServletException
,
RestInterfaceException
{
return
userUpdateService
.
updateUserByGenericStore
(
key
,
value
,
serviceShortName
,
request
.
getServerName
(),
"rest-/attrq/generic/"
+
serviceShortName
+
"/"
+
key
+
"/"
+
value
);
}
@GET
@Path
(
"/attribute/{service}/{key}/{value}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Map
<
String
,
String
>
attributeQueryByAttribute
(
@PathParam
(
"key"
)
String
key
,
@PathParam
(
"value"
)
String
value
,
@PathParam
(
"service"
)
String
serviceShortName
,
@Context
HttpServletRequest
request
)
throws
IOException
,
ServletException
,
RestInterfaceException
{
return
userUpdateService
.
updateUserByAttributeStore
(
key
,
value
,
serviceShortName
,
request
.
getServerName
(),
"rest-/attrq/generic/"
+
serviceShortName
+
"/"
+
key
+
"/"
+
value
);
}
@POST
@Path
(
"/attribute-post/{service}"
)
@Consumes
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Map
<
String
,
String
>
attributeQueryByAttributePost
(
@FormParam
(
"key"
)
String
key
,
@FormParam
(
"value"
)
String
value
,
@PathParam
(
"service"
)
String
serviceShortName
,
@Context
HttpServletRequest
request
)
throws
IOException
,
ServletException
,
RestInterfaceException
{
return
userUpdateService
.
updateUserByAttributeStore
(
key
,
value
,
serviceShortName
,
request
.
getServerName
(),
"rest-/attrq/generic/"
+
serviceShortName
+
"/"
+
key
+
"/"
+
value
);
}
@GET
@Path
(
"/eppn-xml/{service}/{eppn}"
)
@Produces
(
MediaType
.
APPLICATION_XML
)
...
...
bwreg-webapp/src/main/java/edu/kit/scc/webreg/rest/exc/UserNotUniqueExceptionMapper.java
0 → 100644
View file @
a6cefa0c
/*******************************************************************************
* 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.rest.exc
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.ext.ExceptionMapper
;
import
javax.ws.rs.ext.Provider
;
import
edu.kit.scc.webreg.exc.UserNotUniqueException
;
@Provider
public
class
UserNotUniqueExceptionMapper
implements
ExceptionMapper
<
UserNotUniqueException
>
{
@Override
public
Response
toResponse
(
UserNotUniqueException
ex
)
{
return
Response
.
status
(
412
).
entity
(
ex
.
getMessage
())
.
type
(
MediaType
.
TEXT_PLAIN
).
build
();
}
}
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