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

项目:xm-uaa    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:pcm-api    文件:LoginFailureEventListener.java   
@Override
public void handle(Object event) {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent = (AuthenticationFailureBadCredentialsEvent) event;
    Object name = loginFailureEvent.getAuthentication().getPrincipal();
    Users user = usersRepository.loadUserByUsername((String) name);
    eventService.raiseSecurityEvent(new AuthenticationFailedEvent(
            ((WebAuthenticationDetails) loginFailureEvent
                    .getAuthentication().getDetails()).getRemoteAddress(),
            (String) name));
    if (user != null) {
        // update the failed login count
        user.increaseFailedLoginAttempts();
        if (user.getFailedLoginAttempts() >= max_failed_attempts) {
            Calendar cal = Calendar.getInstance();
            user.setLockoutTime(cal);
        }
        // update user
        usersRepository.updateUser(user);
    }
}
项目:xm-uaa    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:jhipster-microservices-example    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:jhipster-microservices-example    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:MTC_Labrat    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:buenojo    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (String key : data.keySet()) {
            Object object = data.get(key);

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(key, object.toString());
            } else {
                results.put(key, "null");
            }
        }
    }

    return results;
}
项目:xm-commons    文件:SpringSecurityXmAuthenticationContext.java   
/**
 * {@inheritDoc}
 */
@Override
public Optional<String> getRemoteAddress() {
    return getDetails().flatMap(details -> {
        String address;
        if (details instanceof OAuth2AuthenticationDetails) {
            address = OAuth2AuthenticationDetails.class.cast(details).getRemoteAddress();
        } else if (details instanceof WebAuthenticationDetails) {
            address = WebAuthenticationDetails.class.cast(details).getRemoteAddress();
        } else {
            throw new IllegalStateException("Unsupported auth details type " + details.getClass());
        }

        return Optional.ofNullable(address);
    });
}
项目:xm-commons    文件:SpringSecurityXmAuthenticationContext.java   
/**
 * {@inheritDoc}
 */
@Override
public Optional<String> getSessionId() {
    return getDetails().flatMap(details -> {
        String sessionId;
        if (details instanceof OAuth2AuthenticationDetails) {
            sessionId = OAuth2AuthenticationDetails.class.cast(details).getSessionId();
        } else if (details instanceof WebAuthenticationDetails) {
            sessionId = WebAuthenticationDetails.class.cast(details).getSessionId();
        } else {
            throw new IllegalStateException("Unsupported auth details type " + details.getClass());
        }

        return Optional.ofNullable(sessionId);
    });
}
项目:xm-commons    文件:SpringSecurityXmAuthenticationContext.java   
@SuppressWarnings("unchecked")
private Optional<Map<String, Object>> getDetailsMap() {
    return getDetails().flatMap(
                    details -> {
                        if (details instanceof OAuth2AuthenticationDetails) {
                            Object decodedDetails = OAuth2AuthenticationDetails.class.cast(
                                            details).getDecodedDetails();
                            return Optional.ofNullable(Map.class.cast(decodedDetails));
                        } else if (details instanceof WebAuthenticationDetails) {
                            return Optional.empty();
                        } else {
                            throw new IllegalStateException("Unsupported auth details type "
                                            + details.getClass());
                        }
                    });
}
项目:xm-ms-balance    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:Armory    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:Armory    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:xm-ms-dashboard    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:patient-portal    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:patient-portal    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:sentry    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:TorgCRM-Server    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:TorgCRM-Server    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:speakTogether    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:xm-ms-entity    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:Code4Health-Platform    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:lemon    文件:SpringSecurityUtils.java   
/**
 * 取得当前用户登录IP, 如果当前用户未登录则返回空字符串.
 */
public static String getCurrentUserIp() {
    Authentication authentication = getAuthentication();

    if (authentication == null) {
        return "";
    }

    Object details = authentication.getDetails();

    if (!(details instanceof WebAuthenticationDetails)) {
        return "";
    }

    WebAuthenticationDetails webDetails = (WebAuthenticationDetails) details;

    return webDetails.getRemoteAddress();
}
项目:spring-io    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:spring-io    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:spring-io    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:spring-io    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:devoxxus-jhipster-microservices-demo    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:devoxxus-jhipster-microservices-demo    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:codemotion-2017-taller-de-jhipster    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:codemotion-2017-taller-de-jhipster    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:shoucang    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (String key : data.keySet()) {
            Object object = data.get(key);

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(key, object.toString());
            } else {
                results.put(key, "null");
            }
        }
    }

    return results;
}
项目:qualitoast    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:qualitoast    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
项目:klask-io    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (String key : data.keySet()) {
            Object object = data.get(key);

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(key, object.toString());
            } else {
                results.put(key, "null");
            }
        }
    }

    return results;
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:AuditEventConverter.java   
/**
 * Internal conversion. This method will allow to save additional data.
 * By default, it will save the object as string
 *
 * @param data the data to convert
 * @return a map of String, String
 */
public Map<String, String> convertDataToStrings(Map<String, Object> data) {
    Map<String, String> results = new HashMap<>();

    if (data != null) {
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            Object object = entry.getValue();

            // Extract the data that will be saved.
            if (object instanceof WebAuthenticationDetails) {
                WebAuthenticationDetails authenticationDetails = (WebAuthenticationDetails) object;
                results.put("remoteAddress", authenticationDetails.getRemoteAddress());
                results.put("sessionId", authenticationDetails.getSessionId());
            } else if (object != null) {
                results.put(entry.getKey(), object.toString());
            } else {
                results.put(entry.getKey(), "null");
            }
        }
    }

    return results;
}