Package org.wso2.carbon.user.core

Examples of org.wso2.carbon.user.core.UserStoreException


    public void updateUserListOfRole(String roleName, String deletedUsers[], String[] newUsers)
            throws UserStoreException {

        if (realmConfig.getEveryOneRoleName().equals(roleName)) {
            throw new UserStoreException("Everyone role is not updatable");
        }

        if (deletedUsers != null) {
            Arrays.sort(deletedUsers);
            if (realmConfig.getAdminRoleName().equals(roleName)
                    && Arrays.binarySearch(deletedUsers, realmConfig.getAdminUserName()) > -1) {
                log.error("An attempt to remove Admin user from Admin role ");
                throw new UserStoreException("Cannot remove Admin user from Admin role");
            }
        }

        if (isReadOnly() == true && hybridRoleManager.isExistingRole(roleName)) {
            hybridRoleManager.updateUserListOfHybridRole(roleName, deletedUsers, newUsers);
        } else {
            String sqlStmt1 = realmConfig
                    .getUserStoreProperty(JDBCRealmConstants.REMOVE_USER_FROM_ROLE);
            if (sqlStmt1 == null) {
                throw new UserStoreException("The sql statement for remove user from role is null");
            }

            Connection dbConnection = null;
            try {
                dbConnection = getDBConnection();
                String type = DatabaseCreator.getDatabaseType(dbConnection);
                String sqlStmt2 = realmConfig
                        .getUserStoreProperty(JDBCRealmConstants.ADD_USER_TO_ROLE + "-" + type);
                if (sqlStmt2 == null) {
                    sqlStmt2 = realmConfig
                            .getUserStoreProperty(JDBCRealmConstants.ADD_USER_TO_ROLE);
                }
                if (sqlStmt2 == null) {
                    throw new UserStoreException("The sql statement for add user to role is null");
                }
                if (deletedUsers != null) {
                    if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
                                deletedUsers, tenantId, roleName, tenantId, tenantId);
                    } else {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
                                deletedUsers, tenantId, roleName);
                    }
                }
                if (newUsers != null) {
                    if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                newUsers, tenantId, roleName, tenantId, tenantId);
                    } else {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                newUsers, tenantId, roleName);
                    }
                }
                dbConnection.commit();
            } catch (SQLException e) {
                log.error(e.getMessage(), e);
                throw new UserStoreException(e.getMessage(), e);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new UserStoreException(e.getMessage(), e);
            } finally {
                DatabaseUtil.closeAllConnections(dbConnection);
            }
        }
    }
View Full Code Here


        if (deletedRoles != null) {
            Arrays.sort(deletedRoles);
            if(Arrays.binarySearch(deletedRoles, realmConfig.getEveryOneRoleName()) > -1){
                log.error("An attempt to remove "+userName+" user from Everyone role ");
                throw new UserStoreException("Everyone role is not updatable");
            }
        }
       
        if (deletedRoles != null) {
            Arrays.sort(deletedRoles);
            if (realmConfig.getAdminUserName().equals(userName)
                    && Arrays.binarySearch(deletedRoles, realmConfig.getAdminRoleName()) > -1) {
                log.error("An attempt to remove Admin user from Admin role ");
                throw new UserStoreException("Cannot remove Admin user from Admin role");
            }
        }

        if (isReadOnly() == true) {
            hybridRoleManager.updateHybridRoleListOfUser(userName, deletedRoles, newRoles);
        } else {
            String sqlStmt1 = realmConfig
                    .getUserStoreProperty(JDBCRealmConstants.REMOVE_ROLE_FROM_USER);
            if (sqlStmt1 == null) {
                throw new UserStoreException("The sql statement for remove user from role is null");
            }
            Connection dbConnection = null;
            try {
                dbConnection = getDBConnection()
                String type = DatabaseCreator.getDatabaseType(dbConnection);
                String sqlStmt2 = realmConfig
                        .getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER + "-" + type);
                if (sqlStmt2 == null) {
                    sqlStmt2 = realmConfig
                            .getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER);
                }
                if (sqlStmt2 == null) {
                    throw new UserStoreException("The sql statement for add user to role is null");
                }

                if (deletedRoles != null) {
                    if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
                                deletedRoles, tenantId, userName, tenantId, tenantId);
                    } else {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
                                deletedRoles, tenantId, userName);
                    }
                }

                if (newRoles != null) {
                    if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                        // System.out.println("" +
                        // DatabaseUtil.getIntegerValueFromDatabase(dbConnection,
                        // sqlStmt, params));
                        // System.out.println("" +
                        // DatabaseUtil.getIntegerValueFromDatabase(dbConnection,
                        // sqlStmt, params));
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                newRoles, tenantId, userName, tenantId, tenantId);
                    } else {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                newRoles, tenantId, userName);
                    }
                }
                dbConnection.commit();
            } catch (SQLException e) {
                log.error(e.getMessage(), e);
                throw new UserStoreException(e.getMessage(), e);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new UserStoreException(e.getMessage(), e);
            } finally {
                DatabaseUtil.closeAllConnections(dbConnection);
            }
        }
    }
