Examples of UserStoreException


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

        return getProperties((Tenant) tenant);
    }

    public int getTenantId(String username) throws UserStoreException {
        if (this.tenantId != 0) {
            throw new UserStoreException("Not allowed to perform this operation");
        }
        String sqlStmt = realmConfig
                .getUserStoreProperty(JDBCRealmConstants.GET_TENANT_ID_FROM_USERNAME);
        if (sqlStmt == null) {
            throw new UserStoreException("The sql statement for retrieving ID is null");
        }
        int id = -1;
        Connection dbConnection = null;
        try {
            dbConnection = getDBConnection();
            id = DatabaseUtil.getIntegerValueFromDatabase(dbConnection, sqlStmt, username);
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
        return id;
    }
View Full Code Here

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

            }

            return map;
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        }
    }
View Full Code Here

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

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

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

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

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

   
    protected boolean checkExistingUserName(String userName) throws UserStoreException {
        String sqlStmt = realmConfig
                .getUserStoreProperty(JDBCRealmConstants.GET_IS_USER_EXISTING);
        if (sqlStmt == null) {
            throw new UserStoreException("The sql statement for is user existing null");
        }
        boolean isExisting = false;

        String isUnique = realmConfig
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USERNAME_UNIQUE);
View Full Code Here

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

                }
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
            log.error("Using sql : " + sqlstmt);
            throw new UserStoreException("Authentication Failure");
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        }

        if (log.isDebugEnabled()) {
View Full Code Here

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

     */
    private void persistUser(String userName, Object credential, String[] roleList,
                             Map<String, String> claims, String profileName,
                             boolean requirePasswordChange) throws UserStoreException {
        if (!checkUserNameValid(userName)) {
            throw new UserStoreException(
                "User name not valid. User name must be a non null string with following format, " +
                    realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG_EX));

        }

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

        }
       
        boolean isExisting = checkExistingUserName(userName);
        if (isExisting) {
            throw new UserStoreException("User name : " + userName
                    + " exists in the system. Please pick another user name");
        }

        Connection dbConnection = null;
        String password = (String) credential;
        try {
            dbConnection = getDBConnection();
            String sqlStmt1 = realmConfig.getUserStoreProperty(JDBCRealmConstants.ADD_USER);

            String saltValue = null;

            if ("true".equals(realmConfig.getUserStoreProperties().get(
                    JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
                byte[] bytes = new byte[16];
                random.nextBytes(bytes);
                saltValue = Base64.encode(bytes);
            }

            password = this.preparePassword(password, saltValue);

            // do all 4 possibilities
            if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN) && (saltValue == null)) {
                this.updateStringValuesToDatabase(dbConnection, sqlStmt1, userName, password, "",
                        requirePasswordChange, new Date(), tenantId);
            } else if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN) && (saltValue != null)) {
                this.updateStringValuesToDatabase(dbConnection, sqlStmt1, userName, password,
                        saltValue, requirePasswordChange, new Date(), tenantId);
            } else if (!sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)
                    && (saltValue == null)) {
                this.updateStringValuesToDatabase(dbConnection, sqlStmt1, userName, password,
                        null, requirePasswordChange, new Date());
            } else {
                this.updateStringValuesToDatabase(dbConnection, sqlStmt1, userName, password,
                        requirePasswordChange, new Date());
            }

            String[] roles = null;
            if (CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(userName)) {
                roles = new String[0];
            } else {
                if (roleList == null || roleList.length == 0) {
                    roles = new String[] { this.realmConfig.getEveryOneRoleName() };
                } else {
                    Arrays.sort(roleList);
                    if (Arrays.binarySearch(roleList, realmConfig.getEveryOneRoleName()) < 0) {
                        roles = new String[roleList.length + 1];
                        int i = 0;
                        for (i = 0; i < roleList.length; i++) {
                            roles[i] = roleList[i];
                        }
                        roles[i] = realmConfig.getEveryOneRoleName();
                    } else {
                        roles = roleList;
                    }
                }
            }

            // add user to role.
            String sqlStmt2 = null;
            String type = DatabaseCreator.getDatabaseType(dbConnection);
            sqlStmt2 = realmConfig.getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER
                    + "-" + type);
            if (sqlStmt2 == null) {
                sqlStmt2 = realmConfig
                        .getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER);
            }
            if (sqlStmt2.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2, roles,
                        tenantId, userName, tenantId, tenantId);
            } else {
                DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2, roles,
                        tenantId, userName);
            }


            if (claims != null) {
                // add the properties
                if (profileName == null) {
                    profileName = UserCoreConstants.DEFAULT_PROFILE;
                }

                Iterator<Map.Entry<String, String>> ite = claims.entrySet().iterator();
                while (ite.hasNext()) {
                    Map.Entry<String, String> entry = ite.next();
                    String claimURI = entry.getKey();
                    String propName = claimManager.getAttributeName(claimURI);
                    String propValue = entry.getValue();
                    addProperty(dbConnection, userName, propName, propValue, profileName);
                }
            }

            dbConnection.commit();
        } catch (Throwable e) {
          try {
        dbConnection.rollback();
      } catch (SQLException e1) {
              log.error(e.getMessage(), e1);
              throw new UserStoreException(e.getMessage(), e1);
      }
            log.error(e.getMessage(), e);
            throw new UserStoreException(e.getMessage(), e);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection);
        }
    }
