小编fye*_*lci的帖子

Spring数据国际化最佳实践

我有一个带有spring数据,jpa和hibernate的spring mvc项目.我有一个多语言数据库.我设计了我的数据库和实体.我正在寻找一种按语言查询表格的最佳实践.我是否必须编写自定义jpa查询,或者是否有通用的方法来查询我的表.

如果我在db或实体设计上有错误,请警告我.

数据库:

CREATE TABLE translation (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (id));

CREATE TABLE translation_text (
  translation_id BIGINT UNSIGNED NOT NULL,
  lang VARCHAR(2),
  text VARCHAR(1000));

ALTER TABLE translation_text
ADD FOREIGN KEY (translation_id)
REFERENCES translation(id);

CREATE TABLE category (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  category_name BIGINT UNSIGNED NOT NULL,
  PRIMARY KEY (id));

ALTER TABLE category
ADD FOREIGN KEY (category_name)
REFERENCES translation(id);
Run Code Online (Sandbox Code Playgroud)

LocalizedString实体:

@Embeddable
public class LocalizedString {

    private String lang;
    private String text;

    //Constructors and …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-data

14
推荐指数
1
解决办法
1921
查看次数

对于经过身份验证且未经过身份验证的用户,Spring Security会在休息服务中获取用户信息

我有一个Spring rest服务,我想将它用于经过身份验证且未经过身份验证的用户.我想从SecurityContextHolder.getContext().getAuthentication()用户身份验证中获取用户信息.

  • 如果我 .antMatchers("/app/rest/question/useroperation/list/**").permitAll() 在下面的ouath2配置中使用,那么我可以获得经过身份验证的用户的用户信息,但是对于未经过身份验证的用户,我会收到401错误.
  • 如果我 在下面.antMatchers("/app/rest/question/useroperation/list/**").permitAll() 忽略了WebSecurity中的url ,那么所有用户都可以调用该服务,但是我无法从SecurityContext获取用户信息.web.ignoring()..antMatchers("/app/rest/question/useroperation/list/**")SecurityConfiguration

如果用户登录,如何配置我的spring安全性来为经过身份验证且未经过身份验证的用户调用URL并从SecurityContext获取用户信息.

@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

    @Inject
    private Http401UnauthorizedEntryPoint authenticationEntryPoint;

