小编Kum*_*hav的帖子

在Spring Boot和Spring Security应用程序中提供静态Web资源

我正在尝试使用Spring安全性Java配置开发Spring Boot Web应用程序并保护它.

按照Spring博客中的建议将静态Web资源放入' src/main/resources/public '后,我就能获得静态资源.即在浏览器中点击确实提供html内容.https://localhost/test.html

问题

启用S​​pring Security后,点击静态资源URL需要进行身份验证.

我的相关Spring Security Java配置如下所示: -

@Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http.
            authorizeRequests()
                .antMatchers("/","/public/**", "/resources/**","/resources/public/**")
                    .permitAll()
                .antMatchers("/google_oauth2_login").anonymous()
                    .anyRequest().authenticated()
                .and()
                .formLogin()
                    .loginPage("/")
                    .loginProcessingUrl("/login")
                    .defaultSuccessUrl("/home")
                    .and()
                    .csrf().disable()
                    .logout()
                        .logoutSuccessUrl("/")
                        .logoutUrl("/logout") // POST only
                .and()
                    .requiresChannel()
                    .anyRequest().requiresSecure()
                .and()
                    .addFilterAfter(oAuth2ClientContextFilter(),ExceptionTranslationFilter.class)
                    .addFilterAfter(googleOAuth2Filter(),OAuth2ClientContextFilter.class)
                .userDetailsService(userService);
        // @formatter:on
    }
Run Code Online (Sandbox Code Playgroud)

我应该如何配置antMatchers以允许放置在src/main/resources/public中的静态资源?

spring-mvc spring-security spring-boot

62
推荐指数
6
解决办法
10万
查看次数

slf4j-log4j12和log4j-over-slf4j之间的区别

slf4j-log4j12和log4j-over-slf4j之间有什么区别?何时应该使用它们?

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.12</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.12</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

java log4j slf4j

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

使用Application Load Balancer + EC2 Container Service时,目标组端口是什么

我正在尝试设置一个侦听端口443的ALB,在随机端口上对ECS Docker容器进行负载均衡,假设我有2个相同任务定义的容器实例,侦听端口30000和30001.

当我尝试在AWS EC2管理控制台中创建目标组时,有一个"端口"输入字段,范围为1-65535.我应该在那里放几个号码?

当我尝试在AWS EC2容器服务控制台中创建新服务以及连接到现有ALB的新目标组时,目标组"端口"没有输入字段.创建后,导航到EC2控制台,新目标组的端口为"80".我必须在80端口听吗?但健康检查发生在"交通港",即集装箱港口30000和30001,那么重点是什么?

amazon-ec2 amazon-web-services amazon-ecs amazon-elb

24
推荐指数
2
解决办法
5651
查看次数

Angular UI Grid 3.x版本中的操作按钮

我试图使用Angular UI Grid(不稳定版本)渲染一个简单的表.对于每一行,我需要一个按钮,点击时应该在我的父控制器中处理.

Plunker

使用Javascript: -

angular.module("app", ['ui.grid', 'ui.grid.edit', 'ui.grid.selection', 'ui.grid.pagination', 'ui.grid.expandable', 'ui.grid.paging']).controller("appController", function($scope) {
  console.log("Controller is up.");
  $scope.data = [];
  for (var i = 0; i < 50; i++) {
    $scope.data.push({
      fullName: "Name" + i,
      age: i
    });
  }

  $scope.clickHandler = function(){
    // this never gets invoked ?!
    console.log("Row Action click Handler.");
  };


  $scope.gridOptions = {
    data: $scope.data,
    columnDefs:[ {name:'fullName',field:'fullName'},
              {name:'age',field:'age'},
              {name:' ',cellTemplate:'<div><button ng-click="clickHandler()">Click Here</button></div>'}
            ]
  };
});
Run Code Online (Sandbox Code Playgroud)

HTML

<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.min.css">
  <link …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-ui-grid

22
推荐指数
3
解决办法
3万
查看次数

从文件系统提供静态资源| Spring Boot Web

使用Spring Boot Web应用程序我尝试从项目外部的文件系统文件夹中提供静态资源.

文件夹结构如下: -

          src
             main
                 java
                 resources
             test
                 java
                 resources
          pom.xml
          ext-resources   (I want to keep my static resources here)
                 test.js
Run Code Online (Sandbox Code Playgroud)

弹簧配置: -

