小编dur*_*dur的帖子

JavaFX 与 Java Swing 在工业中的使用情况

为什么开发人员拒绝使用超级简单的 JavaFX 包启动新项目?为什么他们使用传统的 Java Swing 包继续他们的项目?JavaFX的未来会怎样?会停产吗?我听说 Java Swing 已停产,并且未来不会再进行任何增强。作为一个初学者我应该学什么。

java swing javafx javafx-8 java-package

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

避免 Spring 应用程序在浏览器关闭时注销

我有一个奇怪的问题,无法解决它。

问题 :

我登录到会话超时很长的 Spring Web 应用程序,每当我退出浏览器然后重新打开它时,访问我的 Web 应用程序,我每次都会看到登录页面。

只要浏览器没有关闭,它就可以正常工作。我认为 chrome 设置有问题,但事实并非如此。它也发生在所有浏览器中。

我的web.xml

    <session-config>
        <session-timeout>10000</session-timeout>
        <cookie-config>
            <name>myapp</name>
            <http-only>true</http-only>
        </cookie-config>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>
Run Code Online (Sandbox Code Playgroud)

我的 Spring Security 配置:

    <security:http auto-config="true" use-expressions="true">
        <security:intercept-url pattern="/resources/**" access="permitAll" />
        <security:intercept-url pattern="/login" access="permitAll" />
        <security:intercept-url pattern="/login/forgot" access="permitAll" />
        <security:intercept-url pattern="/login/resetpassword" access="permitAll" />
        <security:intercept-url pattern="/home/admin/**" access="hasAnyRole('ROLE_admin', 'ROLE_manager')" />
        <security:intercept-url pattern="/**" access="hasAnyRole('ROLE_admin', 'ROLE_manager','ROLE_user')" />
        <security:form-login 
            login-page="/login" 
            login-processing-url="/login" 
            authentication-failure-handler-ref="authenticationFailureFilter" 
            authentication-success-handler-ref="authenticationSuccessHandler"  
            username-parameter="email" 
            password-parameter="password" />
        <!-- enable csrf protection -->
        <security:csrf/>

    </security:http>
Run Code Online (Sandbox Code Playgroud)

我的web.xml或 Spring Security有问题吗?

java spring spring-mvc spring-security tomcat7

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

单击图片时如何播放单独的GIF?

所以我刚开始学习C#,我目前正在开发一个简单的Form应用程序.我想要做的是点击GIF时,它会切换到另一个GIF,然后在1秒后回到原始GIF.但是发生的事情一无所获.它只是保持原来的GIF.如果我尝试使用消息框而不是工作正常,它只是试图改变GIF的来源是问题.

private void pictureBox1_Click(object sender, EventArgs e)
{
    /* pictureBox2.Show();
       Thread.Sleep(1000);
       pictureBox2.Hide(); */
    pictureBox1.Image = WindowsLogin.Properties.Resources.PenguinEXE;
    Thread.Sleep(1000);
    pictureBox1.Image = WindowsLogin.Properties.Resources.PenguinIdle;
}
Run Code Online (Sandbox Code Playgroud)

我也试过使用ShowHide方法,但也没用.

c# winforms

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

Spring Security在基本身份验证后抛出403

我使用Spring Security进行基本身份验证来保护我的REST API.

以下是配置代码:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user")
                    .password("password")
                    .roles("admin");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .csrf().disable()
            .authorizeRequests()
                .anyRequest().authenticated();
    }
}
Run Code Online (Sandbox Code Playgroud)

我在使用正确的用户名和密码验证自己时遇到了禁止(403)错误.

在此输入图像描述

请建议修改以使其正常工作.

java spring spring-security basic-authentication

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

Spring Boot + Spring Security - 无法注销

我有一个用 Spring Boot 和 Spring Security 构建的 REST API。我从文档中读到 Spring Security 默认在当前用户请求/logout. 但是,我似乎无法让它发挥作用。

这是我的安全配置:

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .and()
            .httpBasic()
                .and()
            .csrf().disable();
    } 
}
Run Code Online (Sandbox Code Playgroud)

但是,当我向 发出请求时/logout,收到以下错误:

{
    "timestamp": 1485096094269,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/login"
}
Run Code Online (Sandbox Code Playgroud)

java spring-security spring-boot

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

如何按特定主体名称删除现有会话

我在我的项目中使用带有 Redis 后端的 Spring Session 1.3.0。

