本文整理汇总了Java中org.springframework.security.web.authentication.WebAuthenticationDetails.getRemoteAddress方法的典型用法代码示例。如果您正苦于以下问题:Java WebAuthenticationDetails.getRemoteAddress方法的具体用法?Java WebAuthenticationDetails.getRemoteAddress怎么用?Java WebAuthenticationDetails.getRemoteAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.web.authentication.WebAuthenticationDetails
的用法示例。
在下文中一共展示了WebAuthenticationDetails.getRemoteAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
log.debug("Authentication OK: {}", event.getAuthentication().getName());
// Activity log
Object details = event.getAuthentication().getDetails();
String params = null;
if (details instanceof WebAuthenticationDetails) {
WebAuthenticationDetails wad = (WebAuthenticationDetails) details;
params = wad.getRemoteAddress();
} else if (GenericHolder.get() != null) {
params = (String) GenericHolder.get();
}
UserActivity.log(event.getAuthentication().getName(), "LOGIN", null, null, params);
} else if (event instanceof AuthenticationFailureBadCredentialsEvent) {
log.info("Authentication ERROR: {}", event.getAuthentication().getName());
}
}
示例2: onApplicationEvent
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(AbstractSubProtocolEvent ev) {
if(ev instanceof SessionSubscribeEvent) {
sendHistoryToNewSubscriber(ev);
} else if(ev instanceof SessionConnectEvent || ev instanceof SessionDisconnectEvent) {
Authentication user = (Authentication)ev.getUser();
Object details = user.getDetails();
String sessionId = null;
String address = null;
if(details instanceof WebAuthenticationDetails) {
WebAuthenticationDetails wad = (WebAuthenticationDetails) details;
address = wad.getRemoteAddress();
sessionId = wad.getSessionId();
}
if(ev instanceof SessionDisconnectEvent) {
log.info("WebSocket user \"{}\" was disconnected from {} with HTTP session: {}", user.getName(), address, sessionId);
} else {
log.info("WebSocket user \"{}\" was connected from {} with HTTP session: {}", user.getName(), address, sessionId);
}
}
}
示例3: getCurrentUserIp
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
/**
* 取得当前用户登录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();
}
示例4: saveEvent
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
private static String saveEvent(LoginlogService loginlogService, Authentication authentication) {
Object details = authentication.getDetails();
String remoteAddress = "";
boolean success = authentication.isAuthenticated();
String type = authentication.getClass().getSimpleName();
final String tokenSuffix = "AuthenticationToken";
if (type.endsWith(tokenSuffix)) {
type = type.substring(0, type.length() - tokenSuffix.length());
}
if (details instanceof WebAuthenticationDetails) {
WebAuthenticationDetails webAuthenticationDetails = (WebAuthenticationDetails) details;
remoteAddress = webAuthenticationDetails.getRemoteAddress();
}
loginlogService.save(LoginLog.builder().ip(remoteAddress).success(success).type(type).user(authentication.getName()).build());
return remoteAddress;
}
示例5: getRemoteAddress
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Nonnull
private static String getRemoteAddress(@Nonnull final Authentication authentication) {
final Object details = authentication.getDetails();
if (details != null) {
if (details instanceof WebAuthenticationDetails) {
final WebAuthenticationDetails webAuthenticationDetails = (WebAuthenticationDetails) details;
return webAuthenticationDetails.getRemoteAddress();
} else if (details instanceof ExternalAuthenticationDetails) {
final ExternalAuthenticationDetails externalAuthenticationDetails =
(ExternalAuthenticationDetails) details;
return externalAuthenticationDetails.getRemoteAddress();
}
}
throw new InternalAuthenticationServiceException("Authentication details is missing");
}
示例6: getCurrentUserIp
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
/**
* Get current user's IP address.
*
* @return IP
*/
public static String getCurrentUserIp() {
Authentication authentication = getAuthentication();
if (authentication == null) {
return "";
}
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails) details;
return oAuth2AuthenticationDetails.getRemoteAddress();
}
if (details instanceof WebAuthenticationDetails) {
WebAuthenticationDetails webDetails = (WebAuthenticationDetails) details;
return webDetails.getRemoteAddress();
}
return "";
}
示例7: getDetailsMap
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
public Map<String, String> getDetailsMap(final Authentication authentication){
if(authentication == null){
return new HashMap<String, String>();
}else{
//GET SESSION ID AND IP ADDRESS
WebAuthenticationDetails metaDetails = (WebAuthenticationDetails) authentication.getDetails();
String sessionId = ((metaDetails == null)? null : metaDetails.getSessionId());
String ipAddress = ((metaDetails == null)? null : metaDetails.getRemoteAddress());
HashMap<String, String> detailsMap = new HashMap<String, String>();
detailsMap.put(MAP_KEY_IP_ADDRESS, ipAddress);
detailsMap.put(MAP_KEY_SESSION_ID, sessionId);
//GET USERNAME
Object user = authentication.getPrincipal();
String username = null;
if(user instanceof OWFUserDetailsImpl){
username = ((OWFUserDetailsImpl)user).getUsername();
} else {
username = ((user instanceof String) ? (String)user : null);
}
detailsMap.put(MAP_KEY_USERNAME, username);
return detailsMap;
}
}
示例8: newRevision
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Override
public void newRevision(Object revisionEntity) {
AuditRevision auditedRevision = (AuditRevision) revisionEntity;
String userName = SecurityUtil.getUsername();
/* possible approach to get IP address of the user
- http://stackoverflow.com/questions/12786123/ip-filter-using-spring-security
- http://forum.springsource.org/showthread.php?18071-pass-ip-address-to-authentication-provider
*/
WebAuthenticationDetails auth = (WebAuthenticationDetails)
SecurityContextHolder.getContext().getAuthentication().getDetails();
if(auth != null) {
String ipAddress = auth.getRemoteAddress();
auditedRevision.setIpAddress(ipAddress);
}
auditedRevision.setUsername(userName);
}
示例9: vote
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Override
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> configList) {
if (!(authentication.getDetails() instanceof WebAuthenticationDetails)) {
return ACCESS_DENIED;
}
WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
String address = details.getRemoteAddress();
int result = ACCESS_ABSTAIN;
for (ConfigAttribute config : configList) {
result = ACCESS_DENIED;
if (IP_LOCAL_HOST.equals(config.getAttribute())) {
if (address.equals("127.0.0.1") || address.equals("0:0:0:0:0:0:0:1")) {
return ACCESS_GRANTED;
}
}
}
return result;
}
示例10: Message
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
public Message(MessageType type, String message)
{
this.type = type;
this.message = message;
SecurityContext context = SecurityContextHolder.getContext ();
if (context == null)
{
return;
}
Authentication auth =
SecurityContextHolder.getContext ().getAuthentication ();
if (auth == null)
{
return;
}
String user;
if (auth.getDetails () instanceof WebAuthenticationDetails)
{
WebAuthenticationDetails details =
(WebAuthenticationDetails) auth.getDetails ();
user = "["+((User)auth.getPrincipal ()).getUsername () +
" @ "+details.getRemoteAddress ()+"] ";
}
else
{
user = "["+auth.getPrincipal ().toString () + "] ";
}
this.message = user + message;
}
示例11: getUserIp
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
public String getUserIp(Authentication authentication) {
if (authentication == null) {
return "";
}
Object details = authentication.getDetails();
if (!(details instanceof WebAuthenticationDetails)) {
return "";
}
WebAuthenticationDetails webDetails = (WebAuthenticationDetails) details;
return webDetails.getRemoteAddress();
}
示例12: isIpCanBeUsed4LiveFullAnonymous
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
private Boolean isIpCanBeUsed4LiveFullAnonymous(Authentication auth) {
WebAuthenticationDetails wad = (WebAuthenticationDetails) auth.getDetails();
String userIPAddress = wad.getRemoteAddress();
if (ipsStart4LiveFullAnonymousList != null && !ipsStart4LiveFullAnonymousList.isEmpty()) {
for (String ipStart : ipsStart4LiveFullAnonymousList) {
if (userIPAddress.startsWith(ipStart)) {
return true;
}
}
}
return false;
}
示例13: equals
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
public boolean equals(Object obj) {
if (obj instanceof WebAuthenticationDetails) {
WebAuthenticationDetails rhs = (WebAuthenticationDetails) obj;
if ((remoteAddress == null) && (rhs.getRemoteAddress() != null)) {
return false;
}
if ((remoteAddress != null) && (rhs.getRemoteAddress() == null)) {
return false;
}
if (remoteAddress != null) {
if (!remoteAddress.equals(rhs.getRemoteAddress())) {
return false;
}
}
if ((sessionId == null) && (rhs.getSessionId() != null)) {
return false;
}
if ((sessionId != null) && (rhs.getSessionId() == null)) {
return false;
}
if (sessionId != null) {
if (!sessionId.equals(rhs.getSessionId())) {
return false;
}
}
return true;
}
return false;
}
开发者ID:saintdan,项目名称:spring-microservices-boilerplate,代码行数:38,代码来源:CustomWebAuthenticationDetails.java
示例14: equals
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
@Override
public boolean equals(Object obj) {
if (obj instanceof WebAuthenticationDetails) {
WebAuthenticationDetails rhs = (WebAuthenticationDetails) obj;
if ((getRemoteAddress() == null) && (rhs.getRemoteAddress() != null)) {
return false;
}
if ((getRemoteAddress() != null) && (rhs.getRemoteAddress() == null)) {
return false;
}
if (getRemoteAddress() != null) {
if (!getRemoteAddress().equals(rhs.getRemoteAddress())) {
return false;
}
}
if ((getSessionId() == null) && (rhs.getSessionId() != null)) {
return false;
}
if ((getSessionId() != null) && (rhs.getSessionId() == null)) {
return false;
}
if (getSessionId() != null) {
if (!getSessionId().equals(rhs.getSessionId())) {
return false;
}
}
return true;
}
return false;
}
示例15: createEvent
import org.springframework.security.web.authentication.WebAuthenticationDetails; //导入方法依赖的package包/类
private EventBuilder createEvent(String uei, AbstractAuthenticationEvent authEvent) {
EventBuilder builder = new EventBuilder(uei, "OpenNMS.WebUI");
builder.setTime(new Date(authEvent.getTimestamp()));
org.springframework.security.core.Authentication auth = authEvent.getAuthentication();
if (auth != null && auth.getName() != null) {
builder.addParam("user", WebSecurityUtils.sanitizeString(auth.getName()));
}
if (auth != null && auth.getDetails() != null && auth.getDetails() instanceof WebAuthenticationDetails) {
WebAuthenticationDetails webDetails = (WebAuthenticationDetails) auth.getDetails();
if (webDetails.getRemoteAddress() != null) {
builder.addParam("ip", webDetails.getRemoteAddress());
}
}
return builder;
}