View Full Code Here

            String profileName) throws UserStoreException {
        if (profileName == null) {
            profileName = UserCoreConstants.DEFAULT_PROFILE;
        }
        if (claimValue == null) {
            throw new UserStoreException("Cannot set null values.");
        }
        Connection dbConnection = null;
        try {
            dbConnection = getDBConnection();
            ClaimMapping cMapping = (ClaimMapping) claimManager.getClaimMapping(claimURI);
            String property;
            if (cMapping != null) {
                property = cMapping.getMappedAttribute();
            } else {
                property = claimURI;
            }
            String value = getProperty(dbConnection, userName, property, profileName);
            if (value == null) {
                addProperty(dbConnection, userName, property, claimValue, profileName);
            } else {
                updateProperty(dbConnection, userName, property, claimValue, profileName);
            }
            dbConnection.commit();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            throw new UserStoreException(e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
    }
View Full Code Here

                }
            }
            dbConnection.commit();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            throw new UserStoreException(e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
    }
View Full Code Here

            dbConnection = getDBConnection();
            this.deleteProperty(dbConnection, userName, property, profileName);
            dbConnection.commit();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            throw new UserStoreException(e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
    }
View Full Code Here

                this.deleteProperty(dbConnection, userName, property, profileName);
            }
            dbConnection.commit();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } catch (org.wso2.carbon.user.api.UserStoreException e) {
            throw new UserStoreException(e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
    }
View Full Code Here

        if (this.authenticate(userName, oldCredential)) {
            this.updateCredentialByAdmin(userName, newCredential);
        } else {
            log.error("Wrong username/password provided");
            throw new UserStoreException("Wrong username/password provided");
        }
    }
View Full Code Here

                return;
            }
        }

        if (!checkUserPasswordValid(newCredential)) {
            throw new UserStoreException(
                "Credential not valid. Credential must be a non null string with following format, " +
                    realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_JAVA_REG_EX));

        }

        String sqlStmt = realmConfig
                .getUserStoreProperty(JDBCRealmConstants.UPDATE_USER_PASSWORD);
        if (sqlStmt == null) {
            throw new UserStoreException("The sql statement for delete user claim value is null");
        }
        String saltValue = null;
        if ("true".equals(realmConfig.getUserStoreProperties().get(
                JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
            byte[] bytes = new byte[16];
View Full Code Here

                }
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            log.error("Using sql : " + sqlstmt);
            throw new UserStoreException(e.getMessage());
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        }
        return date;
    }
View Full Code Here

            prepStmt = dbConnection.prepareStatement(sqlStmt);
            if (params != null && params.length > 0) {
                for (int i = 0; i < params.length; i++) {
                    Object param = params[i];
                    if (param == null) {
                        throw new UserStoreException("Invalid data provided");
                    } else if (param instanceof String) {
                        prepStmt.setString(i + 1, (String) param);
                    } else if (param instanceof Integer) {
                        prepStmt.setInt(i + 1, (Integer) param);
                    } else if (param instanceof Date) {
                        //Timestamp timestamp = new Timestamp(((Date) param).getTime());
                        //prepStmt.setTimestamp(i + 1, timestamp);
                        prepStmt.setTimestamp(i + 1,new Timestamp(System.currentTimeMillis()));
                    } else if (param instanceof Boolean) {
                        prepStmt.setBoolean(i + 1, (Boolean) param);
                    }
                }
            }
            int count = prepStmt.executeUpdate();
            if(count == 0) {
                log.info("No rows were updated");
            }
            if (log.isDebugEnabled()) {
                log.debug("Executed querry is " + sqlStmt + " and number of updated rows :: "
                        + count);
            }

            if (localConnection) {
                dbConnection.commit();
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            log.error("Using sql : " + sqlStmt);
            throw new UserStoreException(e.getMessage(), e);
        } finally {
            if (localConnection) {
                DatabaseUtil.closeAllConnections(dbConnection);
            }
            DatabaseUtil.closeAllConnections(null, prepStmt);
View Full Code Here

TOP

Related Classes of org.wso2.carbon.user.core.UserStoreException

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.