首页 \ 问答 \ 如何以编程方式配置bean验证?(How to configure bean validation programatically?)

如何以编程方式配置bean验证?(How to configure bean validation programatically?)

我想使用bean验证的代码:

@Inject
private ValidatorFactory validatorFactory;
....

public Response create(@Context HttpServletRequest request) {
        ...
        Set<ConstraintViolation<UserDTO>> validate = validatorFactory.getValidator().validate(userDTO);
        validate.forEach(error-> System.err.println(error.getMessage()));
        if(validate.size() > 0){
            throw new ValidationException("userDTO is not valid!");
        }
        ...
}


public Response update(@Context HttpServletRequest request) {
        Set<ConstraintViolation<UserDTO>> validate = validatorFactory.getValidator().validate(userDTO);
        validate.forEach(error-> System.err.println(error.getMessage()));
        if(validate.size() > 0){
            throw new ValidationException("userDTO is not valid!");
        }
        ...
}

UserDTO:

public class UserDTO {
    private Integer id;
    private String userName;
    @NotNull(message = "is missing")
    private String locked;
    @Email(message = "email is not valid")
    private String email;
    @NotNull(message = "countryCode is missing")
    private String countryCode;
    ...getters-setters more variables...
}

所以我有一个后Http方法,我想创建一个用户... bean验证工作,如果缺少国家代码或锁定确定或如果电子邮件无效确定...但当我想只更新例如电子邮件验证也是运行在整个dto类...所以问题是我可以和我如何配置不每次运行每个变量?


Codes where i want to use bean validation:

@Inject
private ValidatorFactory validatorFactory;
....

public Response create(@Context HttpServletRequest request) {
        ...
        Set<ConstraintViolation<UserDTO>> validate = validatorFactory.getValidator().validate(userDTO);
        validate.forEach(error-> System.err.println(error.getMessage()));
        if(validate.size() > 0){
            throw new ValidationException("userDTO is not valid!");
        }
        ...
}


public Response update(@Context HttpServletRequest request) {
        Set<ConstraintViolation<UserDTO>> validate = validatorFactory.getValidator().validate(userDTO);
        validate.forEach(error-> System.err.println(error.getMessage()));
        if(validate.size() > 0){
            throw new ValidationException("userDTO is not valid!");
        }
        ...
}

UserDTO:

public class UserDTO {
    private Integer id;
    private String userName;
    @NotNull(message = "is missing")
    private String locked;
    @Email(message = "email is not valid")
    private String email;
    @NotNull(message = "countryCode is missing")
    private String countryCode;
    ...getters-setters more variables...
}

So i have a post Http method where i want to create a user...bean validation is working if missing countrycode or locked ok or if email not valid ok...But when i want to just update for example email the validation is also run on the whole dto class...so the question is can i and how can i configure not to run on every variable each time?


原文:https://stackoverflow.com/questions/44967217
更新时间:2023-02-17 21:02

最满意答案

对于Oracle至少,不,创建数据库用户不会创建操作系统用户。 您可以拥有一个外部认证的数据库用户(传统上使用像ops$这样的公共前缀定义,例如ops$osuser尽管这不是必需的 ),但仍然必须单独创建匹配的OS用户。 因此,您可以让操作系统和数据库中都存在用户,但操作系统用户不是由database create user命令create user

除了这种情况,为什么这是一个有用或明智的事情呢? 这也意味着Oracle帐户必须拥有这样做的权限,即root权限或管理员权限,这将是一个潜在危险的权限提升漏洞; 并且必须进行协调,例如,您无法创建具有与现有OS用户匹配的ID的数据库用户。

我无法想象DB2会创建一个OS用户,但我不确定; 我没有这方面的经验,所以其他人需要回答那个部分......


