Java 类org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AuthenticationAuditListener.java   
public void process(AuthenticationAuditListener listener,
        AbstractAuthenticationEvent input) {
    if (listener != null) {
        AuthenticationSwitchUserEvent event = (AuthenticationSwitchUserEvent) input;
        Map<String, Object> data = new HashMap<String, Object>();
        if (event.getAuthentication().getDetails() != null) {
            data.put("details", event.getAuthentication().getDetails());
        }
        data.put("target", event.getTargetUser().getUsername());
        listener.publish(new AuditEvent(event.getAuthentication().getName(),
                "AUTHENTICATION_SWITCH", data));
    }

}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AuthenticationAuditListenerTests.java   
@Test
public void testAuthenticationSwitch() {
    this.listener.onApplicationEvent(new AuthenticationSwitchUserEvent(
            new UsernamePasswordAuthenticationToken("user", "password"),
            new User("user", "password",
                    AuthorityUtils.commaSeparatedStringToAuthorityList("USER"))));
    verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
项目:spring-boot-concourse    文件:AuthenticationAuditListener.java   
public void process(AuthenticationAuditListener listener,
        AbstractAuthenticationEvent input) {
    if (listener != null) {
        AuthenticationSwitchUserEvent event = (AuthenticationSwitchUserEvent) input;
        Map<String, Object> data = new HashMap<String, Object>();
        if (event.getAuthentication().getDetails() != null) {
            data.put("details", event.getAuthentication().getDetails());
        }
        data.put("target", event.getTargetUser().getUsername());
        listener.publish(new AuditEvent(event.getAuthentication().getName(),
                "AUTHENTICATION_SWITCH", data));
    }

}
项目:spring-boot-concourse    文件:AuthenticationAuditListenerTests.java   
@Test
public void testAuthenticationSwitch() {
    this.listener.onApplicationEvent(new AuthenticationSwitchUserEvent(
            new UsernamePasswordAuthenticationToken("user", "password"),
            new User("user", "password",
                    AuthorityUtils.commaSeparatedStringToAuthorityList("USER"))));
    verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
项目:contestparser    文件:AuthenticationAuditListener.java   
public void process(AuthenticationAuditListener listener,
        AbstractAuthenticationEvent input) {
    if (listener != null) {
        AuthenticationSwitchUserEvent event = (AuthenticationSwitchUserEvent) input;
        Map<String, Object> data = new HashMap<String, Object>();
        if (event.getAuthentication().getDetails() != null) {
            data.put("details", event.getAuthentication().getDetails());
        }
        data.put("target", event.getTargetUser().getUsername());
        listener.publish(new AuditEvent(event.getAuthentication().getName(),
                "AUTHENTICATION_SWITCH", data));
    }

}
项目:contestparser    文件:AuthenticationAuditListenerTests.java   
@Test
public void testAuthenticationSwitch() {
    this.listener.onApplicationEvent(new AuthenticationSwitchUserEvent(
            new UsernamePasswordAuthenticationToken("user", "password"),
            new User("user", "password",
                    AuthorityUtils.commaSeparatedStringToAuthorityList("USER"))));
    verify(this.publisher).publishEvent((ApplicationEvent) anyObject());
}
项目:adjule    文件:SwitchUserListener.java   
@Override
public void onApplicationEvent(final AuthenticationSwitchUserEvent event) {
    final String name = event.getAuthentication().getName();
    final String target = event.getTargetUser().getUsername();

    AccessLog accessLog = new AccessLog();
    final String switchedUser = getSwitchedUsername(event.getAuthentication());
    final String username = switchedUser != null ? switchedUser : name;
    accessLog.setUsername(username);
    accessLog.setStatus(LogStatus.success);

    if (event.getSource() instanceof UsernamePasswordAuthenticationToken) {
        UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) event.getSource();
        if (token.getDetails() instanceof WebAuthenticationDetails) {
            WebAuthenticationDetails details = (WebAuthenticationDetails) token.getDetails();
            accessLog.setIp(details.getRemoteAddress());
        }
    }

    if (username.equals(target)) {
        accessLog.setDescription("User change back to original");
    } else {
        accessLog.setDescription("User change to " + target);
    }

    accessService.logAccess(accessLog);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AuthenticationAuditListener.java   
public boolean accepts(AbstractAuthenticationEvent event) {
    return event instanceof AuthenticationSwitchUserEvent;
}
项目:spring-boot-concourse    文件:AuthenticationAuditListener.java   
public boolean accepts(AbstractAuthenticationEvent event) {
    return event instanceof AuthenticationSwitchUserEvent;
}
项目:contestparser    文件:AuthenticationAuditListener.java   
public boolean accepts(AbstractAuthenticationEvent event) {
    return event instanceof AuthenticationSwitchUserEvent;
}