Package javax.security.auth.login

Examples of javax.security.auth.login.LoginException


     */
    public boolean login() throws LoginException {

        // Set up our CallbackHandler requests
        if (callbackHandler == null)
            throw new LoginException("No CallbackHandler specified");
        Callback callbacks[] = new Callback[2];
        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PasswordCallback("Password: ", false);

        // Interact with the user to retrieve the username and password
        String username = null;
        String password = null;
        try {
            callbackHandler.handle(callbacks);
            username = ((NameCallback) callbacks[0]).getName();
            password =
                new String(((PasswordCallback) callbacks[1]).getPassword());
        } catch (IOException e) {
            throw new LoginException(e.toString());
        } catch (UnsupportedCallbackException e) {
            throw new LoginException(e.toString());
        }

        // Validate the username and password we have received
        principal = super.authenticate(username, password);

View Full Code Here


      if (user != null) {
        subject.getPrincipals().add(new User(user.getName()));
        return true;
      }
      LOG.error("Can't find user in " + subject);
      throw new LoginException("Can't find user name");
    }
View Full Code Here

        }

      });
     
      if(!state.getLeft().getAccountContext().hasPassword(credentials.getRight())){
        throw new LoginException("Bad Password");
      }
     
      Unmarshaller um = AllHTTPJAXBContexts.context.createUnmarshaller();
      HTTPRequest request = (HTTPRequest) um.unmarshal(new InputSource(http.getRequestBody()));
View Full Code Here

  private MutablePlayer player;
 
  public AccountContextImpl(String username, String password) throws LoginException {
    //TODO make login system plugable
    if(username==null || password == null || username.length()==0 || !password.equals("test")){
      throw new LoginException();
    }
    player = PlayerFactory.global_Player_Factory.createNewPlayer(username);
   
  }
View Full Code Here

     */
    public boolean login() throws LoginException {

        // Set up our CallbackHandler requests
        if (callbackHandler == null)
            throw new LoginException("No CallbackHandler specified");
        Callback callbacks[] = new Callback[9];
        callbacks[0] = new NameCallback("Username: ");
        callbacks[1] = new PasswordCallback("Password: ", false);
        callbacks[2] = new TextInputCallback("nonce");
        callbacks[3] = new TextInputCallback("nc");
        callbacks[4] = new TextInputCallback("cnonce");
        callbacks[5] = new TextInputCallback("qop");
        callbacks[6] = new TextInputCallback("realmName");
        callbacks[7] = new TextInputCallback("md5a2");
        callbacks[8] = new TextInputCallback("authMethod");

        // Interact with the user to retrieve the username and password
        String username = null;
        String password = null;
        String nonce = null;
        String nc = null;
        String cnonce = null;
        String qop = null;
        String realmName = null;
        String md5a2 = null;
        String authMethod = null;

        try {
            callbackHandler.handle(callbacks);
            username = ((NameCallback) callbacks[0]).getName();
            password =
                new String(((PasswordCallback) callbacks[1]).getPassword());
            nonce = ((TextInputCallback) callbacks[2]).getText();
            nc = ((TextInputCallback) callbacks[3]).getText();
            cnonce = ((TextInputCallback) callbacks[4]).getText();
            qop = ((TextInputCallback) callbacks[5]).getText();
            realmName = ((TextInputCallback) callbacks[6]).getText();
            md5a2 = ((TextInputCallback) callbacks[7]).getText();
            authMethod = ((TextInputCallback) callbacks[8]).getText();
        } catch (IOException e) {
            throw new LoginException(e.toString());
        } catch (UnsupportedCallbackException e) {
            throw new LoginException(e.toString());
        }

        // Validate the username and password we have received
        if (authMethod == null) {
            // BASIC or FORM
            principal = super.authenticate(username, password);
        } else if (authMethod.equals(org.apache.catalina.authenticator.Constants.DIGEST_METHOD)) {
            principal = super.authenticate(username, password, nonce, nc,
                    cnonce, qop, realmName, md5a2);
        } else if (authMethod.equals(org.apache.catalina.authenticator.Constants.CERT_METHOD)) {
            principal = super.getPrincipal(username);
        } else {
            throw new LoginException("Unknown authentication method");
        }

        log.debug("login " + username + " " + principal);

        // Report results based on success or failure
View Full Code Here

        try {
            SyncHandler handler = getSyncHandler();
            Root root = getRoot();
            UserManager userManager = getUserManager();
            if (root == null || userManager == null) {
                throw new LoginException("Cannot synchronize user.");
            }
            Object smValue = options.getConfigValue(PARAM_SYNC_MODE, null, null);
            SyncMode syncMode;
            if (smValue == null) {
                syncMode = DEFAULT_SYNC_MODE;
            } else {
                syncMode = SyncMode.fromObject(smValue);
            }
            ExternalUser eu = getExternalUser();
            if (eu != null && handler.initialize(userManager, root, syncMode, options)) {
                handler.sync(eu);
                root.commit();
                return true;
            } else {
                log.warn("Failed to initialize sync handler.");
                return false;
            }
        } catch (SyncException e) {
            throw new LoginException("User synchronization failed: " + e);
        } catch (CommitFailedException e) {
            throw new LoginException("User synchronization failed: " + e);
        }
    }
View Full Code Here

                    }
                    updateSubject(tc, getAuthInfo(ti), null);
                } else {
                    // failed to create token -> fail commit()
                    log.debug("TokenProvider failed to create a login token for user " + userId);
                    throw new LoginException("Failed to create login token for user " + userId);
                }
            }
        }
        // the login attempt on this module did not succeed: clear state
        clearState();
View Full Code Here

        boolean success = false;
        try {
            Authorizable authorizable = userManager.getAuthorizable(userId);
            if (authorizable == null || authorizable.isGroup()) {
                throw new LoginException("Unknown user " + userId);
            }

            User user = (User) authorizable;
            if (user.isDisabled()) {
                throw new LoginException("User with ID " + userId + " has been disabled: "+ user.getDisabledReason());
            }

            if (credentials instanceof SimpleCredentials) {
                SimpleCredentials creds = (SimpleCredentials) credentials;
                Credentials userCreds = user.getCredentials();
                if (userId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) {
                    success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword());
                }
                checkSuccess(success, "UserId/Password mismatch.");
            } else if (credentials instanceof ImpersonationCredentials) {
                ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials;
                AuthInfo info = ipCreds.getImpersonatorInfo();
                success = equalUserId(ipCreds) && impersonate(info, user);
                checkSuccess(success, "Impersonation not allowed.");
            } else {
                // guest login is allowed if an anonymous user exists in the content (see get user above)
                success = (credentials instanceof GuestCredentials);
            }
        } catch (RepositoryException e) {
            throw new LoginException(e.getMessage());
        }
        return success;
    }
View Full Code Here

    }

    //--------------------------------------------------------------------------
    private static void checkSuccess(boolean success, String msg) throws LoginException {
        if (!success) {
            throw new LoginException(msg);
        }
    }
View Full Code Here

            //TODO
            env.put(Context.SECURITY_AUTHENTICATION, "simple");
            new InitialDirContext(env).close();
            return true;
        } catch (NamingException e) {
            throw new LoginException("Could not create initial LDAP context for user " + user.getDN() + ": " + e.getMessage());
        }
    }
View Full Code Here

TOP

Related Classes of javax.security.auth.login.LoginException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.