protected static void handleAuthException(S3ServiceException e, FileURL fileURL) throws AuthException { int code = e.getResponseCode(); if(code==401 || code==403) throw new AuthException(fileURL); }
FileURL url = authException.getURL(); AuthDialog authDialog = new AuthDialog(WindowManager.getCurrentMainFrame(), url, true, authException.getMessage()); authDialog.showDialog(); newCredentialsMapping = authDialog.getCredentialsMapping();
AuthException authException = (AuthException)e; AuthDialog authDialog = popAuthDialog(authException.getURL(), true, authException.getMessage()); newCredentialsMapping = authDialog.getCredentialsMapping(); guestCredentialsSelected = authDialog.guestCredentialsSelected();
/** * Checks the response code of the given HttpURLConnection and : * <ul> * <li>throws an {@link AuthException} if the response code is 401 (Unauthorized) * <li>throws an IOException if the response code is not in the 2xx - 3xx range (not a positive response) * <li>does nothing otherwise * * @param conn the HttpURLConnection connection to examine * @throws AuthException if the response code is 401 (Unauthorized) * @throws IOException if the response code is not in the 2xx - 3xx range (not a positive response) */ private void checkHTTPResponse(HttpURLConnection conn) throws AuthException, IOException { int responseCode = conn.getResponseCode(); LOGGER.info("response code = {}", responseCode); // If we got a 401 (Unauthorized) response, throw an AuthException to ask for credentials if(responseCode==401) throw new AuthException(fileURL, conn.getResponseMessage()); if(responseCode<200 || responseCode>=400) throw new IOException(conn.getResponseMessage()); }
@Override public void startConnection() throws IOException, AuthException { try { initClientIfNeeded(); } catch (RuntimeFaultFaultMsg e) { throw new IOException(e); } catch (InvalidLocaleFaultMsg e) { throw new IOException(e); } catch (InvalidLoginFaultMsg e) { throw new AuthException(location, e.getMessage()); } }
/** * Throws an {@link AuthException} using this connection handler's realm, credentials and the message passed as * an argument (can be <code>null</code>). The FileURL instance representing the realm that is used to create * the <code>AuthException</code> is a clone of this realm, making it safe for modification. * * @param message the message to pass to AuthException's constructor, can be <code>null</code> * @throws AuthException always throws the created AuthException */ public void throwAuthException(String message) throws AuthException { FileURL clonedRealm = (FileURL)realm.clone(); clonedRealm.setCredentials(credentials); throw new AuthException(clonedRealm, message); }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { if(!url.containsCredentials()) throw new AuthException(url); // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); // Import credentials Credentials creds = url.getCredentials(); if(creds!=null) { // URL-encode secret as it may contain non URL-safe characters ('+' and '/') realm.setCredentials(new Credentials(creds.getLogin(), URLEncoder.encode(creds.getPassword(), "UTF-8"))); } // Change the scheme to the actual Hadoop fileystem (s3 -> s3n) realm.setScheme("s3n"); return FileSystem.get(URI.create(realm.toString(true, false)), DEFAULT_CONFIGURATION); }
throw new AuthException(fileURL, "Authentication required"); throw new AuthException(fileURL, e.getMessage());
public AbstractFile getFile(FileURL url, Object... instantiationParams) throws IOException { Credentials credentials = url.getCredentials(); if(credentials==null || credentials.getLogin().equals("") || credentials.getPassword().equals("")) throw new AuthException(url);
throw new AuthException(fileURL, e.getMessage());