我只是在学习Java,所以我很难获得可能的替代方案以及这样的设计决策的影响.
Java 8 为接口添加了默认方法功能,允许接口具有实现.这允许使用新方法扩展现有接口,而不会破坏客户端,以向后兼容的方式随时间演变接口.但是,给定默认实现,此类扩展有些限制,并且可能使用接口或库方法的现有接口方法来实现.所以我的问题是
我是Spring Oauth和Spring Security的新手.我正在尝试在项目中使用client_credentials流程.现在我设法使用我自己的CustomDetailsService来从我系统中已经存在的数据库中获取client_id和密码(secret).唯一的问题是我无法更改AuthorizationServer使用的DaoAuthenticationProvider中的密码编码器 - 它默认设置为PlaintextPasswordEncoder.我无法按照它的方式配置它,例如SHAPasswordEncoder.它总是使用明文编码器.我可能不太了解流程,因为我是Spring的新手.
这是我的一些代码(没有DaoAuthenticationProvider的工作配置):
SecurityConfig.java
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final String RESOURCE_ID = "restservice";
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/register/**");
}
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(daoAuthenticationProvider());
}
@Bean
public DaoAuthenticationProvider daoAuthenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(userDetailsService());
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
return daoAuthenticationProvider;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new ShaPasswordEncoder();
}
@Configuration
@EnableAuthorizationServer
protected static class …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我想将我的Spring Boot应用程序不仅集成在生产环境中,还集中在本地.为了做到这一点,我想:
这种情况可能吗?我不想使用Gradle或Maven在容器中构建应用程序 - 我想告诉IntelliJ Idea使用内部docker容器java编译器,而不是我本地的那个.
我有一个由 spring security 保护的 spring MVC RESTful 应用程序。客户端是 Angular JS。但是我的登录和注销页面是普通的 jsp,我执行基于表单的登录和注销。成功完全认证后,我加载我的安全页面(它使用 anlgularJS 和 RESTful api)。
调用 REST api 时,我需要帮助处理 AuthenticationException 和 AccessDeniedException。我扩展了 ResponseEntityExceptionHandler 并且我能够捕获 AccessDEniedException 并抛出一个 json 响应。我理解处理 AuthenticationException (所以我可以在剩余请求的情况下停止 302 重定向)我需要扩展 ExceptionTranslationFilter。我发现的大多数示例都使用 XML 配置。但是可以在 Java config 中做吗?
我确实编写了一个组件来扩展 ExceptionTranslationFilter 并创建了一个自定义的 AuthenticationEntryPoint,但我不确定如何将它注入我的 ExceptionTranslationFilter
我收到一个错误,由:java.lang.IllegalArgumentException: authenticationEntryPoint must be specified 我尝试添加一个构造函数,但找不到 thors 方法。任何帮助解决表示赞赏。
我的身份验证入口点
@Service
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2)
throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Unauthorized.");
}
}
Run Code Online (Sandbox Code Playgroud)
我的异常翻译过滤器
@Component
public class …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring Boot 1.2.2.RELEASE运行drools 6.2.0.Final.我按照文档说明配置了drools.我的kie-context.xml配置文件是我保存drools bean的地方,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:kie="http://drools.org/schema/kie-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
<kie:kmodule id="sample_module">
<kie:kbase name="kbase1" packages="composition-rules">
<kie:ksession name="ksession1" type="stateless"/>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
Run Code Online (Sandbox Code Playgroud)
当我尝试编译应用程序并使用spring-boot运行时,我收到以下错误:
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6ab6cc3b: startup date [Wed Apr 15 13:57:02 CEST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:357)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:877)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:150)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:342)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at skeleton.StorfinoApplication.main(StorfinoApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在docker容器中运行nuxt应用程序.为此,我创建了以下Dockerfile:
FROM node:6.10.2
RUN mkdir -p /app
EXPOSE 3000
COPY . /app
WORKDIR /app
RUN npm install
RUN npm run build
CMD [ "npm", "start" ]
Run Code Online (Sandbox Code Playgroud)
但是,当我构建映像并运行容器(docker run -p 3000:3000 <image-id>)时,我localhost:3000在浏览器中点击时什么都没有.可能是什么原因?