小编Him*_*dar的帖子

Spring Security:按客户端类型启用/禁用CSRF(浏览器/非浏览器)

Spring doc说

"当您使用CSRF保护时?我们的建议是对普通用户可以由浏览器处理的任何请求使用CSRF保护.如果您只创建非浏览器客户端使用的服务,您可能希望禁用CSRF保护."

如果我的服务将被"浏览器"和"非浏览器"客户端(如第三方外部服务)使用,那么Spring安全性是否为某些类型的客户端专门禁用csrf提供了一种方法呢?

参考:http://docs.spring.io/spring-security/site/docs/3.2.0.CI-SNAPSHOT/reference/html/csrf.html

java spring spring-mvc csrf spring-security

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

Spring MVC REST通过返回JSON来处理Bad Url(404)

我正在使用SpringMVC开发一个REST服务,我在类和方法级别有@RequestMapping.

此应用程序当前配置为返回在web.xml中配置的错误页面jsp.

<error-page>
    <error-code>404</error-code>
    <location>/resourceNotFound</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

但是我想返回自定义JSON而不是此错误页面.

我可以通过在控制器中编写这个来处理异常并返回json以获取其他异常,但是当url根本不存在时,不知道如何以及在何处编写逻辑以返回JSON.

    @ExceptionHandler(TypeMismatchException.class)
        @ResponseStatus(value=HttpStatus.NOT_FOUND)
        @ResponseBody
        public ResponseEntity<String> handleTypeMismatchException(HttpServletRequest req, TypeMismatchException ex) {

            HttpHeaders headers = new HttpHeaders();
            headers.add("Content-Type", "application/json; charset=utf-8");
            Locale locale = LocaleContextHolder.getLocale();
            String errorMessage = messageSource.getMessage("error.patient.bad.request", null, locale);

            errorMessage += ex.getValue();
            String errorURL = req.getRequestURL().toString();

            ErrorInfo errorInfo = new ErrorInfo(errorURL, errorMessage);
            return new ResponseEntity<String>(errorInfo.toJson(), headers, HttpStatus.BAD_REQUEST);

        }
Run Code Online (Sandbox Code Playgroud)

我试过@ControllerAdvice,它适用于其他异常场景,但是当映射不可用时,

@ControllerAdvice
public class RestExceptionProcessor {

