reorganized packages
This commit is contained in:
parent
87500802bf
commit
c5e9810fc0
|
@ -1,150 +1,139 @@
|
|||
package org.gcube.service.idm.rest;
|
||||
|
||||
import org.gcube.common.authorization.library.policies.Users;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.service.rest.ResponseBean;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
// @Path("2/users")
|
||||
// @ResourceGroup("Users APIs")
|
||||
// @ResourceLabel("Greetings APIs")
|
||||
// @RequestHeaders({
|
||||
// @RequestHeader(name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
||||
// @RequestHeader(name = "Authorization", description = "Bearer token, see <a
|
||||
// href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
||||
// })
|
||||
public class UsersRest {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Users.class);
|
||||
|
||||
/*
|
||||
* // @GET
|
||||
* // @Path("/get-usernames-by-role")
|
||||
* // @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json"
|
||||
* })
|
||||
* public Response getUsernamesByRole(
|
||||
*
|
||||
* @QueryParam("role-name") String roleName) {
|
||||
* Status status = Status.OK;
|
||||
* ResponseBean responseBean = new ResponseBean();
|
||||
*
|
||||
* List<String> usernames = new ArrayList<String>();
|
||||
* try {
|
||||
* String ctx = SecretManagerProvider.get().getContext();
|
||||
* KeycloakApiClient keycloackApiClient =
|
||||
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
|
||||
*
|
||||
* List<UserRepresentation> users = null; // searchByRole(keycloackApiClient,
|
||||
* roleName);
|
||||
* if (users != null) {
|
||||
* for (UserRepresentation user : users) {
|
||||
* usernames.add(user.getUsername());
|
||||
* }
|
||||
* }
|
||||
* responseBean.setResult(usernames);
|
||||
* responseBean.setSuccess(true);
|
||||
* } catch (Exception e) {
|
||||
* logger.error("Unable to retrieve user with the requested role", e);
|
||||
* responseBean.setMessage(e.getMessage());
|
||||
* status = Status.INTERNAL_SERVER_ERROR;
|
||||
* }
|
||||
*
|
||||
* return Response.status(status).entity(responseBean).build();
|
||||
*
|
||||
* }
|
||||
*
|
||||
* private static List<UserRepresentation> searchByRole(KeycloackApiClient
|
||||
* keycloackApiClient, String roleName) {
|
||||
* logger.info("Searching by role: {}", roleName);
|
||||
*
|
||||
* List<ClientRepresentation> clients =
|
||||
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
|
||||
* .clients().findByClientId(keycloackApiClient.clientIdContext);
|
||||
*
|
||||
* String id = "";
|
||||
* for (ClientRepresentation client : clients) {
|
||||
* logger.info("found client =" + client.getClientId());
|
||||
* logger.info("found client id=" + client.getId());
|
||||
* id = client.getId();
|
||||
* }
|
||||
*
|
||||
* List<UserRepresentation> users =
|
||||
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
|
||||
* .clients()
|
||||
* .get(id).roles().get(roleName)
|
||||
* .getUserMembers(0, 100000);
|
||||
* return users;
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-profile}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public String getCurrentProfile() {
|
||||
* // SMARTGEARS Specializza il tracciamento della chiamata su Accounting
|
||||
* InnerMethodName.instance.set("getCurrentProfile");
|
||||
* Owner owner = SecretManagerProvider.get().getOwner();
|
||||
*
|
||||
* ApplicationContext appContext = ContextProvider.get();
|
||||
* SimpleCredentials credentials = ((DefaultAuthorizationProvider)
|
||||
* appContext.container().authorizationProvider())
|
||||
* .getCredentials();
|
||||
*
|
||||
* String ctx = SecretManagerProvider.get().getContext();
|
||||
* KeycloackApiClient keycloackApiClient =
|
||||
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
|
||||
* return null;
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-email}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public String getCurrentEmail() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-fullname}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public String getCurrentFullname() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-all-usernames}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public String getAllUsernames() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-all-fullnames-and-usernames}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public String getAllUsernamesFullnames() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{user-exists}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public boolean checkUserExists() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*
|
||||
* @GET
|
||||
*
|
||||
* @Path("/{get-oauth-profile}")
|
||||
*
|
||||
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
* public boolean getCurrentOAuthProfile() {
|
||||
* throw new NotImplementedYetException();
|
||||
* }
|
||||
*/
|
||||
// @GET
|
||||
// @Path("/get-usernames-by-role")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public Response getUsernamesByRole(
|
||||
|
||||
// @QueryParam("role-name") String roleName) {
|
||||
// Status status = Status.OK;
|
||||
// ResponseBean responseBean = new ResponseBean();
|
||||
|
||||
// List<String> usernames = new ArrayList<String>();
|
||||
// try {
|
||||
// String ctx = SecretManagerProvider.get().getContext();
|
||||
// KeycloakApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
|
||||
|
||||
// List<UserRepresentation> users = null; // searchByRole(keycloackApiClient, roleName);
|
||||
// if (users != null) {
|
||||
// for (UserRepresentation user : users) {
|
||||
// usernames.add(user.getUsername());
|
||||
// }
|
||||
// }
|
||||
// responseBean.setResult(usernames);
|
||||
// responseBean.setSuccess(true);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("Unable to retrieve user with the requested role", e);
|
||||
// responseBean.setMessage(e.getMessage());
|
||||
// status = Status.INTERNAL_SERVER_ERROR;
|
||||
// }
|
||||
|
||||
// return Response.status(status).entity(responseBean).build();
|
||||
|
||||
// }
|
||||
|
||||
// private static List<UserRepresentation> searchByRole(KeycloackApiClient keycloackApiClient, String roleName) {
|
||||
// logger.info("Searching by role: {}", roleName);
|
||||
|
||||
// List<ClientRepresentation> clients = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
|
||||
// .clients().findByClientId(keycloackApiClient.clientIdContext);
|
||||
|
||||
// String id = "";
|
||||
// for (ClientRepresentation client : clients) {
|
||||
// logger.info("found client =" + client.getClientId());
|
||||
// logger.info("found client id=" + client.getId());
|
||||
// id = client.getId();
|
||||
// }
|
||||
|
||||
// List<UserRepresentation> users = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
|
||||
// .clients()
|
||||
// .get(id).roles().get(roleName)
|
||||
// .getUserMembers(0, 100000);
|
||||
// return users;
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-profile}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public String getCurrentProfile() {
|
||||
// // SMARTGEARS Specializza il tracciamento della chiamata su Accounting
|
||||
// InnerMethodName.instance.set("getCurrentProfile");
|
||||
// Owner owner = SecretManagerProvider.get().getOwner();
|
||||
|
||||
// ApplicationContext appContext = ContextProvider.get();
|
||||
// SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().authorizationProvider())
|
||||
// .getCredentials();
|
||||
|
||||
// String ctx = SecretManagerProvider.get().getContext();
|
||||
// KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-email}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public String getCurrentEmail() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-fullname}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public String getCurrentFullname() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-all-usernames}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public String getAllUsernames() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-all-fullnames-and-usernames}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public String getAllUsernamesFullnames() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{user-exists}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public boolean checkUserExists() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
|
||||
// @GET
|
||||
// @Path("/{get-oauth-profile}")
|
||||
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
|
||||
// public boolean getCurrentOAuthProfile() {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.service.idm.test.services;
|
||||
package org.gcube.service.idm.rest.test;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
@ -8,7 +8,10 @@ import javax.ws.rs.core.MediaType;
|
|||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.service.idm.rest.TestRest;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Lucio Le (ISTI - CNR)
|
||||
|
@ -18,6 +21,8 @@ import org.gcube.smartgears.utils.InnerMethodName;
|
|||
@Path("auth")
|
||||
public class AuthenticatedService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AuthenticatedService.class);
|
||||
|
||||
private static final String ALLOWED_ROLE = "myRole";
|
||||
private static final String ALLOWED_ROLE_ORG = "OrganizationMember";
|
||||
private static final String ALLOWED_ROLE_MEMBER = "Member";
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.service.idm.test.services;
|
||||
package org.gcube.service.idm.rest.test;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -69,7 +69,12 @@ public class HelloService {
|
|||
Owner owner = secret.getOwner();
|
||||
data.put("owner", owner);
|
||||
|
||||
ContainerContext container = ContextProvider.get().container();
|
||||
logger.info("details for {} - {} {} - {}", owner.getId(), owner.getFirstName(), owner.getLastName(), owner.getEmail());
|
||||
|
||||
ApplicationContext contextProvider = ContextProvider.get();
|
||||
ContainerContext container = contextProvider.container();
|
||||
|
||||
//ContainerContext container = ContextProvider.get().container();
|
||||
data.put("container", container);
|
||||
|
||||
ObjectMapper objectMapper = ContextSerializator.getSerializer();
|
Loading…
Reference in New Issue