List of usage examples for javax.security.auth.login LoginException LoginException
public LoginException(String msg)
From source file:org.polymap.rhei.um.auth.UmLoginModule.java
@Override public boolean login() throws LoginException { Callback label = new TextOutputCallback(TextOutputCallback.INFORMATION, dialogTitle); NameCallback nameCallback = new NameCallback(i18n.get("username"), "default"); PasswordCallback passwordCallback = new PasswordCallback(i18n.get("password"), false); try {//from w w w. j a v a2s . c o m callbackHandler.handle(new Callback[] { label, nameCallback, passwordCallback }); } catch (Exception e) { log.warn("", e); throw new LoginException(e.getLocalizedMessage()); } String username = nameCallback.getName(); // if (username == null) { // return false; // } // admin if (username == null || username.equals("admin")) { // FIXME read password hash from persistent storage and check log.warn("!!! NO PASSWORD check for admin user yet !!!!!!"); principal = new UserPrincipal("admin"); return loggedIn = true; } // ordinary user User user = repo.findUser(username); log.info("username: " + user.email().get()); if (user != null && passwordCallback.getPassword() != null) { String password = String.valueOf(passwordCallback.getPassword()); if (PasswordEncryptor.instance().checkPassword(password, user.passwordHash().get())) { log.info("username: " + user.username().get()); principal = new UmUserPrincipal(user); return loggedIn = true; } } return false; }
From source file:org.transdroid.search.revolutiontt.RevolutionTTAdapter.java
private HttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.RevolutionTT); String password = SettingsHelper.getSitePass(context, TorrentSite.RevolutionTT); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/*from w w w . j a va 2s . co m*/ // Setup http client HttpClient httpclient = HttpHelper.buildDefaultSearchHttpClient(false); httpclient.execute(new HttpGet("https://revolutiontt.me/login.php")); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair[] { new BasicNameValuePair("username", username), new BasicNameValuePair("password", password) }))); HttpResponse loginResult = httpclient.execute(loginPost); String loginHtml = HttpHelper.convertStreamToString(loginResult.getEntity().getContent()); final String LOGIN_ERROR = "Login failed!"; if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK || loginHtml.indexOf(LOGIN_ERROR) >= 0) { // Failed to sign in throw new LoginException("Login failure for RevolutionTT with user " + username); } return httpclient; }
From source file:org.apache.nifi.security.krb.AbstractKerberosUser.java
/** * Performs a logout of the current user. * * @throws LoginException if the logout fails *///from ww w . j a va 2 s. c o m @Override public synchronized void logout() throws LoginException { if (!isLoggedIn()) { return; } try { loginContext.logout(); loggedIn.set(false); LOGGER.debug("Successful logout for {}", new Object[] { principal }); subject = null; loginContext = null; } catch (LoginException e) { throw new LoginException("Logout failed due to: " + e.getMessage()); } }
From source file:org.transdroid.search.AsiaTorrents.AsiaTorrentsAdapter.java
private DefaultHttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.AsiaTorrents); String password = SettingsHelper.getSitePass(context, TorrentSite.AsiaTorrents); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/* ww w . j ava 2 s . c om*/ // Setup request using GET HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT); DefaultHttpClient httpclient = new DefaultHttpClient(httpparams); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair[] { new BasicNameValuePair(LOGIN_USER, username), new BasicNameValuePair(LOGIN_PASS, password) }))); HttpResponse loginResult = httpclient.execute(loginPost); if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { // Failed to sign in throw new LoginException("Login failure for AsiaTorrents with user " + username); } return httpclient; }
From source file:org.transdroid.search.IpTorrents.IpTorrentsAdapter.java
private DefaultHttpClient prepareRequest(Context context) throws Exception { String username = null;//SettingsHelper.getSiteUser(context, TorrentSite.IpTorrents); String password = null;//SettingsHelper.getSitePass(context, TorrentSite.IpTorrents); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/*from ww w . j av a 2 s. c o m*/ // Setup request using GET HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT); DefaultHttpClient httpclient = new DefaultHttpClient(httpparams); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair[] { new BasicNameValuePair(LOGIN_USER, username), new BasicNameValuePair(LOGIN_PASS, password) }))); HttpResponse loginResult = httpclient.execute(loginPost); if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { // Failed to sign in throw new LoginException("Login failure for IPTorrents with user " + username); } return httpclient; }
From source file:org.transdroid.search.BroadcasTheNet.BroadcasTheNetAdapter.java
private DefaultHttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.BroadcasTheNet); String password = SettingsHelper.getSitePass(context, TorrentSite.BroadcasTheNet); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/*from w w w .jav a 2 s.c o m*/ // Setup request using GET HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT); DefaultHttpClient httpclient = new DefaultHttpClient(httpparams); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair[] { new BasicNameValuePair(LOGIN_USER, username), new BasicNameValuePair(LOGIN_PASS, password) }))); HttpResponse loginResult = httpclient.execute(loginPost); if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { // Failed to sign in throw new LoginException("Login failure for BroadcasTheNet with user " + username); } return httpclient; }
From source file:com.redhat.topicindex.security.FedoraAccountSystem.java
@SuppressWarnings("unchecked") private boolean authenticate() throws LoginException { if (password == null || username == null) throw new LoginException("No Username/Password found"); if (password.equals("") || username.equals("")) throw new LoginException("No Username/Password found"); HttpClient client = new HttpClient(); PostMethod method = new PostMethod(FEDORA_JSON_URL); try {/*from ww w .j ava 2 s .co m*/ // Generate the data to send List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new NameValuePair("username", username)); formparams.add(new NameValuePair("user_name", username)); formparams.add(new NameValuePair("password", String.valueOf(password))); formparams.add(new NameValuePair("login", "Login")); method.addParameters(formparams.toArray(new NameValuePair[formparams.size()])); // Send the data and get the response client.executeMethod(method); // Handle the response BufferedReader br = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(method.getResponseBody()))); JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; // Parse the response to check authentication success and valid groups String line; while ((line = br.readLine()) != null) { Map json = (Map) parser.parse(line, containerFactory); if (json.containsKey("success") && json.containsKey("person")) { if (json.get("person") instanceof LinkedHashMap) { LinkedHashMap person = (LinkedHashMap) json.get("person"); if (person.get("status").equals("active")) { if (person.containsKey("approved_memberships")) { if (person.get("approved_memberships") instanceof LinkedList) { if (!checkCLAAgreement(((LinkedList) person.get("approved_memberships")))) { throw new LoginException("FAS authentication failed for " + username + ". Contributor License Agreement not yet signed"); } } else if (person.get("approved_memberships") instanceof LinkedHashMap) { if (!checkCLAAgreement(((LinkedHashMap) person.get("approved_memberships")))) { throw new LoginException("FAS authentication failed for " + username + ". Contributor License Agreement not yet signed"); } } } else { throw new LoginException("FAS authentication failed for " + username + ". Contributor License Agreement not yet signed"); } } else { throw new LoginException( "FAS authentication failed for " + username + ". Account is not active"); } } } else { throw new LoginException("Error: FAS authentication failed for " + username); } } } catch (LoginException e) { throw e; } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } finally { method.releaseConnection(); } return true; }
From source file:org.josso.wls81.agent.mbeans.SSOGatewayLoginModuleImpl.java
/** * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon. * * This method obtains from the gateway, using the provided session identifier, the user associated with * such session identifier.// w w w .j av a2s. c om * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session * identifier. Any other callback type is ignored. * * @return true in all cases since this LoginModule * should not be ignored. * * @exception javax.security.auth.login.FailedLoginException if the authentication fails. * * @exception javax.security.auth.login.LoginException if this LoginModule * is unable to perform the authentication. */ public boolean login() throws LoginException { if (_callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; // Just ask for the session identifier callbacks[0] = new NameCallback("ssoSessionId"); callbacks[1] = new PasswordCallback("password", false); String ssoSessionId; String ssoSessionId2 = null; try { _callbackHandler.handle(callbacks); ssoSessionId = ((NameCallback) callbacks[0]).getName(); if (((PasswordCallback) callbacks[1]).getPassword() != null) ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword()); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } logger.debug("Session requested authentication to gateway : " + ssoSessionId + "/" + ssoSessionId2); try { if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId)) ssoSessionId = ssoSessionId2; // If no session is found, ignore this module. if (ssoSessionId == null) { logger.debug("Session authentication failed : " + ssoSessionId); _succeeded = false; return false; } _currentSSOSessionId = ssoSessionId; SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager(); SSOUser jossoUser = im.findUserInSession(ssoSessionId); WLSJOSSOUser wlsUser = new WLSJOSSOUser(jossoUser); logger.debug("Session authentication succeeded : " + ssoSessionId); _ssoUserPrincipal = wlsUser; _succeeded = true; } catch (SSOIdentityException e) { // Ignore this ... (user does not exist for this session) logger.debug(e.getMessage()); // Only log if debug is enabled ... if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; return false; } catch (Exception e) { logger.error("Session login failed for Principal : " + _ssoUserPrincipal + e.getMessage()); // Only log if debug is enabled ... if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; clearCredentials(); throw new FailedLoginException( "Fatal error authenticating session : " + _ssoUserPrincipal + " : " + e.getMessage()); } return true; }
From source file:edu.ku.brc.af.auth.specify.SpecifySecurityMgr.java
@Override public boolean authenticateDB(final String user, final String pass, final String driverClass, final String url, final String dbUserName, final String dbPwd) throws Exception { Connection conn = null;/*from w w w . ja v a2 s . co m*/ Statement stmt = null; boolean passwordMatch = false; try { Class.forName(driverClass); conn = DriverManager.getConnection(url, dbUserName, dbPwd); String query = "SELECT * FROM specifyuser where name='" + user + "'"; //$NON-NLS-1$ //$NON-NLS-2$ stmt = conn.createStatement(); ResultSet result = stmt.executeQuery(query); String dbPassword = null; while (result.next()) { if (!result.isFirst()) { throw new LoginException("authenticateDB - Ambiguous user (located more than once): " + user); //$NON-NLS-1$ } dbPassword = result.getString(result.findColumn("Password")); //$NON-NLS-1$ if (StringUtils.isNotEmpty(dbPassword) && StringUtils.isAlphanumeric(dbPassword) && UIHelper.isAllCaps(dbPassword) && dbPassword.length() > 20) { dbPassword = Encryption.decrypt(dbPassword, pass); } break; } /*if (dbPassword == null) { throw new LoginException("authenticateDB - Password for User " + user + " undefined."); //$NON-NLS-1$ //$NON-NLS-2$ }*/ if (pass != null && dbPassword != null && pass.equals(dbPassword)) { passwordMatch = true; } // else: passwords do NOT match, user will not be authenticated } catch (java.lang.ClassNotFoundException e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifySecurityMgr.class, e); log.error("authenticateDB - Could not connect to database, driverclass - ClassNotFoundException: "); //$NON-NLS-1$ log.error(e.getMessage()); throw new LoginException("authenticateDB - Database driver class not found: " + driverClass); //$NON-NLS-1$ } catch (SQLException ex) { if (debug) log.error("authenticateDB - SQLException: " + ex.toString()); //$NON-NLS-1$ if (debug) log.error("authenticateDB - " + ex.getMessage()); //$NON-NLS-1$ throw new LoginException("authenticateDB - SQLException: " + ex.getMessage()); //$NON-NLS-1$ } finally { try { if (conn != null) conn.close(); if (stmt != null) stmt.close(); } catch (SQLException e) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifySecurityMgr.class, e); log.error("Exception caught: " + e.toString()); //$NON-NLS-1$ e.printStackTrace(); } } return passwordMatch; }