Repository: openmeetings Updated Branches: refs/heads/3.3.x 2c0468f35 -> ca5595649
http://git-wip-us.apache.org/repos/asf/openmeetings/blob/ca559564/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java ---------------------------------------------------------------------- diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java index 858a745..2fef310 100644 --- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java +++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java @@ -47,6 +47,7 @@ import org.apache.openmeetings.IApplication; import org.apache.openmeetings.core.util.StrongPasswordValidator; import org.apache.openmeetings.db.dao.basic.ConfigurationDao; import org.apache.openmeetings.db.dao.server.SOAPLoginDao; +import org.apache.openmeetings.db.dao.user.IUserManager; import org.apache.openmeetings.db.dao.user.UserDao; import org.apache.openmeetings.db.dto.basic.ServiceResult; import org.apache.openmeetings.db.dto.basic.ServiceResult.Type; @@ -62,7 +63,6 @@ import org.apache.openmeetings.db.util.AuthLevelUtil; import org.apache.openmeetings.service.user.UserManager; import org.apache.openmeetings.util.OmException; import org.apache.openmeetings.util.OpenmeetingsVariables; -import org.apache.openmeetings.webservice.cluster.UserService; import org.apache.openmeetings.webservice.error.ServiceException; import org.apache.wicket.Application; import org.apache.wicket.util.string.Strings; @@ -85,13 +85,15 @@ import org.slf4j.Logger; @Features(features = "org.apache.cxf.feature.LoggingFeature") @Produces({MediaType.APPLICATION_JSON}) @Path("/user") -public class UserWebService extends BaseWebService implements UserService { +public class UserWebService extends BaseWebService { private static final Logger log = Red5LoggerFactory.getLogger(UserWebService.class, webAppRootKey); - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#login(java.lang.String, java.lang.String) + /** + * @param user - login or email of Openmeetings user with admin or SOAP-rights + * @param pass - password + * + * @return - {@link ServiceResult} with error code or SID and userId */ - @Override @WebMethod @GET @Path("/login") @@ -114,10 +116,15 @@ public class UserWebService extends BaseWebService implements UserService { } } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#get(java.lang.String) + /** + * Lists all users in the system! + * + * @param sid + * The SID from getSession + * + * @return - list of users + * @throws ServiceException */ - @Override @WebMethod @GET @Path("/") @@ -134,10 +141,20 @@ public class UserWebService extends BaseWebService implements UserService { } } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#add(java.lang.String, org.apache.openmeetings.db.dto.user.UserDTO, java.lang.Boolean) + /** + * Adds a new User like through the Frontend, but also does activates the + * Account To do SSO see the methods to create a hash and use those ones! + * + * @param sid + * The SID from getSession + * @param user + * user object + * @param confirm + * whatever or not to send email, leave empty for auto-send + * + * @return - id of the user added or error code + * @throws ServiceException */ - @Override @WebMethod @POST @Path("/") @@ -217,10 +234,18 @@ public class UserWebService extends BaseWebService implements UserService { //FIXME no update - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#delete(java.lang.String, long) + /** + * + * Delete a certain user by its id + * + * @param sid + * The SID from getSession + * @param id + * the openmeetings user id + * + * @return - id of the user deleted, error code otherwise + * @throws ServiceException */ - @Override @WebMethod @DELETE @Path("/{id}") @@ -241,10 +266,20 @@ public class UserWebService extends BaseWebService implements UserService { } } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#deleteExternal(java.lang.String, java.lang.String, java.lang.String) + /** + * + * Delete a certain user by its external user id + * + * @param sid + * The SID from getSession + * @param externalId + * externalUserId + * @param externalType + * externalUserId + * + * @return - id of user deleted, or error code + * @throws ServiceException */ - @Override @DELETE @Path("/{externaltype}/{externalid}") public ServiceResult deleteExternal( @@ -272,10 +307,21 @@ public class UserWebService extends BaseWebService implements UserService { } } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#getRoomHash(java.lang.String, org.apache.openmeetings.db.dto.user.ExternalUserDTO, org.apache.openmeetings.db.dto.room.RoomOptionsDTO) + /** + * Description: sets the SessionObject for a certain SID, after setting this + * Session-Object you can use the SID + a RoomId to enter any Room. ... + * Session-Hashs are deleted 15 minutes after the creation if not used. + * + * @param sid + * The SID from getSession + * @param user + * user details to set + * @param options + * room options to set + * + * @return - secure hash or error code + * @throws ServiceException */ - @Override @WebMethod @POST @Path("/hash") @@ -325,17 +371,21 @@ public class UserWebService extends BaseWebService implements UserService { return new ServiceResult(-1L, "Unknown error", Type.ERROR); } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#kick(java.lang.String, java.lang.String) + /** + * Kick a user by its public SID + * + * @param sid + * The SID from getSession + * @param uid the uid of the client + * @return - <code>true</code> if user was kicked */ - @Override @WebMethod @POST - @Path("/kick/{publicsid}") - public ServiceResult kick(@WebParam(name="sid") @QueryParam("sid") String sid, @WebParam(name="publicsid") @PathParam("publicsid") String publicSID) throws ServiceException { + @Path("/kick/{uid}") + public ServiceResult kick(@WebParam(name="sid") @QueryParam("sid") String sid, @WebParam(name="uid") @PathParam("uid") String uid) throws ServiceException { try { if (AuthLevelUtil.hasWebServiceLevel(getRights(sid))) { - Boolean success = getBean(UserManager.class).kickUserByPublicSID(sid, publicSID); + Boolean success = getBean(IUserManager.class).kickClient(sid, uid); return new ServiceResult(Boolean.TRUE.equals(success) ? 1L : 0L, Boolean.TRUE.equals(success) ? "deleted" : "not deleted", Type.SUCCESS); } else { @@ -347,10 +397,14 @@ public class UserWebService extends BaseWebService implements UserService { } } - /* (non-Javadoc) - * @see org.apache.openmeetings.webservice.cluster.UserService#count(java.lang.String, java.lang.Long) + /** + * Returns the count of users currently in the Room with given id + * No admin rights are necessary for this call + * + * @param sid The SID from UserService.getSession + * @param roomId id of the room to get users + * @return number of users as int */ - @Override @WebMethod @GET @Path("/count/{roomid}") http://git-wip-us.apache.org/repos/asf/openmeetings/blob/ca559564/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/RestClient.java ---------------------------------------------------------------------- diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/RestClient.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/RestClient.java deleted file mode 100644 index 856beea..0000000 --- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/RestClient.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.webservice.cluster; - -import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; -import static org.apache.openmeetings.webservice.Constants.TNS; -import static org.apache.openmeetings.webservice.Constants.USER_SERVICE_NAME; -import static org.apache.openmeetings.webservice.Constants.USER_SERVICE_PORT_NAME; - -import java.net.URL; - -import javax.xml.namespace.QName; -import javax.xml.ws.Service; - -import org.apache.openmeetings.db.dto.basic.ServiceResult; -import org.apache.openmeetings.db.entity.server.Server; -import org.red5.logging.Red5LoggerFactory; -import org.slf4j.Logger; - -/** - * - * Performs call to the WebService Gateway to load the server load from the - * slave's of the cluster - * - * @author sebawagner - * - */ -public class RestClient { - private static final Logger log = Red5LoggerFactory.getLogger(RestClient.class, webAppRootKey); - private final static QName USER_SERVICE_QNAME = new QName(TNS, USER_SERVICE_NAME); - private final static QName USER_SERVICE_PORT_QNAME = new QName(TNS, USER_SERVICE_PORT_NAME); - - private enum Action { - //kick the user from the server - KICK_USER, - } - - private final String host; - private final int port; - private final String protocol; - private final String webapp; - private final String user; - private final String pass; - - private boolean loginSuccess = false; - private String sessionId; - - private String publicSID; - - private String getUserServiceWsdl() { - return String.format("%s://%s:%s/%s/services/UserService?wsdl", protocol, host, port, webapp); - } - - /** - * The observerInstance will be notified whenever a ping was completed - * - * @param observerInstance - * @param host - * @param port - * @param protocol - * @param webapp - * @param user - * @param pass - */ - public RestClient(Server server) { - this.host = server.getAddress(); - this.port = server.getPort(); - this.protocol = server.getProtocol(); - this.webapp = server.getWebapp(); - this.user = server.getUser(); - this.pass = server.getPass(); - } - - /** - * Main method to perform tests - * - * @param strings - */ - public static void main(String... strings) { - RestClient rClient = new RestClient("127.0.0.1", 5080, "http", "openmeetings", "admin", "12345"); - try { - rClient.loginUser(Action.KICK_USER); - } catch (Exception e) { - log.error("Error", e); - } - } - - /** - * for simple testing this method provides a version of the constructor - * without need for a server entity.<br/> - * <br/> - * There is no spring or JPA enhanced class in use here. This Object is - * stored in session/memory - * - * @param host - * @param port - * @param protocol - * @param webapp - * @param user - * @param pass - */ - private RestClient(String host, int port, String protocol, String webapp, String user, String pass) { - this.host = host; - this.port = port; - this.protocol = protocol; - this.webapp = webapp; - this.user = user; - this.pass = pass; - } - - /** - * compare if the details here and the one stored are still the same - * - * @param server2 - * @return - */ - public boolean hasServerDetailsChanged(Server server2) { - return !host.equals(server2.getAddress()) - || port != server2.getPort() - || !user.equals(server2.getUser()) - || !pass.equals(server2.getPass()) - || !webapp.equals(server2.getWebapp()) - || !protocol.equals(server2.getProtocol()); - } - - private UserService getUserClient() throws Exception { - URL wsdlURL = new URL(getUserServiceWsdl()); - Service service = Service.create(wsdlURL, USER_SERVICE_QNAME); - return service.getPort(USER_SERVICE_PORT_QNAME, UserService.class); - } - - /** - * Login the user via REST - * - * @throws Exception - */ - public void loginUser(Action action) throws Exception { - UserService client = getUserClient(); - - ServiceResult result = client.login(user, pass); - - loginSuccess = result.getCode() > 0; - - switch (action) { - case KICK_USER: - kickUserInternl(); - break; - default: - throw new Exception("No action defined"); - } - } - - /** - * sets the publicSID and removes a user from a slave host by calling a REST service - * - * @param publicSID - */ - public void kickUser(String publicSID) { - this.publicSID = publicSID; - kickUserInternl(); - } - - private void kickUserInternl() { - try { - if (!loginSuccess) { - loginUser(Action.KICK_USER); - } - - UserService client = getUserClient(); - ServiceResult result = client.kick(sessionId, publicSID); - - if (result.getCode() == 0) { - throw new Exception("Could not delete user from slave host"); - } - - } catch (Exception err) { - log.error("[kickUser failed]", err); - } - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/ca559564/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/SlaveHTTPConnectionManager.java ---------------------------------------------------------------------- diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/SlaveHTTPConnectionManager.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/SlaveHTTPConnectionManager.java deleted file mode 100644 index 1f83615..0000000 --- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/SlaveHTTPConnectionManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.webservice.cluster; - -import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.openmeetings.core.remote.ISlaveHTTPConnectionManager; -import org.apache.openmeetings.db.entity.server.Server; -import org.red5.logging.Red5LoggerFactory; -import org.slf4j.Logger; - -/** - * Manages connections to the other nodes of the cluster. - * - * Use-case: When you kick a user via the admin-panel, it is probably on anther server. - * So you need to perform a REST call to the node and let that node do the actual disconnect. - * - * @author sebawagner - * - */ -public class SlaveHTTPConnectionManager implements ISlaveHTTPConnectionManager { - private static Logger log = Red5LoggerFactory.getLogger(SlaveHTTPConnectionManager.class, webAppRootKey); - - /** - * We store the list of RestClients in the memory, so that we can simply - * call ping to get the load, without the need to get a new session Hash and - * to login again. <br/> - * There can be only one RestClient per server, so we use the primary key of - * the server to store the RestClient. - */ - private static Map<Long, RestClient> restClientsSessionStore = new ConcurrentHashMap<>(); - - /** - * Synchronized, cause nobody should manipulate the object while another - * process requests it, the scheduler could run several times and request - * the same object, add or remove it.<br/> - * If there is no object yet, create one. - * - * @param server - */ - private static RestClient getRestClient(Server server) { - RestClient restClient = restClientsSessionStore.get(server.getId()); - - // check if any values of the server have been changed, - // if yes, we need a new RestClient to make sure it will re-login to the - // changed server details - if (restClient != null && restClient.hasServerDetailsChanged(server)) { - log.debug("Server details changed, get new rest client"); - restClient = null; - } - - if (restClient == null) { - restClient = new RestClient(server); - restClientsSessionStore.put(server.getId(), restClient); - } - return restClient; - } - - /** - * Gets the current {@link RestClient} from the session store and then - * performs a kickUser on that. It is not possible that there is no - * {@link RestClient}, because if you want to kick a user from a slave, the - * master <i>must</i> already have loaded the sessions from the slave, so - * there logically <i>must</i> by a {@link RestClient} available that has an - * open connection to that slave / {@link Server} - * - * @param serverId - * @param publicSID - */ - @Override - public void kickSlaveUser(Server server, String publicSID) throws Exception { - RestClient rClient = getRestClient(server); - - if (rClient == null) { - throw new Exception("No RestClient found for server " + server); - } - - rClient.kickUser(publicSID); - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/ca559564/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/UserService.java ---------------------------------------------------------------------- diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/UserService.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/UserService.java deleted file mode 100644 index 6ccba83..0000000 --- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/cluster/UserService.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.webservice.cluster; - -import static org.apache.openmeetings.webservice.Constants.TNS; -import static org.apache.openmeetings.webservice.Constants.USER_SERVICE_NAME; -import static org.apache.openmeetings.webservice.Constants.USER_SERVICE_PORT_NAME; - -import java.util.List; - -import javax.jws.WebParam; -import javax.jws.WebService; -import javax.ws.rs.FormParam; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; - -import org.apache.openmeetings.db.dto.basic.ServiceResult; -import org.apache.openmeetings.db.dto.room.RoomOptionsDTO; -import org.apache.openmeetings.db.dto.user.ExternalUserDTO; -import org.apache.openmeetings.db.dto.user.UserDTO; -import org.apache.openmeetings.webservice.error.ServiceException; - -/** - * This interface is required for RestClient - */ -@WebService(serviceName = USER_SERVICE_NAME, targetNamespace = TNS, portName = USER_SERVICE_PORT_NAME) -public interface UserService { - - /** - * @param user - login or email of Openmeetings user with admin or SOAP-rights - * @param pass - password - * - * @return - {@link ServiceResult} with error code or SID and userId - */ - ServiceResult login(@WebParam(name="user") @QueryParam("user") String user, @WebParam(name="pass") @QueryParam("pass") String pass); - - /** - * Lists all users in the system! - * - * @param sid - * The SID from getSession - * - * @return - list of users - * @throws ServiceException - */ - List<UserDTO> get(@WebParam(name="sid") @QueryParam("sid") String sid) throws ServiceException; - - /** - * Adds a new User like through the Frontend, but also does activates the - * Account To do SSO see the methods to create a hash and use those ones! - * - * @param sid - * The SID from getSession - * @param user - * user object - * @param confirm - * whatever or not to send email, leave empty for auto-send - * - * @return - id of the user added or error code - * @throws ServiceException - */ - UserDTO add( - @WebParam(name="sid") @QueryParam("sid") String sid - , @WebParam(name="user") @QueryParam("user") UserDTO user - , @WebParam(name="confirm") @QueryParam("confirm") Boolean confirm - ) throws ServiceException; - - /** - * - * Delete a certain user by its id - * - * @param sid - * The SID from getSession - * @param id - * the openmeetings user id - * - * @return - id of the user deleted, error code otherwise - * @throws ServiceException - */ - ServiceResult delete(@WebParam(name="sid") @QueryParam("sid") String sid, @WebParam(name="id") @PathParam("id") long id) throws ServiceException; - - /** - * - * Delete a certain user by its external user id - * - * @param sid - * The SID from getSession - * @param externalId - * externalUserId - * @param externalType - * externalUserId - * - * @return - id of user deleted, or error code - * @throws ServiceException - */ - ServiceResult deleteExternal( - @WebParam(name="sid") @QueryParam("sid") String sid - , @WebParam(name="externaltype") @PathParam("externaltype") String externalType - , @WebParam(name="externalid") @PathParam("externalid") String externalId - ) throws ServiceException; - - /** - * Description: sets the SessionObject for a certain SID, after setting this - * Session-Object you can use the SID + a RoomId to enter any Room. ... - * Session-Hashs are deleted 15 minutes after the creation if not used. - * - * @param sid - * The SID from getSession - * @param user - * user details to set - * @param options - * room options to set - * - * @return - secure hash or error code - * @throws ServiceException - */ - ServiceResult getRoomHash( - @WebParam(name="sid") @QueryParam("sid") String sid - , @WebParam(name="user") @FormParam("user") ExternalUserDTO user - , @WebParam(name="options") @FormParam("options") RoomOptionsDTO options - ) throws ServiceException; - - /** - * Kick a user by its public SID - * - * @param sid - * The SID from getSession - * @param publicSID - * the publicSID (you can get it from the call to get users in a - * room) - * @return - <code>true</code> if user was kicked - */ - ServiceResult kick(@WebParam(name="sid") @QueryParam("sid") String sid, @WebParam(name="publicsid") @PathParam("publicsid") String publicSID) throws ServiceException; - - /** - * Returns the count of users currently in the Room with given id - * No admin rights are necessary for this call - * - * @param sid The SID from UserService.getSession - * @param roomId id of the room to get users - * @return number of users as int - */ - ServiceResult count(@WebParam(name="sid") @QueryParam("sid") String sid, @WebParam(name="roomid") @PathParam("roomid") Long roomId); -}