    @Inject
    private AjaxLogoutSuccessHandler ajaxLogoutSuccessHandler;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .exceptionHandling()
                .authenticationEntryPoint(authenticationEntryPoint)
                .and()
                .logout()
                .logoutUrl("/app/logout")
                .logoutSuccessHandler(ajaxLogoutSuccessHandler)
                .and()
                .csrf()
                .requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize"))
                .disable()
                .headers()
                .frameOptions().disable()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .antMatchers("/views/**").permitAll()
                .antMatchers("/app/rest/authenticate").permitAll()
                .antMatchers("/app/rest/register").permitAll()
                .antMatchers("/app/rest/question/useroperation/list/**").permitAll()
                .antMatchers("/app/rest/question/useroperation/comment/**").authenticated()
                .antMatchers("/app/rest/question/useroperation/answer/**").authenticated()
                .antMatchers("/app/rest/question/definition/**").hasAnyAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/app/rest/logs/**").hasAnyAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/app/**").authenticated()
                .antMatchers("/websocket/tracker").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/websocket/**").permitAll()
                .antMatchers("/metrics/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/health/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/dump/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/shutdown/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/beans/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/info/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/autoconfig/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/env/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
                .antMatchers("/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN) …
Run Code Online (Sandbox Code Playgroud)

java authentication spring spring-security jhipster

11
推荐指数
1
解决办法
9636
查看次数

Jhispter安装:包karma不满足其兄弟姐妹的peerDependencies要求

我正试图通过你来实现jhipster项目.但是当我运行它时,会发生一个奇怪的错误:The package karma does not satisfy its siblings' peerDependencies requirements! 我完全卸载了nodejs并再次安装它,但仍然是同样的错误.当我搜索有一些像这样这样的解决方案建议.

我有64位win7,节点-v v0.10.26 npm -v 1.4.3

error peerinvalid The package karma does not satisfy its siblings' peerDependencies requirements!
error peerinvalid Peer karma-script-launcher@0.1.0 wants karma@>=0.9
error peerinvalid Peer karma-chrome-launcher@0.1.2 wants karma@>=0.9.3
error peerinvalid Peer karma-html2js-preprocessor@0.1.0 wants karma@>=0.9
error peerinvalid Peer karma-jasmine@0.1.5 wants karma@>=0.9
error peerinvalid Peer karma-requirejs@0.2.1 wants karma@>=0.9
error peerinvalid Peer karma-phantomjs-launcher@0.1.2 wants karma@>=0.9
error peerinvalid Peer grunt-karma@0.7.3 wants karma@~0.12.0
error System Windows_NT 6.1.7601
error …
Run Code Online (Sandbox Code Playgroud)

npm yeoman karma-runner yeoman-generator jhipster

5
推荐指数
2
解决办法
4763
查看次数

Kubernetes入口规则:如何同时使用通配符和特定子域

我希望Ingress将特定子域重定向到一个后端,将所有其他子域重定向到另一后端。基本上,我想定义如下规则:

如果是子域,foo.bar.com则转到s1,对于所有其他子域,请转到s2

当我按照Ingress规范中的定义定义规则时,在部署时会遇到此异常:

Error: UPGRADE FAILED: cannot re-use a name that is still in use
Run Code Online (Sandbox Code Playgroud)

但是,当我更改*.bar.comdemo.bar.com它时,它会起作用。

这是我的Ingress资源规范:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - backend:
          serviceName: s1
          servicePort: 80
  - host: *.bar.com
    http:
      paths:
      - backend:
          serviceName: s2
          servicePort: 80
Run Code Online (Sandbox Code Playgroud)

任何人都知道是否可能吗?

kubernetes traefik kubernetes-ingress traefik-ingress

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

使用Spring 4注释进行404错误页面配置

我有一个Spring 4的Spring MVC项目.我的服务器是tomcat 7.我正在尝试创建一个404页面,我尝试了很多东西,但我做不到.

我错过了什么?

这是WebAppContext:

@Configuration
@ComponentScan(basePackages = {
        "com.***"
})
@EnableWebMvc
public class WebAppContext extends WebMvcConfigurerAdapter {

    private static final String VIEW_RESOLVER_PREFIX = "/WEB-INF/pages/";
    private static final String VIEW_RESOLVER_SUFFIX = ".jsp";

    @Autowired
    private EventLogService eventLogService;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public SimpleMappingExceptionResolver exceptionResolver() {
        SimpleMappingExceptionResolver exceptionResolver = new SimpleMappingExceptionResolver();

        Properties exceptionMappings = new Properties();
        exceptionMappings.put("org.springframework.security.web.authentication.rememberme.CookieTheftException", "user/login?error=sessionExpired");
        exceptionMappings.put("java.lang.RuntimeException", "error/error");
        exceptionMappings.put("java.lang.Exception", "error/error");
        exceptionResolver.setExceptionMappings(exceptionMappings);

        Properties statusCodes = new Properties(); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc servlet-3.0

3
推荐指数
1
解决办法
5787
查看次数

Vert.x检查请求标头是否包含X-Requested-With,如果不包含则拒绝

在vert.x中,如果标头中不存在“ X-Requested-With”标头,我想拒绝请求。我要这样做是为了保护CSRF?我找不到一个很好的文件。有人有主意吗?

java csrf csrf-protection vert.x

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

D3.js折线图,x轴有任意日期,但想要显示它们的序列

我有一个折线图.x轴有日期,但它们不是正常分布的(午餐或周末没有数据),但我想按顺序显示它们.示例数据和我的示例图表如下,我不希望我的图表显示没有数据的时间的直线,它应该从前一个日期继续.

x = d3.time.scale().range([0, width])用来画x线.任何的想法?

x         y
10:00:00  4
10:10:00  5
10:20:00  3
10:30:00  2
10:40:00  5
10:50:00  3
14:30:00  6
14:40:00  7
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

javascript d3.js

0
推荐指数
1
解决办法
378
查看次数