我有一个用例,超级管理员可能会更新可能已经登录的现有用户的角色。我想在更改角色后删除这些用户的现有会话记录。

是否有 Spring Session 的 API 来归档它?

spring spring-security redis spring-boot spring-session

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

身份验证失败重定向请求参数不起作用

我正在尝试配置我自己的成功和身份验证失败处理程序。在身份验证失败时,我想使用请求参数重定向回我的登录页面,此参数的存在将在我的登录页面上输出错误消息。但是,尽管出错时我被重定向回我的登录页面,但请求参数始终为null.

代码如下:

protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()
        .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/login").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login.html").permitAll() 
            .usernameParameter("username")
            .passwordParameter("password")                                               
            .loginProcessingUrl("/login")
            .successHandler(successHandler())
            .failureHandler(handleAuthenticationFailure());
}

@Autowired
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    //database checks
}
};
}

/**
 * Authentication success handler defines action when successfully authenticated
 * @return
 */
@Bean
public AuthenticationSuccessHandler successHandler(){
    return new AuthenticationSuccessHandler() {

        @Override
        public void onAuthenticationSuccess(HttpServletRequest httpRequest, HttpServletResponse httpResponse, Authentication authentication)
                throws IOException, ServletException {

            // custom auth success here
            httpResponse.setStatus(HttpServletResponse.SC_OK); …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-boot

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

Spring LDAP querybuilder PartialResultException

我正在尝试从LDAP服务器中获取所有用户,并从基础上进行搜索,这是我的代码:

public LdapTemplate ldapTemplate() {
        LdapContextSource ctxSrc = new LdapContextSource();
        ctxSrc.setUrl("ldap://127.0.0.1:389/");
        ctxSrc.setBase("dc=test,dc=com");
        ctxSrc.setUserDn("admin");
        ctxSrc.setPassword("password");
        ctxSrc.afterPropertiesSet();
        LdapTemplate lt = new LdapTemplate(ctxSrc);
        return lt;
}
private LdapTemplate ldapTemplate = ldapTemplate();
public List<User> getAllUsers() {

        LdapQuery query= query().base("").where("objectclass").is("user");
        return ldapTemplate.search(query, new UserAttributesMapper());
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

10:07:09.406 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
10:07:09.413 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
10:07:09.416 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://127.0.0.1:389/dc=test,dc=com
10:07:09.548 [main] DEBUG o.s.l.c.s.AbstractContextSource - Got Ldap context on …
Run Code Online (Sandbox Code Playgroud)

spring spring-ldap

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

主体作为 UsernamePasswordAuthenticationToken 返回

我遇到了我认为可能是错误的情况。

我正在使用 Spring Boot 和 Spring Security。通常情况下,一切都运行良好,但是当我尝试通过控制器或直接从控制器获取主体时,由于某种奇怪的原因HttpServletRequest,它会被强制转换UsernamePasswordAuthenticationToken。当我使用SecurityContextHolder.getContext().getAuthentication().getPrincipal()它时,它返回正确的对象。

请参阅下面的代码,请参阅最后 6 行左右的注释以了解实际返回的内容。

@RequestMapping(method = RequestMethod.POST)
public ElementDto postElement(@RequestBody @Valid ElementDto element, BindingResult bindingResult, HttpServletRequest httpServletRequest, Principal principal) {
    logger.info("postElement - {}", element);
    if (bindingResult.hasErrors()) {
        throw new SpringBootCommonError(bindingResult.getAllErrors().get(0).getDefaultMessage(), SpringBootCommonErrorEnum.VALIDATION);
    }
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = (UsernamePasswordAuthenticationToken)principal; /*is of type UsernamePasswordAuthenticationToken*/
    Principal requestPrincipal = httpServletRequest.getUserPrincipal();/*is of type UsernamePasswordAuthenticationToken*/
    Principal principalFromCast = (Principal)usernamePasswordAuthenticationToken.getPrincipal();/*is of type User (what I want)*/
    Object securityPrincipal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();/*is of type (what I want)*/
    element.setUploadedBy(((User) httpServletRequest.getUserPrincipal()).getEntityNo()); …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-boot

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

如何在Java中使用WSDL生成模拟Web服务?

我有WSDL文件,对于本地测试,我需要生成模拟Web服务。

请不要推荐SoapUI

有人可以帮助使用Java使用WSDL生成模拟Web服务吗?

java web-services mocking

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