小编Pet*_*man的帖子

关于hibernate stalestateException的最佳更新策略

我们正在使用带有乐观锁定的hibernate.我们所有的实体都有@version注释.

这很好,如果用户试图保存一个陈旧的对象,我们会得到一个stalestateexception.在我们的例子中,我们希望为用户提供一个通知屏幕,以丢弃他的更改或覆盖数据库中的当前值.

这是陈旧状态异常的常见用例.我的问题与此用例有关.如果用户决定用他的更改覆盖当前数据库行,那么最佳策略是什么?我已经浏览了hibernate参考指南和不同的网站,但所有提到的事实是你必须自己捕获stalestateexception然后programmaticaly处理数据的覆盖.我想知道hibernate是否有一些实用程序来简化这个策略,如果用户决定用他的数据覆盖从数据库中检索实体的最后一个版本然后将所有更改的字段复制到此对象,我可以忍受的最简单的事情然后将更改的对象保存回数据库.但我不禁想知道是否有更优雅的解决方案.

state hibernate version

6
推荐指数
1
解决办法
1982
查看次数

Spring启动:使用oauth2保护api端点,同时拥有mvc UI页面

我正在尝试使用标准登录的spring-boot mvc应用程序,同时使用oAuth2安全性公开一些API端点.基本上我的要求如下:

如果用户点击主页("/"),请检查它是否经过身份验证.如果没有显示登录表单,则显示主页.但是,用户还应该能够请求oauth身份验证令牌,并使用该令牌access/api/assignment/{id}.

我可以让标准登录工作,我可以让oauth2工作,但我不能让他们一起工作.

这是我目前的配置:

WebSecurityConfig

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private DataSource dataSource;

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);        
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {    
        auth.jdbcAuthentication().dataSource(this.dataSource).passwordEncoder(new BCryptPasswordEncoder());
    }
}
Run Code Online (Sandbox Code Playgroud)

OAuth2Config

@Configuration
@EnableResourceServer
@EnableAuthorizationServer
public class OAuth2Config {

protected static final String RESOURCE_ID = "oauthdemo";

@Configuration
@EnableResourceServer
protected static class ResourceServer extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-security oauth-2.0 spring-boot

5
推荐指数
1
解决办法
1211
查看次数

列出了 Firebase 重定向域,但仍然出现 signInWithRedirect 错误

我有一个使用 firebase 进行身份验证的 angular 2 应用程序。我想使用 Google 作为我的身份验证提供程序,并设置好所有内容以使其正常工作。

如果我尝试使用 signinWithPopup 进行身份验证(如文档中所述),它会起作用:

firebase.auth().signInWithPopup(provider).then(function(result) {
  // This gives you a Google Access Token. You can use it to access the Google API.
  var token = result.credential.accessToken;
  // The signed-in user info.
  var user = result.user;
  // ...
}).catch(function(error) {
  // Handle Errors here.
});
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用重定向尝试相同的代码,则会firebase.auth().signInWithRedirect(provider) 收到错误消息:

[firebase-auth] 信息:当前域未被授权进行 OAuth 操作。这将阻止 signInWithPopup、signInWithRedirect、linkWithPopup 和 linkWithRedirect 工作。将您的域 (localhost) 添加到 Firebase 控制台 -> 身份验证部分 -> 登录方法选项卡中的 OAuth 重定向域列表。

但是该域在我的 firebase 控制台中列出(本地主机甚至是默认允许的域之一)。并且错误指出这也会阻止仍然有效的 signinwithpopup。

任何人都知道为什么弹出方法有效而重定向方法无效?

google-authentication firebase firebase-authentication angular

5
推荐指数
1
解决办法
1745
查看次数