CPD Results

The following document contains the results of PMD's CPD 4.2.2.

Duplications

File Line
org/abstracthorizon/danube/auth/jaas/keystore/KeyStoreModuleService.java 115
org/abstracthorizon/danube/auth/jaas/memory/PropertiesModuleService.java 100
        AppConfigurationEntry entry = new AppConfigurationEntry(PropertiesLoginModule.class.getName(), flag, options);

        AppConfigurationEntry[] list = new AppConfigurationEntry[1];
        list[0] = entry;
        Method method = configuration.getClass().getMethod("setAppConfigurationEntry", new Class[]{String.class, list.getClass()});
        Object[] args = {loginContext, list};
        method.invoke(configuration, args);
        logger.info("Set up login context '" + loginContext + "'");
    }


    public void stop() throws Exception {
        Method method = configuration.getClass().getMethod("removeAppConfigurationEntry", new Class[]{String.class});
        Object[] args = {loginContext};
        method.invoke(configuration, args);
        logger.info("Removed login context '" + loginContext + "'");
    }

    /**
     * Lists certificates (users) from the keystore
     * @return users as a string
     * @throws Exception
     */
    public String listUsersString() throws Exception {
        List<String> u = listUsers();
        String[] users = new String[u.size()];
        users = (String[])u.toArray(users);

        StringBuffer res = new StringBuffer();
        res.append("[");
        for (int i=0; i<users.length; i++) {
            if (i > 0) {
                res.append(", ");
            }
            res.append(users[i]);
        }
        res.append("]");
        return res.toString();
    }

    /**
     * Returns a list of all users in the keystore
     * @return list of all users in the keystore
     * @throws Exception
     */
    public List<String> listUsers() throws Exception {

File Line
org/abstracthorizon/danube/auth/jaas/keystore/KeyStoreLoginModule.java 190
org/abstracthorizon/danube/auth/jaas/memory/PropertiesLoginModule.java 140
            obtainCertificates();
            status = AUTHENTICATED;
            return true;
        }

        throw new LoginException("The login module is not initialized");
    }

    /**
     * This method obtains username and password from the party that tries to log in
     * @throws LoginException
     */
    private void obtainAuthenticationDetails() throws LoginException {
        TextOutputCallback bannerCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "Please login to keystore");
        NameCallback aliasCallback = new NameCallback("Keystore alias: ");
        PasswordCallback privateKeyPasswordCallback = new PasswordCallback("Password: ", false);
        ConfirmationCallback confirmationCallback = new ConfirmationCallback(ConfirmationCallback.INFORMATION, ConfirmationCallback.OK_CANCEL_OPTION,
                ConfirmationCallback.OK);
        try {
            callbackHandler.handle(
                    new Callback[]{
                            bannerCallback,
                            aliasCallback,
                            privateKeyPasswordCallback,
                            confirmationCallback}
                );
        } catch (IOException e) {
            throw new LoginException("Exception while getting keystore alias and password: " + e);
        } catch (UnsupportedCallbackException e) {
            throw new LoginException("Error: " + e.getCallback().toString() + " is not available to retrieve authentication "
                    + " information from the user");
        }

        int confirmationResult = confirmationCallback.getSelectedIndex();
        if (confirmationResult == ConfirmationCallback.CANCEL) {
            throw new LoginException("Login cancelled");
        }

        username = aliasCallback.getName();

        char[] tmpPassword = privateKeyPasswordCallback.getPassword();
        userPassword = new char[tmpPassword.length];
        System.arraycopy(tmpPassword, 0, userPassword, 0, tmpPassword.length);
        for (int i = 0; i < tmpPassword.length; i++) {

File Line
org/abstracthorizon/danube/auth/jaas/keystore/KeyStoreLoginModule.java 322
org/abstracthorizon/danube/auth/jaas/memory/PropertiesLoginModule.java 250
                subject.getPrincipals().addAll(principals);
                subject.getPublicCredentials().add(publicCredentials);
                subject.getPrivateCredentials().add(privateCredential);
                status = LOGGED_IN;
                return true;
            }
        }
        if (status == INITIALIZED) {
            logoutImpl();
            throw new LoginException("Authentication failed");
        }

        throw new LoginException("The login module is not initialized");
    }

    /**
     * Aborts login
     * @return <code>true</code> if successful
     */
    public boolean abort() throws LoginException {
        if ((status == AUTHENTICATED) || (status == LOGGED_IN)) {
            logoutImpl();
            return true;
        }

        return false;
    }

    /**
     * Logs out
     * @return <code>true</code> if successful
     */
    public boolean logout() throws LoginException {
        if (status == LOGGED_IN) {
            logoutImpl();
            return true;
        }

        return false;
    }

    /**
     * Internal log out method
     * @throws LoginException
     */
    private void logoutImpl() throws LoginException {
        for (int i = 0; i < userPassword.length; i++) {
            userPassword[i] = '\0';
        }
        userPassword = null;

        if (subject.isReadOnly()) {

File Line
org/abstracthorizon/danube/auth/jaas/keystore/KeyStoreModuleService.java 94
org/abstracthorizon/danube/auth/jaas/memory/PropertiesModuleService.java 77
    public PropertiesModuleService() {
    }

    /**
     * Starts the service - adding keystore login module to system application configuration entry
     * @throws Exception
     */
    public void start() throws Exception {

        AppConfigurationEntry.LoginModuleControlFlag flag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;

        if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.toString().indexOf(controlFlag) > 0 ) {
            flag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
        } else if( AppConfigurationEntry.LoginModuleControlFlag.REQUISITE.toString().indexOf(controlFlag) > 0 ) {
            flag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
        } else if( AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT.toString().indexOf(controlFlag) > 0 ) {
            flag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
        }else if( AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL.toString().indexOf(controlFlag) > 0 ) {
            flag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
        }

File Line
org/abstracthorizon/danube/auth/jaas/keystore/KeyStoreLoginModule.java 374
org/abstracthorizon/danube/auth/jaas/memory/PropertiesLoginModule.java 302
            principals = null;
            publicCredentials = null;
            status = INITIALIZED;

            Iterator<Object> it = subject.getPrivateCredentials().iterator();
            while (it.hasNext()) {
                Object obj = it.next();
                if (privateCredential.equals(obj)) {
                    privateCredential = null;
                    try {
                        ((Destroyable) obj).destroy();
                        break;
                    } catch (DestroyFailedException dfe) {
                        throw new LoginException("Unable to destroy private credential, " + obj.getClass().getName() + ": " + dfe.getMessage());
                    }
                }
            }

            throw new LoginException("Unable to remove Principal (X500Principal) and public credential from read-only Subject");
        }
        
        
        if (principals != null) {