View Full Code Here

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

            throws UserStoreException {
        Connection dbConnection = null;
        try {

            if (!roleNameValid(roleName)) {
                throw new UserStoreException(
                    "Role name not valid. Role name must be a non null string with following format, " +
                        realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_ROLE_NAME_JAVA_REG_EX));
            }

            if (isExistingRole(roleName)) {
                throw new UserStoreException(
                        "Role name: "+roleName+" in the system. Please pick another role name.");
            }
            dbConnection = getDBConnection();
            if (isReadOnly() == true) {
                hybridRoleManager.addHybridRole(roleName, userList);
            } else {
                String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.ADD_ROLE);
                if (sqlStmt.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt, roleName, tenantId);
                } else {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt, roleName);
                }
                if (userList != null) {
                    // add role to user
                    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.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                userList, tenantId, roleName, tenantId, tenantId);
                    } else {
                        DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
                                userList, tenantId, roleName);
                    }
                }
            }

            if (permissions != null) {
                for (Permission permission : permissions) {
                    String resourceId = permission.getResourceId();
                    String action = permission.getAction();
                    jdbcUserRealm.getAuthorizationManager().authorizeRole(roleName, resourceId, action);
                }
            }

            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

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

        if (isReadOnly() == true) {
            hybridRoleManager.updateHybridRoleName(roleName, newRoleName);
        } else {
            if (realmConfig.getAdminRoleName().equals(roleName)) {
                throw new UserStoreException("Cannot delete admin role");
            }
            if (realmConfig.getEveryOneRoleName().equals(roleName)) {
                throw new UserStoreException("Cannot delete everyone role");
            }
            if (isExistingRole(newRoleName)) {
                throw new UserStoreException(
                        "Role name: "+newRoleName+" in the system. Please pick another role name.");
            }
            String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.UPDATE_ROLE_NAME);
            if (sqlStmt == null) {
                throw new UserStoreException("The sql statement for update role name is null");
            }           
            Connection dbConnection = null;
            try {

                dbConnection = getDBConnection();
                if (sqlStmt.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt, newRoleName, roleName,
                            tenantId);
                } else {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt, newRoleName, roleName);
                }
                dbConnection.commit();
                this.jdbcUserRealm.getAuthorizationManager().resetPermissionOnUpdateRole(roleName,
                                                                                     newRoleName);               
            } catch (SQLException e) {
                log.error(e.getMessage(), e);
                log.error("Using sql : " + sqlStmt);
                throw new UserStoreException(e.getMessage(), e);
            } finally {
                DatabaseUtil.closeAllConnections(dbConnection);
            }
        }
    }
View Full Code Here

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

    public void deleteRole(String roleName) throws UserStoreException {
        if (isReadOnly() == true && hybridRoleManager.isExistingRole(roleName)) {
            hybridRoleManager.deleteHybridRole(roleName);
        } else {
            if (realmConfig.getAdminRoleName().equals(roleName)) {
                throw new UserStoreException("Cannot delete admin role");
            }

            if (realmConfig.getEveryOneRoleName().equals(roleName)) {
                throw new UserStoreException("Cannot delete everyone role");
            }
            String sqlStmt1 = realmConfig
                    .getUserStoreProperty(JDBCRealmConstants.ON_DELETE_ROLE_REMOVE_USER_ROLE);
            if (sqlStmt1 == null) {
                throw new UserStoreException(
                        "The sql statement for delete user-role mapping is null");
            }

            String sqlStmt2 = realmConfig.getUserStoreProperty(JDBCRealmConstants.DELETE_ROLE);
            if (sqlStmt2 == null) {
                throw new UserStoreException("The sql statement for delete role is null");
            }

            Connection dbConnection = null;
            try {
                dbConnection = getDBConnection();
                if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt1, roleName, tenantId,
                            tenantId);
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt2, roleName, tenantId);
                } else {
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt1, roleName);
                    this.updateStringValuesToDatabase(dbConnection, sqlStmt2, roleName);
                }
                this.jdbcUserRealm.getAuthorizationManager().clearRoleAuthorization(roleName);
                dbConnection.commit();
            } catch (SQLException e) {
                log.error(e.getMessage(), e);
                log.error("Using sql : " + sqlStmt1);
                throw new UserStoreException(e.getMessage(), e);
            } finally {
                DatabaseUtil.closeAllConnections(dbConnection);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.