當前位置: 首頁>>代碼示例>>Java>>正文


Java WebAuthenticationDetails.getRemoteAddress方法代碼示例

本文整理匯總了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());
	}
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:22,代碼來源:LoggerListener.java

示例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);
        }
    }
}
 
開發者ID:codeabovelab,項目名稱:haven-platform,代碼行數:22,代碼來源:EventRouter.java

示例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();
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:21,代碼來源:SpringSecurityUtils.java

示例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;
}
 
開發者ID:zjnu-acm,項目名稱:judge,代碼行數:17,代碼來源:LoginListener.java

示例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");
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:17,代碼來源:RemoteAddressBlocker.java

示例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 "";
}
 
開發者ID:saintdan,項目名稱:spring-microservices-boilerplate,代碼行數:22,代碼來源:SpringSecurityUtils.java

示例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;
	}
}
 
開發者ID:ozoneplatform,項目名稱:owf-security,代碼行數:26,代碼來源:AuthenticationUtils.java

示例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);
}
 
開發者ID:charybr,項目名稱:spring-data-rest-acl,代碼行數:19,代碼來源:AuditingRevisionListener.java

示例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;
}
 
開發者ID:AncientMariner,項目名稱:SpringByExample,代碼行數:19,代碼來源:IpAddressVoter.java

示例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;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:31,代碼來源:Message.java

示例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();
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:16,代碼來源:SpringSecurityListener.java

示例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;
}
 
開發者ID:EsupPortail,項目名稱:esup-nfc-tag-server,代碼行數:13,代碼來源:LiveLongPoolController.java

示例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;
}
 
開發者ID:rockagen,項目名稱:security-stateless-samples,代碼行數:39,代碼來源:ExWebAuthenticationDetails.java

示例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;
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:16,代碼來源:SecurityAuthenticationEventOnmsEventBuilder.java


注:本文中的org.springframework.security.web.authentication.WebAuthenticationDetails.getRemoteAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。