Search in sources :

Example 1 with GwtKuraException

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;
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) StringTokenizer(java.util.StringTokenizer) CryptoService(org.eclipse.kura.crypto.CryptoService) HttpSession(javax.servlet.http.HttpSession) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Subject(javax.security.auth.Subject)

Example 2 with GwtKuraException

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");
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) KuraConnectException(org.eclipse.kura.KuraConnectException) DataService(org.eclipse.kura.data.DataService)

Example 3 with GwtKuraException

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;
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) PositionService(org.eclipse.kura.position.PositionService) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair)

Example 4 with GwtKuraException

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);
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) SystemService(org.eclipse.kura.system.SystemService) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException)

Example 5 with GwtKuraException

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);
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) PasswordCommandService(org.eclipse.kura.command.PasswordCommandService)

Aggregations

GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)49 KuraException (org.eclipse.kura.KuraException)22 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)11 NetworkAdminService (org.eclipse.kura.net.NetworkAdminService)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 SystemService (org.eclipse.kura.system.SystemService)7 ServiceLocator (org.eclipse.kura.web.server.util.ServiceLocator)7 GeneralSecurityException (java.security.GeneralSecurityException)4 CertificateException (java.security.cert.CertificateException)4 NetConfig (org.eclipse.kura.net.NetConfig)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 FileOutputStream (java.io.FileOutputStream)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 UnknownHostException (java.net.UnknownHostException)3 ZipInputStream (java.util.zip.ZipInputStream)3 ServletException (javax.servlet.ServletException)3