如何以编程方式配置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
最满意答案
对于Oracle至少,不,创建数据库用户不会创建操作系统用户。 您可以拥有一个外部认证的数据库用户(传统上使用像
ops$
这样的公共前缀定义,例如ops$osuser
, 尽管这不是必需的 ),但仍然必须单独创建匹配的OS用户。 因此,您可以让操作系统和数据库中都存在用户,但操作系统用户不是由databasecreate 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 databasecreate 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 ...
-
云上的IBM Db2 Warehouse管理用户对模式的访问(IBM Db2 Warehouse on Cloud manage user access to schemas)[2024-03-12]
存在不同的选项,可以根据您的安全模型和操作要求混合使用。 这是一个很大的话题。 有关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中的数据库特权授予其他Domain用户(How to grant database privileges in DB2 to other Domain users)[2022-05-22]
要对域进行身份验证,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 ... -
SAP上的DB2用户(DB2 Users on SAP)[2022-07-25]
您无法使用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权限或管理员权限,这将是一个潜在危险的权 ...
-
DB2 SQL聚合(DB2 SQL Aggregation)[2023-10-04]
这是一个基本的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 ...