@SpringBootApplication
public class DemoStaticresourceApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(DemoStaticresourceApplication.class, args);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/test/**").addResourceLocations("file:///./ext-resources/")
                .setCachePeriod(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的浏览器中点击' http:// localhost:9999/test/test.js '会返回404.

我应该如何配置ResourceHandlerRegistry来提供上述'ext-resources'文件夹中的静态资源?

我应该能够为dev/prod环境打开/关闭缓存.

谢谢

更新1

给绝对文件路径有效: -

@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/test/**")
                .addResourceLocations(
                        "file:///C:/Sambhav/Installations/workspace/demo-staticresource/ext-resources/")
                .setCachePeriod(0);
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能提供相对位置?绝对路径将使我的生活在构建和部署过程中变得艰难.

spring-mvc spring-boot

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

Yeoman | 咕噜| 没有这样的文件或目录 - bower.json

使用'yo angular'我创建了AngularJS种子应用程序.

尝试使用'grunt serve'运行应用程序会出现此错误: -

>grunt serve
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module 'imagemin-pngquant'

Running "serve" task

Running "clean:server" (clean) task

Running "wiredep:app" (wiredep) task
Warning: ENOENT, no such file or directory 'C:\a\b\c\yup\app\bower.json' Use --force to continue.

Aborted due to warnings.


Execution Time (2014-09-11 10:10:36 UTC)
loading tasks   10ms  ??? 2%
wiredep:app    533ms  ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 97%
Total 549ms
Run Code Online (Sandbox Code Playgroud)

为什么它在app文件夹中寻找bower.json?它存在一级.

我怎样才能解决这个问题?

凉亭版 - 1.3.9

Grunt版本 - grunt v0.4.5

哟版本 - 1.2.1

Gruntfile.js: -

// Generated on 2014-09-11 using generator-angular 0.9.5 …
Run Code Online (Sandbox Code Playgroud)

gruntjs yeoman-generator-angular

14
推荐指数
2
解决办法
8758
查看次数

使用Spring Security Java配置时禁用基本身份验证

我正在尝试使用Spring Security java配置来保护Web应用程序.

这是配置的外观: -

@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    private String googleClientSecret;

    @Autowired
    private CustomUserService customUserService;

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.security.config.annotation.web.configuration.
     * WebSecurityConfigurerAdapter
     * #configure(org.springframework.security.config
     * .annotation.web.builders.HttpSecurity)
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        // @formatter:off
        http
            .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll()
                .anyRequest().authenticated()
            .and()
                .formLogin()
                    .and()
                .httpBasic().disable()
            .requiresChannel().anyRequest().requiresSecure();
        // @formatter:on
        super.configure(http);
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        // @formatter:off
        auth
            .eraseCredentials(true)
            .userDetailsService(customUserService);
        // @formatter:on
        super.configure(auth);
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我已使用以下方法明确禁用HTTP基本身份验证:

.httpBasic().disable()
Run Code Online (Sandbox Code Playgroud)

我在访问安全网址时仍然会收到HTTP …

spring-security spring-boot spring-java-config

13
推荐指数
2
解决办法
6万
查看次数

使用$ http.get调用响应初始化AngularJS常量

如何通过响应GET请求来初始化我的angularjs应用程序.

例如 :-

    angular.module('A',[]);
    angular.module('A').run( function ($rootScope,$http){
      $rootScope.safeApply = function (fn) {

                $http.get('url').success(function(result){

                    // This doesn't work. I am not able to inject 'theConstant' elsewhere in my application
                    angular.module('A').constant('theConstant', result);
                });                   
                var phase = $rootScope.$$phase;
                if (phase === '$apply' || phase === '$digest') {
                    if (fn && (typeof (fn) === 'function')) {
                        fn();
                    }
                } else {
                    this.$apply(fn);
                }
            };
      });
Run Code Online (Sandbox Code Playgroud)

我希望在我的应用程序初始化时设置常量,并能够在我的组件之间共享常量.

实现这一目标的最佳方法是什么?

javascript angularjs

13
推荐指数
2
解决办法
2万
查看次数

AngularJS | 使用$ http.get方法设置路径参数

我有一个GET端点,其URI为/ user/user-id.'user-id'是路径变量.

如何在发出GET请求时设置路径变量?

这是我试过的: -

$http.get('/user/:id',{
                params: {id:key}
            });
Run Code Online (Sandbox Code Playgroud)

而不是替换路径变量,id作为查询参数附加.即我的调试器将请求URL显示为'http://localhost:8080/user/:id?id=test'

我预期的已解析URL应该像' http:// localhost:8080/user/test '

angularjs

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

开放API 3.0.2 | Spring 服务器生成器 | Api/Controller接口命名

我正在尝试为 OpenApi 3.0.2 规范生成生成的服务器端 Spring MVC 代码。

这就是“路径”之一的样子:-

paths:
  /api/v1/int/integrations/{some-path-variable}/some-action:
    get:
      summary: Summary
      description: How to change the generated Api/Controller class name?
      operationId: methodName
      tags:
        - inventory
      parameters:
        - name: Authorization
      other details....
Run Code Online (Sandbox Code Playgroud)

服务器端代码使用 Maven 插件生成,配置为:-

    <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>               
        <version>4.1.0</version>           

        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/open-api/myapi.yaml</inputSpec>
                    <generatorName>spring</generatorName>
                    <library>spring-boot</library>
                    <output>${project.build.directory}/generated-openapi/spring</output>
                    <generateApis>true</generateApis>
                    <addCompileSourceRoot>true</addCompileSourceRoot>
                    <artifactVersion>${project.version}</artifactVersion>
                    <groupId>com.company.division</groupId>
                    <artifactId>myapi-api</artifactId>
                    <generateApiTests>true</generateApiTests>
                    <modelPackage>com.company.division.myapi.generated.model</modelPackage>
                    <apiPackage>com.company.division.myapi.generated.api</apiPackage>
                    <generateApiDocumentation>true</generateApiDocumentation>

                    <configOptions>
                        <dateLibrary>java8</dateLibrary>
                        <java8>true</java8>
                        <interfaceOnly>true</interfaceOnly>
                        <reactive>false</reactive>
                        <useBeanValidation>true</useBeanValidation>
                        <performBeanValidation>true</performBeanValidation>
                        <useOptional>false</useOptional>
                        <serviceInterface>true</serviceInterface>
                        <serviceImplementation>false</serviceImplementation>
                    </configOptions>
                </configuration>

            </execution>
        </executions>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

从插件配置中可以看出,我只对生成模型类和 Spring 控制器接口/API 接口感兴趣。

问题

对于提到的 …

spring-mvc openapi openapi-generator

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