    @Autowired
    private MessageSource messageSource;

    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @ResponseStatus(value=HttpStatus.NOT_FOUND)
    @ResponseBody
    public ResponseEntity<String> requestMethodNotSupported(HttpServletRequest req, HttpRequestMethodNotSupportedException ex) {
        Locale locale = LocaleContextHolder.getLocale();
        String …
Run Code Online (Sandbox Code Playgroud)

rest json spring-mvc

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

在Groovy/Gradle中执行Sql脚本文件

def db = [
    moduleGroup: 'mysql',
    moduleName: 'mysql-connector-java',
    moduleVersion: '5.1.18',
    driver: "com.mysql.jdbc.Driver",
    url: 'jdbc:mysql://localhost:3306/bham',
    user: mySqlUser,
    password: mySqlPassword
]

configurations {
    sql
}    


task connect << {

        // This is needed to get mySql driver onto the Groovy/Gradle classpath 
        configurations.sql.each { file ->
          println "Adding URL: $file"
          gradle.class.classLoader.addURL(file.toURI().toURL())
        }

        def sql = groovy.sql.Sql.newInstance(db.url, db.user, db.password, db.driver)

        sql.execute("actStatusCodeLkp.sql") 
        String sqlFilePath = "src/main/resources/sqlscripts/actStatusCodeLkp.sql"
        String sqlString = new File(sqlFilePath).text
        sql.execute(sqlString)

        sql.close()

     }
Run Code Online (Sandbox Code Playgroud)

actStatusCodeLkp.sql

insert into act_status_code (id, code, display_name, code_system_name, code_system) values (1, …
Run Code Online (Sandbox Code Playgroud)

mysql groovy gradle

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

Wordpress插件滑块革命错误

我无法摆脱以下错误.激活插件后,错误显示出来.

Slider Revolution error: could not unzip into the revslider/public/assets/ folder, please make sure that this folder is writable. 
Run Code Online (Sandbox Code Playgroud)

我做了chmod 777到revslider/public/assets /但没有用.

我在浏览器中也遇到了这个错误..

Revolution Slider Error: You have some jquery.js library include that comes after the revolution files js include.
This includes make eliminates the revolution slider libraries, and make it not work.
To fix it you can:
    1. In the Slider Settings -> Troubleshooting set option: Put JS Includes To Body option to true.
    2. Find the double jquery.js …
Run Code Online (Sandbox Code Playgroud)

wordpress jquery revolution-slider

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

perf4j @Profiled注释不起作用

我已经通过perf4J网站的以下链接,并做了同样的事情:http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects

在我的spring.xml中添加了以下内容.

<aop:aspectj-autoproxy/>
<bean id="timingAspect" class="org.perf4j.log4j.aop.TimingAspect"/>
<bean id="wscClientBase" class="com.xyz.csa.core.common.WscClientBase"/>
Run Code Online (Sandbox Code Playgroud)

在类WscClientBase中,我使用@Profiled注释的以下方法.

@Profiled(tag = "SOAPCALLTEST")
public Object sendMessage(Object message) {
    String msg = message.toString();
    if (msg.indexOf(' ') > 1) {
        msg = msg.substring(1, msg.indexOf(' '));
    }
    try {
        Object ret = marshalSendAndReceive(message);
        return ret;
    } catch (RuntimeException ex) {
        throw ex;
    }
}
Run Code Online (Sandbox Code Playgroud)

我没有在应用程序日志中看到perf4j TimingLogger语句.但是,如果我使用它(如下没有注释),我会成功地看到日志语句.

public Object sendMessage(Object message) {
    String msg = message.toString();
    if (msg.indexOf(' ') > 1) {
        msg = msg.substring(1, msg.indexOf(' '));
    }
    StopWatch stopWatch …
Run Code Online (Sandbox Code Playgroud)

spring log4j seam spring-aop perf4j

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

单向休息时双向SSL还是单向SSL?

我创建了一个client-rest-api,它调用了server-rest-api(单向调用).我的client-rest-api使用server-rest-api颁发的证书.但是我的client-rest-api从未向server-rest-api颁发任何证书.它是单向ssl还是双向ssl?

事件虽然它只是从客户端到服务器的单向调用,但我认为它的双向ssl,因为这里server-rest-api验证客户端是否拥有服务器发出的适当证书?

rest ssl ssl-certificate

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

卡夫卡经纪人vs话题

一个话题通常居住内的经纪人(服务器进程),并有多个分区,但在多个经纪或节点(机器),它可以跨越?

即,可以说一个主题分为两个分区,分区1和分区2。分区1可以属于同一主题的代理1,分区2可以完全属于不同的代理2或不同的节点吗?

apache-kafka

7
推荐指数
3
解决办法
5192
查看次数

java.security.SignatureException:签名不匹配

  1. 我创建了一个名为cloudslkeystore.jks的 java 密钥库

     keytool -genkeypair -validity 730 -alias cloudsslkey -keystore cloudsslkeystore.jks -dname "cn=localhost" -keypass password -storepass password
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我将其导出为名称为cloudcertificate.cer 的证书

     keytool -export -rfc -keystore cloudsslkeystore.jks -alias cloudsslkey -file cloudcertificate.cer 
     Enter keystore password:password
     Certificate stored in file <cloudcertificate.cer>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我将证书 cloudcertificate.cer 添加到我的本地 java 安全文件夹

    C:\Program Files\Java\jre7\lib\security>keytool -keystore cacerts -importcert -noprompt -trustcacerts -alias cloudsslkey -file cloudcertificate.cer
    Enter keystore password:changeit
    Certificate was added to keystore
    
    Run Code Online (Sandbox Code Playgroud)

    现在,我使用的相同的Java密钥cloudsslkeystore.jks不同的机器的Tomcat服务器通过修改的server.xml

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
                   maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" keystoreFile="c:\keytool\cloudsslkeystore.jks" keystorePass="password" …
    Run Code Online (Sandbox Code Playgroud)

java security keytool tomcat7

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

客户网关和路由器有什么区别

客户网关

客户网关是您这边连接的锚点。它可以是物理或软件设备。

客户可以将多个客户网关 (CGW) 连接到单个 VPC 虚拟专用网关 (VGW),也可以将单个路由器连接到多个 VPC VGW。

路由器和客户网关之间有区别吗?从AWS常见问题解答部分https://aws.amazon.com/vpc/faqs/#C9来看,它们似乎是一回事。

amazon-web-services amazon-vpc

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

在独立的Java Spring spring应用程序中删除getBean(非Web应用程序,没有容器)

在Web应用程序中,我们真的不需要做..

ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-context.xml");
ctx.getBean("beanId");
Run Code Online (Sandbox Code Playgroud)

因为一般的做法是加载上下文文件并使用webL中的ContextLoaderServlet注入所有具有依赖关系的bean,如下所示.

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring-context.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- or use the ContextLoaderServlet instead of the above listener
<servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
--> 
Run Code Online (Sandbox Code Playgroud)

然而,在没有容器的独立Java应用程序中,我最终做了ctx.getBean("xyz"); .有没有干净的方法来做到这一点,无法在网上找到一个例子.

我检查过.. Simple Spring,使用ClasspathApplicationContext进行独立应用,如何重用?,讨论使用SingletonBeanFactoryLocator,但最终使用context.getBean().

我还查看了ServiceLocatorFactoryBean,但这又是通过使用代理来获取bean的需求.

我正在寻找从我的独立Java应用程序的main()程序加载上下文文件(所有bean)的解决方案,这样我就不想按需获取bean.

示例代码:

public interface IReader {
    public String read();
}

public class TextFileReader implements IReader {

    private StringBuilder builder = null;
    private Scanner scanner = null;

    public TextFileReader(String fileName) throws FileNotFoundException {
        scanner = new Scanner(new …
Run Code Online (Sandbox Code Playgroud)

java spring

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