/** * Delete connection from configuration. * * @param req HTTP request * @param id forward id to delete * @return service response. */ @DELETE @Path("connection/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public ServiceResponse deleteConnection( @Context HttpServletRequest req, @PathParam("id") String id) { Configuration cfg = getEditConfiguration(req); for (SshSession sshClient : cfg.getSshSession()) { for (Forward fwd : sshClient.getForward()) { if (((Connection) fwd.getConnection()).getId().equals(id)) { return ServiceUtils.createNOKResponse( "Connection is in use by session " + sshClient.getName()); } } } Iterator<Connection> iter = cfg.getConnection().iterator(); while (iter.hasNext()) { Connection connection = iter.next(); if (connection.getId().equals(id)) { iter.remove(); return ServiceUtils.createOKResponse("Connection deleted"); } } return ServiceUtils.createOKResponse("Connection not found: " + id); }
/** * Change forward configuration. * * @param req HTTP request * @param id forward id to change * @return service response. */ @POST @Path("forward/update/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse updateForward( @Context HttpServletRequest req, @PathParam("id") String id, Forward forwardReq) { Configuration cfg = getEditConfiguration(req); for (SshSession sshClient : cfg.getSshSession()) { Iterator<Forward> iter = sshClient.getForward().iterator(); while (iter.hasNext()) { Forward fwd = iter.next(); if (fwd.getId().equals(id)) { Connection mAccount = getConnectionById((String) forwardReq.getConnection(), cfg); if (mAccount != null) { fwd.setDescription(forwardReq.getDescription()); fwd.setEnabled(forwardReq.isEnabled()); fwd.setType(forwardReq.getType()); fwd.setRHost(forwardReq.getRHost()); fwd.setSHost(forwardReq.getSHost()); fwd.setRPort(forwardReq.getRPort()); fwd.setSPort(forwardReq.getSPort()); fwd.setConnection(mAccount); fwd.setFilter(forwardReq.getFilter()); return ServiceUtils.createOKResponse("Forward changed"); } return ServiceUtils.createNOKResponse("Connection not found"); } } } return ServiceUtils.createOKResponse("Forward not found: " + id); }
/** * Change connection configuration. * * @param req HTTP request * @param id forward id to change * @return service response. */ @POST @Path("connection/update/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse updateConnection( @Context HttpServletRequest req, @PathParam("id") String id, Connection forwardReq) { Configuration cfg = getEditConfiguration(req); for (Connection account : cfg.getConnection()) { if (account.getId().equals(id)) { account.setName(forwardReq.getName()); account.setHost(forwardReq.getHost()); account.setPort(forwardReq.getPort()); account.setUser(forwardReq.getUser()); account.setPassword( forwardReq.getPassword().endsWith("==") ? forwardReq.getPassword() : DrillServer.getEncDecorder().encrypt(forwardReq.getPassword())); account.setProxy(forwardReq.getProxy()); return ServiceUtils.createOKResponse("Connection changed"); } } return ServiceUtils.createOKResponse("Connection not found: " + id); }
@Test public void testParseMultiValueParam() { Map<String, List<String>> result; result = ServiceUtils.parseMultiValueParam("product:4384681"); assertEquals(1, result.size()); assertEquals(1, result.get(PROD_LABEL).size()); result = ServiceUtils.parseMultiValueParam("product:4384681,4384682"); assertEquals(1, result.size()); assertEquals(2, result.get(PROD_LABEL).size()); assertEquals(PRODUCT_ID_1, result.get(PROD_LABEL).get(0)); assertEquals(PRODUCT_ID_2, result.get(PROD_LABEL).get(1)); }
/** {@inheritDoc} */ @Override public void start(BundleContext bundleContext) throws Exception { focusManager = ServiceUtils.getService(bundleContext, FocusManager.class); Assert.notNull(focusManager, "focusManager"); versionService = ServiceUtils.getService(bundleContext, VersionService.class); Assert.notNull(versionService, "versionService"); meetTools = focusManager.getOperationSet(OperationSetJitsiMeetTools.class); Assert.notNull(meetTools, "meetTools"); super.start(bundleContext); }
/** * Create image getter for context * * @param context */ @Inject public HttpImageGetter(Context context) { this.context = context; dir = context.getCacheDir(); width = ServiceUtils.getDisplayWidth(context); loading = new LoadingImageGetter(context, 24); }
/** * Returns the <tt>UIService</tt> obtained from the bundle context. * * @return the <tt>UIService</tt> obtained from the bundle context */ private UIService getUIService() { if (uiService == null) { uiService = ServiceUtils.getService(ResourceManagementActivator.bundleContext, UIService.class); } return uiService; }
/** * Delete session from configuration. * * @param req HTTP request * @param id session id to delete * @return service response. */ @DELETE @Path("session/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public ServiceResponse deleteSession( @Context HttpServletRequest req, @PathParam("id") String id) { Configuration cfg = getEditConfiguration(req); Iterator<SshSession> iter = cfg.getSshSession().iterator(); while (iter.hasNext()) { SshSession sshClient = iter.next(); if (sshClient.getId().equals(id)) { iter.remove(); return ServiceUtils.createOKResponse("Session '" + sshClient.getName() + "' deleted"); } } return ServiceUtils.createNOKResponse("Session not found: " + id); }
/** * Ctor. * * @param videoChannel The <tt>VideoChannel</tt> associated to this <tt>SimulcastEngine</tt>. */ public SimulcastEngine(VideoChannel videoChannel) { this.videoChannel = videoChannel; simulcastReceiver = new SimulcastReceiver( this, ServiceUtils.getService(videoChannel.getBundleContext(), ConfigurationService.class)); this.logger = Logger.getLogger(classLogger, videoChannel.getContent().getConference().getLogger()); }
/** * Create image getter for context * * @param context * @param service */ @Inject public HttpImageGetter(Context context, ContentsService service) { this.context = context; this.service = service; dir = context.getCacheDir(); width = ServiceUtils.getDisplayWidth(context); loading = new LoadingImageGetter(context, 24); okHttpClient = new OkHttpClient(); }
/** * Returns a <tt>MediaService</tt> implementation (if any). * * @return a <tt>MediaService</tt> implementation (if any) */ MediaService getMediaService() { MediaService mediaService = ServiceUtils.getService(getBundleContext(), MediaService.class); // TODO For an unknown reason, ServiceUtils2.getService fails to // retrieve the MediaService implementation. In the form of a temporary // workaround, get it through LibJitsi. if (mediaService == null) mediaService = LibJitsi.getMediaService(); return mediaService; }
/** * Returns the password last saved for the specified account. * * <p>TODO Delegate the implementation to {@link AccountManager} because it knows the format in * which the password (among the other account properties) was saved. * * @param bundleContext a currently valid bundle context. * @param accountID the AccountID for the account whose password we're looking for.. * @return a String containing the password for the specified accountID. */ protected String loadPassword(BundleContext bundleContext, AccountID accountID) { String accountPrefix = findAccountPrefix(bundleContext, accountID, getFactoryImplPackageName()); if (accountPrefix == null) return null; CredentialsStorageService credentialsStorage = ServiceUtils.getService(bundleContext, CredentialsStorageService.class); return credentialsStorage.loadPassword(accountPrefix); }
/** * Delete forward from configuration. * * @param req HTTP request * @param id forward id to delete * @return service response. */ @DELETE @Path("forward/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public ServiceResponse deleteForward( @Context HttpServletRequest req, @PathParam("id") String id) { Configuration cfg = getEditConfiguration(req); for (SshSession sshClient : cfg.getSshSession()) { Iterator<Forward> iter = sshClient.getForward().iterator(); while (iter.hasNext()) { Forward fwd = iter.next(); if (fwd.getId().equals(id)) { iter.remove(); return ServiceUtils.createOKResponse("Forward removed"); } } } return ServiceUtils.createOKResponse("Forward not found: " + id); }
private void maybeDoShutdown() { if (shutdownInProgress && conferences.size() == 0) { logger.info("Focus is shutting down NOW"); ShutdownService shutdownService = ServiceUtils.getService(FocusBundleActivator.bundleContext, ShutdownService.class); shutdownService.beginShutdown(); } }
/** * Change session configuration. * * @param req HTTP request * @param id session id to change * @return service response. */ @POST @Path("session/update/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse updateSession( @Context HttpServletRequest req, @PathParam("id") String id, SshSession newSessionCfg) { Configuration cfg = getEditConfiguration(req); for (SshSession sessionCfg : cfg.getSshSession()) { if (sessionCfg.getId().equals(id)) { sessionCfg.setName(newSessionCfg.getName()); sessionCfg.setEnabled(newSessionCfg.isEnabled()); sessionCfg.setDescription(newSessionCfg.getDescription()); return ServiceUtils.createOKResponse("Session configuration changed"); } } return ServiceUtils.createOKResponse("Session not found: " + id); }
/** * Add new session to configuration. * * @param req HTTP request * @param forwardReq forward data * @return service response. */ @POST @Path("session/add") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse addSession(@Context HttpServletRequest req, SshSession sessionCfg) { Configuration cfg = getEditConfiguration(req); sessionCfg.setId(StringUtils.createUUID()); cfg.getSshSession().add(sessionCfg); return ServiceUtils.createOKResponse("SSH client session added"); }
/** * Add new connection to configuration. * * @param req HTTP request * @param connectionCfg forward data * @return service response. */ @POST @Path("connection/add") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse addConnection(@Context HttpServletRequest req, Connection connectionCfg) { Configuration cfg = getEditConfiguration(req); connectionCfg.setId(StringUtils.createUUID()); connectionCfg.setPassword(DrillServer.getEncDecorder().encrypt(connectionCfg.getPassword())); cfg.getConnection().add(connectionCfg); return ServiceUtils.createOKResponse("Connection added"); }
/** * Add new forward to configuration. * * @param req HTTP request * @param forwardReq forward data * @return service response. */ @POST @Path("forward/add/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ServiceResponse addForward( @Context HttpServletRequest req, @PathParam("id") String sessionId, Forward forwardReq) { Configuration cfg = getEditConfiguration(req); for (SshSession sshClient : cfg.getSshSession()) { if (sshClient.getId().equals(sessionId)) { Connection mAccount = getConnectionById((String) forwardReq.getConnection(), cfg); if (mAccount != null) { Forward fwd = new Forward(); fwd.setConnection(mAccount); fwd.setId(StringUtils.createUUID()); fwd.setDescription(forwardReq.getDescription()); fwd.setEnabled(forwardReq.isEnabled()); fwd.setSHost(forwardReq.getSHost()); fwd.setSPort(forwardReq.getSPort()); fwd.setRHost(forwardReq.getRHost()); fwd.setRPort(forwardReq.getRPort()); fwd.setType(forwardReq.getType()); sshClient.getForward().add(fwd); return ServiceUtils.createOKResponse("SSH forward added"); } return ServiceUtils.createNOKResponse("SSH connection not found"); } } return ServiceUtils.createNOKResponse("SSH client not found"); }
public String[] listCAs() throws RemoteException, VOMSException { log.info("listCAs();"); try { List cas = (List) ListCaOperation.instance().execute(); HibernateFactory.commitTransaction(); return ServiceUtils.casToStringArray(cas); } catch (RuntimeException e) { ServiceExceptionHelper.handleServiceException(log, e); throw e; } }
public String[] listRoles(String username, String userca) throws RemoteException, VOMSException { log.info("listRoles(" + StringUtils.join(new Object[] {username, userca}, ',') + ");"); try { Set roles = (Set) ListUserRolesOperation.instance(username, userca).execute(); HibernateFactory.commitTransaction(); return ServiceUtils.toStringArray(roles); } catch (RuntimeException e) { ServiceExceptionHelper.handleServiceException(log, e); throw e; } }
/** implements BundleActivator.start() */ public void start(BundleContext bc) throws Exception { logger.info("starting popup message test "); bundleContext = bc; setName("PopupMessageHandlerSLick"); Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put("service.pid", getName()); // we maybe are running on machine without WM and systray // (test server machine), skip tests if (ServiceUtils.getService(bc, SystrayService.class) != null) { addTest(TestPopupMessageHandler.suite()); } bundleContext.registerService(getClass().getName(), this, properties); }
/** * Saves the password for the specified account after scrambling it a bit so that it is not * visible from first sight (Method remains highly insecure). * * <p>TODO Delegate the implementation to {@link AccountManager} because it knows the format in * which the password (among the other account properties) is to be saved. * * @param bundleContext a currently valid bundle context. * @param accountID the <tt>AccountID</tt> of the account whose password is to be stored * @param password the password to be stored * @throws IllegalArgumentException if no account corresponding to <tt>accountID</tt> has been * previously stored. * @throws OperationFailedException if anything goes wrong while storing the specified * <tt>password</tt> */ protected void storePassword(BundleContext bundleContext, AccountID accountID, String password) throws IllegalArgumentException, OperationFailedException { String accountPrefix = findAccountPrefix(bundleContext, accountID, getFactoryImplPackageName()); if (accountPrefix == null) { throw new IllegalArgumentException( "No previous records found for account ID: " + accountID.getAccountUniqueID() + " in package" + getFactoryImplPackageName()); } CredentialsStorageService credentialsStorage = ServiceUtils.getService(bundleContext, CredentialsStorageService.class); if (!credentialsStorage.storePassword(accountPrefix, password)) { throw new OperationFailedException( "CredentialsStorageService failed to storePassword", OperationFailedException.GENERAL_ERROR); } }
public String[] listSubGroups(String groupname) throws RemoteException, VOMSException { log.info("listSubGroups(" + StringUtils.join(new Object[] {groupname}, ',') + ");"); try { List childrenGroups; if (groupname == null) { VOMSContext ctxt = VOMSContext.getVoContext(); childrenGroups = (List) ListChildrenGroupsOperation.instance(ctxt.getGroup()).execute(); } else childrenGroups = (List) ListChildrenGroupsOperation.instance(groupname).execute(); HibernateFactory.commitTransaction(); return ServiceUtils.groupsToStringArray(childrenGroups); } catch (RuntimeException e) { ServiceExceptionHelper.handleServiceException(log, e); throw e; } }
@Override protected Response doInBackground(Void... params) { // we need this value in onPostExecute, so get it already here mAction = TraktAction.values()[mArgs.getInt(InitBundle.TRAKTACTION)]; // check for network connection if (!AndroidUtils.isNetworkConnected(mContext)) { Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = mContext.getString(R.string.offline); return r; } // check for valid credentials if (!ServiceUtils.isTraktCredentialsValid(mContext)) { // return null so a credentials dialog is displayed // it will call us again with valid credentials return null; } // get an authenticated trakt-java ServiceManager ServiceManager manager = ServiceUtils.getTraktServiceManagerWithAuth(mContext, false); if (manager == null) { // password could not be decrypted Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = mContext.getString(R.string.trakt_generalerror); return r; } // get values used by all actions final int showTvdbId = mArgs.getInt(InitBundle.SHOW_TVDBID); final int season = mArgs.getInt(InitBundle.SEASON); final int episode = mArgs.getInt(InitBundle.EPISODE); // last chance to abort if (isCancelled()) { return null; } try { Response r = null; switch (mAction) { case CHECKIN_EPISODE: { final String message = mArgs.getString(InitBundle.MESSAGE); final CheckinBuilder checkinBuilder = manager.showService().checkin(showTvdbId).season(season).episode(episode); if (!TextUtils.isEmpty(message)) { checkinBuilder.message(message); } r = checkinBuilder.fire(); if (TraktStatus.SUCCESS.equals(r.status)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); r.message = mContext.getString( R.string.checkin_success_trakt, (r.show != null ? r.show.title + " " : "") + Utils.getEpisodeNumber(prefs, season, episode)); } break; } case CHECKIN_MOVIE: { final String imdbId = mArgs.getString(InitBundle.IMDB_ID); final String message = mArgs.getString(InitBundle.MESSAGE); final MovieService.CheckinBuilder checkinBuilder = manager.movieService().checkin(imdbId); if (!TextUtils.isEmpty(message)) { checkinBuilder.message(message); } r = checkinBuilder.fire(); if (TraktStatus.SUCCESS.equals(r.status)) { r.message = mContext.getString( R.string.checkin_success_trakt, (r.movie != null ? r.movie.title + " " : "")); } break; } case RATE_EPISODE: { final Rating rating = Rating.fromValue(mArgs.getString(InitBundle.RATING)); r = manager .rateService() .episode(showTvdbId) .season(season) .episode(episode) .rating(rating) .fire(); break; } case RATE_SHOW: { final Rating rating = Rating.fromValue(mArgs.getString(InitBundle.RATING)); r = manager.rateService().show(showTvdbId).rating(rating).fire(); break; } case SHOUT: { final String shout = mArgs.getString(InitBundle.MESSAGE); final boolean isSpoiler = mArgs.getBoolean(InitBundle.ISSPOILER); if (episode == 0) { r = manager .commentService() .show(showTvdbId) .comment(shout) .spoiler(isSpoiler) .fire(); } else { r = manager .commentService() .episode(showTvdbId) .season(season) .episode(episode) .comment(shout) .spoiler(isSpoiler) .fire(); } break; } case WATCHLIST_MOVIE: { final int tmdbId = mArgs.getInt(InitBundle.TMDB_ID); manager.movieService().watchlist().movie(tmdbId).fire(); // In case of failure this will just return an exception, so // we need to construct our own response r = new Response(); r.status = TraktStatus.SUCCESS; r.message = mContext.getString(R.string.watchlist_added); break; } case UNWATCHLIST_MOVIE: { final int tmdbId = mArgs.getInt(InitBundle.TMDB_ID); manager.movieService().unwatchlist().movie(tmdbId).fire(); // In case of failure this will just return an exception, so // we need to construct our own response r = new Response(); r.status = TraktStatus.SUCCESS; r.message = mContext.getString(R.string.watchlist_removed); break; } default: break; } return r; } catch (TraktException e) { Utils.trackExceptionAndLog(mContext, TAG, e); Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = mContext.getString(R.string.trakt_generalerror); return r; } catch (ApiException e) { Utils.trackExceptionAndLog(mContext, TAG, e); Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = mContext.getString(R.string.trakt_generalerror); return r; } }
@Test public void testParseMultiValueParam_null() { assertEquals(0, ServiceUtils.parseMultiValueParam(null).size()); }
/** * Performs UI changes after the chat room join task has finished. * * @param returnCode the result code from the chat room join task. */ private void done(String returnCode) { ConfigurationUtils.updateChatRoomStatus( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), GlobalStatusEnum.ONLINE_STATUS); String errorMessage = null; if (JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) { chatRoomWrapper.removePassword(); AuthenticationWindowService authWindowsService = ServiceUtils.getService(MUCActivator.bundleContext, AuthenticationWindowService.class); AuthenticationWindowService.AuthenticationWindow authWindow = authWindowsService.create( null, null, null, false, chatRoomWrapper.isPersistent(), AuthenticationWindow.getAuthenticationWindowIcon( chatRoomWrapper.getParentProvider().getProtocolProvider()), resources.getI18NString( "service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {chatRoomWrapper.getParentProvider().getName()}), resources.getI18NString( "service.gui.CHAT_ROOM_REQUIRES_PASSWORD", new String[] {chatRoomWrapper.getChatRoomName()}), "", null, isFirstAttempt ? null : resources.getI18NString( "service.gui.AUTHENTICATION_FAILED", new String[] {chatRoomWrapper.getChatRoomName()}), null); authWindow.setVisible(true); if (!authWindow.isCanceled()) { joinChatRoom( chatRoomWrapper, nickName, new String(authWindow.getPassword()).getBytes(), authWindow.isRememberPassword(), false, subject); } } else if (JOIN_REGISTRATION_REQUIRED_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_REGISTRATION_REQUIRED", new String[] {chatRoomWrapper.getChatRoomName()}); } else if (JOIN_PROVIDER_NOT_REGISTERED_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_NOT_CONNECTED", new String[] {chatRoomWrapper.getChatRoomName()}); } else if (JOIN_SUBSCRIPTION_ALREADY_EXISTS_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_ALREADY_JOINED", new String[] {chatRoomWrapper.getChatRoomName()}); } else { errorMessage = resources.getI18NString( "service.gui.FAILED_TO_JOIN_CHAT_ROOM", new String[] {chatRoomWrapper.getChatRoomName()}); } if (!JOIN_SUCCESS_PROP.equals(returnCode) && !JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) { MUCActivator.getAlertUIService() .showAlertPopup(resources.getI18NString("service.gui.ERROR"), errorMessage); } if (JOIN_SUCCESS_PROP.equals(returnCode)) { if (rememberPassword) { chatRoomWrapper.savePassword(new String(password)); } if (subject != null) { try { chatRoomWrapper.getChatRoom().setSubject(subject); } catch (OperationFailedException ex) { logger.warn("Failed to set subject."); } } } chatRoomWrapper.firePropertyChange(returnCode); }
@Test public void testParseMultiValueParam_one_colon() { assertEquals(0, ServiceUtils.parseMultiValueParam("colon:").size()); }
@Test public void testParseMultiValueParam_three_colons() { assertEquals(1, ServiceUtils.parseMultiValueParam("colon:colon:").size()); }
@Test public void testParseMultiValueParam_empty_string() { assertEquals(0, ServiceUtils.parseMultiValueParam("").size()); }
/** Loads all service references */ private void initServices() { BundleContext bc = DnsConfigActivator.bundleContext; R = ServiceUtils.getService(bc, ResourceManagementService.class); }