public boolean login()

in jaas/jaas-modules/src/main/java/org/apache/servicemix/kernel/jaas/modules/osgi/OsgiConfigLoginModule.java [57:104]


    public boolean login() throws LoginException {
        try {
            String pid = (String) options.get(PID);
            Configuration config = ConfigAdminHolder.getService().getConfiguration(pid);
            Dictionary properties = config.getProperties();

            Callback[] callbacks = new Callback[2];

            callbacks[0] = new NameCallback("Username: ");
            callbacks[1] = new PasswordCallback("Password: ", false);
            try {
                callbackHandler.handle(callbacks);
            } catch (IOException ioe) {
                throw new LoginException(ioe.getMessage());
            } catch (UnsupportedCallbackException uce) {
                throw new LoginException(uce.getMessage() + " not available to obtain information from user");
            }
            String user = ((NameCallback) callbacks[0]).getName();
            char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
            if (tmpPassword == null) {
                tmpPassword = new char[0];
            }

            String userInfos = (String) properties.get(USER_PREFIX + user);
            if (userInfos == null) {
                throw new FailedLoginException("User does not exist");
            }
            String[] infos = userInfos.split(",");
            if (!new String(tmpPassword).equals(infos[0])) {
                throw new FailedLoginException("Password does not match");
            }

            principals = new HashSet<Principal>();
            principals.add(new UserPrincipal(user));
            for (int i = 1; i < infos.length; i++) {
                principals.add(new RolePrincipal(infos[i]));
            }

            return true;
        } catch (LoginException e) {
            throw e;
        } catch (Exception e) {
            throw (LoginException) new LoginException("Unable to authenticate user").initCause(e);
        } finally {
            callbackHandler = null;
            options = null;
        }
    }