List of usage examples for javax.security.auth.login LoginException LoginException
public LoginException(String msg)
From source file:org.apache.nifi.security.krb.StandardKeytabUser.java
/** * Performs a login using the specified principal and keytab. * * @throws LoginException if the login fails *///w ww . j a v a 2s .co m @Override public synchronized void login() throws LoginException { if (isLoggedIn()) { return; } try { // If it's the first time ever calling login then we need to initialize a new context if (loginContext == null) { LOGGER.debug("Initializing new login context..."); this.subject = new Subject(); final Configuration config = new KeytabConfiguration(principal, keytabFile); this.loginContext = new LoginContext("KeytabConf", subject, null, config); } loginContext.login(); loggedIn.set(true); LOGGER.debug("Successful login for {}", new Object[] { principal }); } catch (LoginException le) { throw new LoginException( "Unable to login with " + principal + " and " + keytabFile + " due to: " + le.getMessage()); } }
From source file:org.adeptnet.auth.kerberos.Krb5.java
public String isTicketValid(String spn, byte[] ticket) { checkCreds();//from w ww.j a v a 2 s. c o m LoginContext ctx = null; try { if (!config.getKeytab().exists()) { throw new LoginException( String.format("KeyTab does not exist: %s", config.getKeytab().getAbsolutePath())); } final Principal principal = new KerberosPrincipal(spn, KerberosPrincipal.KRB_NT_SRV_INST); Set<Principal> principals = new HashSet<>(); principals.add(principal); final Subject subject = new Subject(false, principals, new HashSet<>(), new HashSet<>()); ctx = new LoginContext(config.getContextName(), subject, null, getJaasKrb5TicketCfg(spn)); ctx.login(); final Krb5TicketValidateAction validateAction = new Krb5TicketValidateAction(ticket, spn); final String username = Subject.doAs(subject, validateAction); return username; } catch (java.security.PrivilegedActionException | LoginException e) { LOG.fatal(spn, e); } finally { try { if (ctx != null) { ctx.logout(); } } catch (LoginException e2) { LOG.fatal(spn, e2); } } return FAILED; }
From source file:org.transdroid.search.BitHdtv.BitHdtvAdapter.java
private HttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.BitHdtv); String password = SettingsHelper.getSitePass(context, TorrentSite.BitHdtv); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/*from www. ja v a 2s .co m*/ // First log in HttpClient httpclient = HttpHelper.buildDefaultSearchHttpClient(false); HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(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 BitHdTv with user " + username); } String loginHtml = HttpHelper.convertStreamToString(loginResult.getEntity().getContent()); final String LOGIN_ERROR = "Login failed!"; if (loginHtml == null || loginHtml.contains(LOGIN_ERROR)) { // Failed to sign in throw new LoginException("Login failure for BitHdTv with user " + username); } return httpclient; }
From source file:org.sakaiproject.jcr.jackrabbit.sakai.SakaiLoginModule.java
/** * {@inheritDoc}//from w w w . j a v a2 s .c o m */ @SuppressWarnings("unchecked") public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) { throw new LoginException("no CallbackHandler available"); } if (userDirectoryService == null) { userDirectoryService = getUserDirectoryService(); } if (authenticationManager == null) { authenticationManager = getAuthenticationManager(); } boolean authenticated = false; principals.clear(); try { // Get credentials using a JAAS callback CredentialsCallback ccb = new CredentialsCallback(); callbackHandler.handle(new Callback[] { ccb }); Credentials creds = ccb.getCredentials(); // Use the credentials to set up principals if (creds != null) { if (creds instanceof SimpleCredentials) { SimpleCredentials sc = (SimpleCredentials) creds; // authenticate User u = null; try { Authentication auth = authenticationManager .authenticate(new IdPwEvidence(sc.getUserID(), new String(sc.getPassword()))); u = userDirectoryService.getUser(auth.getUid()); } catch (NullPointerException e) { u = null; } catch (AuthenticationException e) { u = null; } catch (UserNotDefinedException e) { u = null; } // old way used UDS directly, no caching, new way above gets cached -AZ // User u = userDirectoryService.authenticate(sc.getUserID(), // new String(sc.getPassword())); if (u == null) { principals.add(new JCRAnonymousPrincipal(SAKAI_ANON_USER)); } else { principals.add(new SakaiUserPrincipalImpl(u)); } authenticated = true; } else if (creds instanceof SakaiJCRCredentials) { principals.add(new JCRSystemPrincipal(SAKAI_SYSTEM_USER)); authenticated = true; } } else { // authenticated via Session or Sakai Wrapper User u = userDirectoryService.getCurrentUser(); if (u == null) { principals.add(new JCRAnonymousPrincipal(SAKAI_ANON_USER)); } else { principals.add(new SakaiUserPrincipalImpl(u)); } authenticated = true; } } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException(uce.getCallback().toString() + " not available"); } if (authenticated) { return !principals.isEmpty(); } else { principals.clear(); throw new FailedLoginException(); } }
From source file:de.ingrid.admin.security.AbstractLoginModule.java
@Override public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("user name:"); PasswordCallback passwordCallback = new PasswordCallback("password:", false); try {/*from ww w . j a v a 2 s .com*/ _callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); String name = nameCallback.getName(); char[] password = passwordCallback.getPassword(); if (name != null) { if (password != null) { IngridPrincipal ingridPrincipal = authenticate(name, new String(password)); if (ingridPrincipal.isAuthenticated()) { setAuthenticated(true); _currentPrincipal = ingridPrincipal; } } } } catch (Exception e) { LOG.error("login failed.", e); throw new LoginException(e.getMessage()); } return isAuthenticated(); }
From source file:org.transdroid.search.HoundDawgs.HoundDawgsAdapter.java
private HttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.HoundDawgs); String password = SettingsHelper.getSitePass(context, TorrentSite.HoundDawgs); 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 v a 2 s . c o m*/ // Setup http client HttpClient httpclient = HttpHelper.buildDefaultSearchHttpClient(false); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("username", username), new BasicNameValuePair("password", password), new BasicNameValuePair("Login", "login")))); HttpResponse loginResult = httpclient.execute(loginPost); String loginHtml = HttpHelper.convertStreamToString(loginResult.getEntity().getContent()); final String LOGIN_ERROR = "<li><a href=\"login.php\">Login</a></li>"; if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK || loginHtml.indexOf(LOGIN_ERROR) >= 0) { // Failed to sign in throw new LoginException("Login failure for HoundDawgs with user " + username); } return httpclient; }
From source file:com.hs.mail.security.login.JndiLoginModule.java
@Override protected Principal[] validate(Callback[] callbacks) throws LoginException { String username = ((NameCallback) callbacks[0]).getName(); char[] password = ((PasswordCallback) callbacks[1]).getPassword(); Principal[] principals = new Principal[1]; principals[0] = new UserPrincipal(username); try {//from w ww.ja va 2 s .co m boolean ok = authenticate(username, String.valueOf(password)); if (!ok) throw new CredentialException("Incorrect password for " + username); else return principals; } catch (Exception e) { throw (LoginException) new LoginException("LDAP Error").initCause(e); } }
From source file:com.redhat.topicindex.security.FedoraAccountSystem.java
public boolean login() throws LoginException { if (callbackHandler == null) throw new LoginException("No CallbackHandler available"); NameCallback nameCallback = new NameCallback("Username"); PasswordCallback passwordCallback = new PasswordCallback("Password", false); Callback[] callbacks = new Callback[] { nameCallback, passwordCallback }; try {//ww w . j a v a2s . co m callbackHandler.handle(callbacks); username = nameCallback.getName(); password = passwordCallback.getPassword(); passwordCallback.clearPassword(); } catch (IOException e) { throw new LoginException(e.toString()); } catch (UnsupportedCallbackException e) { throw new LoginException("Error: " + e.getCallback().toString() + "not available"); } if (authenticate()) { loginSucceeded = true; } else { return false; } return true; }
From source file:org.transdroid.search.TorrentDay.TorrentDayAdapter.java
private DefaultHttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.TorrentDay); String password = SettingsHelper.getSitePass(context, TorrentSite.TorrentDay); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }//w ww .ja v a 2s .c o m // Setup http client 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("username", username), new BasicNameValuePair("password", password) }))); HttpResponse loginResult = httpclient.execute(loginPost); if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { // Failed to sign in throw new LoginException("Login failure for TorrentDay with user " + username); } return httpclient; }
From source file:org.transdroid.search.Danishbits.DanishbitsAdapter.java
private HttpClient prepareRequest(Context context) throws Exception { String username = SettingsHelper.getSiteUser(context, TorrentSite.Danishbits); String password = SettingsHelper.getSitePass(context, TorrentSite.Danishbits); if (username == null || password == null) { throw new InvalidParameterException( "No username or password was provided, while this is required for this private site."); }/* w w w. ja v a2s .co m*/ // Setup http client HttpClient httpclient = HttpHelper.buildDefaultSearchHttpClient(false); // First log in HttpPost loginPost = new HttpPost(LOGINURL); loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("username", username), new BasicNameValuePair("password", password), new BasicNameValuePair("Login", "login")))); HttpResponse loginResult = httpclient.execute(loginPost); String loginHtml = HttpHelper.convertStreamToString(loginResult.getEntity().getContent()); final String LOGIN_ERROR = "<form id=\"loginform\" method=\"post\" action=\"login.php\">"; if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK || loginHtml.indexOf(LOGIN_ERROR) >= 0) { // Failed to sign in throw new LoginException("Login failure for HoundDawgs with user " + username); } return httpclient; }