For Oracle at least, no, creating a database user does not create an operating system user. You can have an externally-authenticated database user (traditionally defined with a common prefix like ops$, e.g. ops$osuser, though that isn't necessary), but the matching OS user still has to be created separately. So you can have a user that exists in both the OS and database, but the OS user is not created by the database create user command.

Aside from that situation, why would it be a useful or sensible thing to do? It would also mean the Oracle account had to have permission to do so, i.e root or administrator privs, which would be a potentially dangerous privilege escalation hole; and would have to coordinate so that, for example, you couldn't create a database user with an ID matching an existing OS user.

I can't imagine DB2 would create an OS user either, but I don't know for sure; I have no experience of that so someone else will need to answer that part...

相关问答

更多
  • 您的连接详细信息确定在展开连接树时将浏览的SCHEMA。 其他用户节点允许您浏览其他模式。 您的连接用户权限将决定您在其他模式中可以或不可以看到的内容。 数据库对象由单个用户拥有,或存在于单个模式中(实际上是用户拥有的对象集合。)没有共享对象。 Your connection details determines which SCHEMA you will be browsing when you expand the connection tree. The other users node allows ...
  • 存在不同的选项,可以根据您的安全模型和操作要求混合使用。 这是一个很大的话题。 有关CREATE ROLE和GRANT和REVOKE语句的详细信息,请参阅Db2文档,并计划您将使用ROLES还是USERS / GROUPS或两者都使用 Different options exist, can be mixed depending on your security model and operational requirements. This is a large topic. Refer to the D ...
  • 在publib上的DB2 / z 9.1文档中有一个用于ODBC访问DB2 / z的特定部分 。 Publib应始终是任何IBM doco的第一个调用点。 还有DB2 / z ODBC PDF 。 这是从OE / OMVS / USS上的C(或者现在称之为的任何东西)访问DB2 / z的最佳方式。 如果它是Java,我可能会帮助更多。 在线帮助对于让JRE与大型机DB2(来自USS和PC)进行通信非常有价值,而对本地sysprog的麻烦最小。 当然,使用它们会更容易:-)尤其是在设置z / OS(非USS) ...
  • 要对域进行身份验证,DB2 Service(实例)必须使用域帐户运行 - 无法使用本地计算机上定义的帐户启动它。 您可以停止实例,然后从Windows服务面板更改DB2服务以开始使用域ID。 确保此域ID具有足够的权限,如此处所述 。 To authenticate against the domain, the DB2 Service (instance) must be running using a domain account - it can't be started using an accou ...
  • 您无法使用DB2帐户访问SAP应用程序。 SAP用户被定义,信息被存储在usr02表中。 db2用户在操作系统或数据库使用的认证工具中定义。 根据数据访问设置,您可以使用DB2实例用户访问SAP数据。 You cannot access the SAP application using the DB2 accounts. SAP users are defined and the information is stored amongst others in the usr02 table. The db ...
  • 对于Oracle至少,不,创建数据库用户不会创建操作系统用户。 您可以拥有一个外部认证的数据库用户(传统上使用像ops$这样的公共前缀定义,例如ops$osuser , 尽管这不是必需的 ),但仍然必须单独创建匹配的OS用户。 因此,您可以让操作系统和数据库中都存在用户,但操作系统用户不是由database create user命令create user 。 除了这种情况,为什么这是一个有用或明智的事情呢? 这也意味着Oracle帐户必须拥有这样做的权限,即root权限或管理员权限,这将是一个潜在危险的权 ...
  • 这是一个基本的PIVOT查询: SELECT USER_ID, SUM( CASE MGD_TYPE WHEN 'FX' THEN MTHLY_AMT END ) As FX_AMT, SUM( CASE MGD_TYPE WHEN 'REAL_ESTATE' THEN MTHLY_AMT END ) As REAL_EST_AMT, SUM( CASE MGD_TYPE WHEN 'MERGERS' THEN MTHLY_AMT END ) As MERGERS_AM ...
  • DB2支持团队已针对此问题打开了一个缺陷。 应在下一版本中提供修复程序。 有关详细信息,请参阅developerWorks上的帖子, 网址为https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014927797#repliesPg=1 。 DB2 support team has opened a defect for this issue. A fix should be ...
  • odbc设置实际上在db2cli.ini中的db2客户端中 The odbc settings are actually in db2 client in db2cli.ini
  • 我找不到任何解决这个问题的方法。 我最终做的是找出“Tree”和“Array”类型的安全组件,列出它们的组件,并在Java中重构等效树。 1)找出授予用户的标签 SELECT A.grantee ,B.secpolicyname ,c.seclabelname FROM syscat.securitylabelaccess A ,syscat.securitypolicies B ,syscat.securitylabels C WHERE A.seclabeli ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)