List of usage examples for java.lang SecurityException SecurityException
public SecurityException()
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
public static String postJSON(String host, String service, String body, String token, Map<String, Object> parameters) throws SecurityException, RemoteException { String queryString = generateQueryString(parameters); final HttpResponse resp; final HttpPost post = new HttpPost(normalizeURL(host + service) + queryString); post.setHeader(RH_ACCEPT, "application/json"); post.setHeader(RH_AUTH_TOKEN, bearer(token)); try {// w w w . j a v a2 s . c o m StringEntity input = new StringEntity(body, DEFAULT_CHARSET); input.setContentType("application/json"); post.setEntity(input); resp = getHttpClient().execute(post); String response = EntityUtils.toString(resp.getEntity(), DEFAULT_CHARSET); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response; } if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN || resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new SecurityException(); } String msg = ""; try { msg = response.substring(response.indexOf("<h1>") + 4, response.indexOf("</h1>", response.indexOf("<h1>"))); } catch (Exception e) { msg = resp.getStatusLine().toString(); } throw new RemoteException(msg); } catch (ClientProtocolException e) { throw new RemoteException(e.getMessage(), e); } catch (ParseException e) { throw new RemoteException(e.getMessage(), e); } catch (IOException e) { throw new RemoteException(e.getMessage(), e); } }
From source file:org.sakaiproject.poll.service.impl.PollListManagerImpl.java
public boolean savePoll(Poll t) throws SecurityException, IllegalArgumentException { boolean newPoll = false; if (t == null || t.getText() == null || t.getSiteId() == null || t.getVoteOpen() == null || t.getVoteClose() == null) { throw new IllegalArgumentException("you must supply a question, siteId & open and close dates"); }//from w ww.j a v a 2s.c om if (!externalLogic.isUserAdmin() && !externalLogic.isAllowedInLocation(PollListManager.PERMISSION_ADD, externalLogic.getSiteRefFromId(t.getSiteId()), externalLogic.getCurrentuserReference())) { throw new SecurityException(); } if (t.getId() == null) { newPoll = true; t.setId(idManager.createUuid()); } try { dao.save(t); } catch (DataAccessException e) { log.error("Hibernate could not save: " + e.toString()); e.printStackTrace(); return false; } log.debug(" Poll " + t.toString() + "successfuly saved"); externalLogic.registerStatement(t.getText(), newPoll); if (newPoll) externalLogic.postEvent("poll.add", "poll/site/" + t.getSiteId() + "/poll/" + t.getId(), true); else externalLogic.postEvent("poll.update", "poll/site/" + t.getSiteId() + " /poll/" + t.getId(), true); return true; }
From source file:org.traccar.web.server.model.DataServiceImpl.java
@Override public User register(String login, String password) { if (getApplicationSettings().getRegistrationEnabled()) { User user = new User(); user.setLogin(login);//from ww w . j av a 2 s. c o m user.setPassword(password); createUser(getSessionEntityManager(), user); setSessionUser(user); return user; } else { throw new SecurityException(); } }
From source file:org.jolokia.http.HttpRequestHandlerTest.java
@Test public void requestErrorHandling() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException { Object[] exceptions = new Object[] { new ReflectionException(new NullPointerException()), 404, 500, new InstanceNotFoundException(), 404, 500, new MBeanException(new NullPointerException()), 500, 500, new AttributeNotFoundException(), 404, 500, new UnsupportedOperationException(), 500, 500, new IOException(), 500, 500, new IllegalArgumentException(), 400, 400, new SecurityException(), 403, 403, new RuntimeMBeanException(new NullPointerException()), 500, 500 }; for (int i = 0; i < exceptions.length; i += 3) { Exception e = (Exception) exceptions[i]; reset(backend);//from ww w .j a v a 2 s . co m expect(backend.isDebug()).andReturn(true).anyTimes(); backend.error(find("" + exceptions[i + 1]), EasyMock.<Throwable>anyObject()); backend.error(find("" + exceptions[i + 2]), EasyMock.<Throwable>anyObject()); expect(backend.handleRequest(EasyMock.<JmxRequest>anyObject())).andThrow(e); replay(backend); JSONObject resp = (JSONObject) handler.handleGetRequest("/jolokia", "/read/java.lang:type=Memory/HeapMemoryUsage", null); assertEquals(resp.get("status"), exceptions[i + 1]); resp = handler.handleThrowable(e); assertEquals(resp.get("status"), exceptions[i + 2], e.getClass().getName()); } }
From source file:com.datatorrent.stram.webapp.StramWebServices.java
void checkAccess(HttpServletRequest request) { if (!hasAccess(request)) { throw new SecurityException(); } }
From source file:org.traccar.web.server.model.DataServiceImpl.java
@Override public User addUser(User user) { User currentUser = getSessionUser(); if (user.getLogin().isEmpty() || user.getPassword().isEmpty()) { throw new IllegalArgumentException(); } if (currentUser.getAdmin()) { EntityManager entityManager = getSessionEntityManager(); synchronized (entityManager) { entityManager.getTransaction().begin(); try { entityManager.persist(user); entityManager.getTransaction().commit(); return user; } catch (RuntimeException e) { entityManager.getTransaction().rollback(); throw e; }/*from w ww .j a v a 2s.co m*/ } } else { throw new SecurityException(); } }
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
public static String putJSON(String host, String service, String body, String token, Map<String, Object> parameters) throws SecurityException, RemoteException { final HttpResponse resp; String queryString = generateQueryString(parameters); String uriString = normalizeURL(host + service) + queryString; final HttpPut put = new HttpPut(uriString); put.setHeader(RH_ACCEPT, "application/json"); put.setHeader(RH_AUTH_TOKEN, bearer(token)); try {/*www.j a v a 2 s. c om*/ if (body != null) { StringEntity input = new StringEntity(body, DEFAULT_CHARSET); input.setContentType("application/json"); put.setEntity(input); } resp = getHttpClient().execute(put); String response = EntityUtils.toString(resp.getEntity(), DEFAULT_CHARSET); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response; } if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN || resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new SecurityException(); } throw new RemoteException("Error validating " + resp.getStatusLine()); } catch (final Exception e) { throw new RemoteException(e.getMessage(), e); } }
From source file:org.traccar.web.server.model.DataServiceImpl.java
@Override public User updateUser(User user) { User currentUser = getSessionUser(); if (user.getLogin().isEmpty() || user.getPassword().isEmpty()) { throw new IllegalArgumentException(); }/*w ww .j a v a 2 s .c o m*/ if (currentUser.getAdmin() || (currentUser.getId() == user.getId() && !user.getAdmin())) { EntityManager entityManager = getSessionEntityManager(); synchronized (entityManager) { entityManager.getTransaction().begin(); try { // TODO: better solution? if (currentUser.getId() == user.getId()) { currentUser.setLogin(user.getLogin()); currentUser.setPassword(user.getPassword()); currentUser.setUserSettings(user.getUserSettings()); currentUser.setAdmin(user.getAdmin()); entityManager.merge(currentUser); user = currentUser; } else { // TODO: handle other users } entityManager.getTransaction().commit(); setSessionUser(user); return user; } catch (RuntimeException e) { entityManager.getTransaction().rollback(); throw e; } } } else { throw new SecurityException(); } }
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
public static String deleteJSON(String host, String service, String token, Map<String, Object> parameters) throws SecurityException, RemoteException { final HttpResponse resp; String queryString = generateQueryString(parameters); final HttpDelete delete = new HttpDelete(normalizeURL(host + service) + queryString); delete.setHeader(RH_ACCEPT, "application/json"); delete.setHeader(RH_AUTH_TOKEN, bearer(token)); try {// ww w .j a va2 s . c o m resp = getHttpClient().execute(delete); String response = EntityUtils.toString(resp.getEntity(), DEFAULT_CHARSET); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response; } if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN || resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new SecurityException(); } throw new RemoteException("Error validating " + resp.getStatusLine()); } catch (ClientProtocolException e) { throw new RemoteException(e.getMessage(), e); } catch (ParseException e) { throw new RemoteException(e.getMessage(), e); } catch (IOException e) { throw new RemoteException(e.getMessage(), e); } }
From source file:eu.geopaparazzi.library.gps.GpsService.java
@Override public void onDestroy() { log("onDestroy Gpsservice."); if (isDatabaseLogging) { stopDatabaseLogging();//from w w w.j av a2 s .c o m } if (locationManager != null && isListeningForUpdates) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException(); } locationManager.removeUpdates(this); locationManager.removeGpsStatusListener(this); isListeningForUpdates = false; } if (TestMock.isOn) { TestMock.stopMocking(locationManager); } super.onDestroy(); }