use of org.eclipse.kura.web.shared.GwtKuraException in project kura by eclipse.
the class SecureBasicHttpContext method handleSecurity.
/**
* Provides Basic authentication over HTTPS.
*/
@Override
public synchronized boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setHeader("X-FRAME-OPTIONS", "SAMEORIGIN");
response.setHeader("X-XSS-protection", "1; mode=block");
response.setHeader("X-Content-Type-Options", "nosniff");
response.setHeader("Cache-Control", "no-cache,no-store");
response.setHeader("Pragma", "no-cache");
// If a trailing "/" is used when accesssing the app, redirect
if (request.getRequestURI().equals(this.m_appRoot + "/")) {
response.sendRedirect(this.m_appRoot);
}
// If using root context, redirect
if (request.getRequestURI().equals("/")) {
response.sendRedirect(this.m_appRoot);
}
HttpSession session = request.getSession(false);
if (session != null) {
String logout = (String) session.getAttribute("logout");
if (logout != null) {
session.removeAttribute("logout");
session.invalidate();
return failAuthorization(response);
}
}
String authHeader = request.getHeader("Authorization");
if (authHeader == null) {
s_logger.debug("Missing 'Authorization' HTTP header");
return failAuthorization(response);
}
StringTokenizer tokens = new StringTokenizer(authHeader);
String authScheme = tokens.nextToken();
if (!"Basic".equals(authScheme)) {
s_logger.error("The authentication scheme is not 'Basic'");
return failAuthorization(response);
}
String base64 = tokens.nextToken();
String credentials = null;
try {
CryptoService cryptoService = ServiceLocator.getInstance().getService(CryptoService.class);
credentials = cryptoService.decodeBase64(base64);
} catch (GwtKuraException e) {
throw new IOException(e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new IOException(e.getMessage());
}
int colon = credentials.indexOf(':');
String userid = credentials.substring(0, colon);
String password = credentials.substring(colon + 1);
Subject subject = login(request, response, userid, password);
if (subject == null) {
return failAuthorization(response);
}
request.setAttribute(HttpContext.REMOTE_USER, null);
request.setAttribute(HttpContext.AUTHENTICATION_TYPE, request.getAuthType());
request.setAttribute(HttpContext.AUTHORIZATION, null);
return true;
}
use of org.eclipse.kura.web.shared.GwtKuraException in project kura by eclipse.
the class GwtStatusServiceImpl method connectDataService.
@Override
public void connectDataService(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
DataService dataService = ServiceLocator.getInstance().getService(DataService.class);
int counter = 10;
try {
dataService.connect();
while (!dataService.isConnected() && counter > 0) {
Thread.sleep(1000);
counter--;
}
} catch (KuraConnectException e) {
s_logger.warn("Error connecting", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Error connecting");
} catch (InterruptedException e) {
s_logger.warn("Interrupt Exception", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Interrupt Exception");
} catch (IllegalStateException e) {
s_logger.warn("Illegal client state", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Illegal client state");
}
}
use of org.eclipse.kura.web.shared.GwtKuraException in project kura by eclipse.
the class GwtStatusServiceImpl method getPositionStatus.
private List<GwtGroupedNVPair> getPositionStatus() throws GwtKuraException {
List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
try {
PositionService positionService = ServiceLocator.getInstance().getService(PositionService.class);
if (positionService != null) {
pairs.add(new GwtGroupedNVPair("positionStatus", "Longitude", Double.toString(Math.toDegrees(positionService.getPosition().getLongitude().getValue()))));
pairs.add(new GwtGroupedNVPair("positionStatus", "Latitude", Double.toString(Math.toDegrees(positionService.getPosition().getLatitude().getValue()))));
pairs.add(new GwtGroupedNVPair("positionStatus", "Altitude", positionService.getPosition().getAltitude().toString()));
}
} catch (GwtKuraException e) {
s_logger.warn("Get position status failed", e);
throw e;
}
return pairs;
}
use of org.eclipse.kura.web.shared.GwtKuraException in project kura by eclipse.
the class ThreadGroupComparator method startBundle.
@Override
public void startBundle(GwtXSRFToken xsrfToken, String bundleId) throws GwtKuraException {
checkXSRFToken(xsrfToken);
SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
Bundle[] bundles = systemService.getBundles();
s_logger.info("Starting bundle with ID: {}", bundleId);
for (Bundle b : bundles) {
if (b.getBundleId() == Long.parseLong(bundleId)) {
try {
b.start();
return;
} catch (BundleException e) {
s_logger.error("Failed to start bundle {}", b.getBundleId(), e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR);
}
}
}
// Bundle was not found, throw error
s_logger.error("Could not find bundle with ID: {}", bundleId);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR);
}
use of org.eclipse.kura.web.shared.GwtKuraException in project kura by eclipse.
the class ThreadGroupComparator method executeCommand.
@Override
public String executeCommand(GwtXSRFToken xsrfToken, String cmd, String pwd) throws GwtKuraException {
checkXSRFToken(xsrfToken);
PasswordCommandService commandService = ServiceLocator.getInstance().getService(PasswordCommandService.class);
try {
return commandService.execute(cmd, pwd);
} catch (KuraException e) {
// s_logger.error(e.getLocalizedMessage());
if (e.getCode() == KuraErrorCode.OPERATION_NOT_SUPPORTED) {
throw new GwtKuraException(GwtKuraErrorCode.SERVICE_NOT_ENABLED);
} else if (e.getCode() == KuraErrorCode.CONFIGURATION_ATTRIBUTE_INVALID) {
throw new GwtKuraException(GwtKuraErrorCode.ILLEGAL_ARGUMENT);
}
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR);
}
}
Aggregations