added method to check user existence
This commit is contained in:
parent
56e01e91f8
commit
1e916b21b6
|
@ -11,6 +11,8 @@ method add and remove admin on a VREFolder enabled also for admin role
|
|||
|
||||
fixed bug on unsharing folder on user removal
|
||||
|
||||
added method exist user
|
||||
|
||||
## [v1.2.2] - [2020-06-20]
|
||||
|
||||
method for description update added
|
||||
|
|
|
@ -380,6 +380,9 @@ public class GroupManager {
|
|||
Group group = (Group)usrManager.getAuthorizable(groupId);
|
||||
User user = (User)usrManager.getAuthorizable(userId);
|
||||
|
||||
if (user==null)
|
||||
throw new InvalidCallParameters("user "+userId+" not exists");
|
||||
|
||||
if (group.isMember(user))
|
||||
throw new InvalidCallParameters("user "+userId+" is already member of group "+groupId);
|
||||
|
||||
|
|
|
@ -32,10 +32,11 @@ import org.apache.jackrabbit.api.security.user.QueryBuilder;
|
|||
import org.apache.jackrabbit.api.security.user.User;
|
||||
import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
|
||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
import org.gcube.common.gxrest.response.outbound.ErrorCode;
|
||||
import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
|
||||
import org.gcube.common.storagehub.model.Excludes;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.types.NodeProperty;
|
||||
|
@ -104,6 +105,37 @@ public class UserManager {
|
|||
return users;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{user}")
|
||||
public String getUser(@PathParam("user") String user){
|
||||
|
||||
InnerMethodName.instance.set("getUser");
|
||||
|
||||
JackrabbitSession session = null;
|
||||
try {
|
||||
session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||
|
||||
org.apache.jackrabbit.api.security.user.UserManager usrManager = session.getUserManager();
|
||||
Authorizable authorizable = usrManager.getAuthorizable(user);
|
||||
|
||||
if (authorizable != null && !authorizable.isGroup())
|
||||
return authorizable.getPrincipal().getName();
|
||||
|
||||
log.debug("user {} not found", user);
|
||||
|
||||
}catch(Exception e) {
|
||||
log.error("jcr error getting user", e);
|
||||
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
||||
} finally {
|
||||
if (session!=null)
|
||||
session.logout();
|
||||
}
|
||||
|
||||
GXOutboundErrorResponse.throwException(new IdNotFoundException(user));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("")
|
||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
|
|
Loading…
Reference in New Issue