001/* 002 * Copyright (c) 2013 - 2016 TDP Ltd All Rights Reserved. 003 * TDP Ltd grants permission, free of charge, to any person obtaining copies 004 * of this software and its associated documentation files (the "Software"), 005 * to deal in the Software without restriction, including to use, copy, adapt, 006 * publish, distribute, display, perform, sublicense, and sell copies of the 007 * Software, subject to the following condition: You must include the above 008 * copyright notice and this permission notice in all full or partial copies 009 * of the Software. 010 * 011 * TDP LTD PROVIDES THE SOFTWARE "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 012 * INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 013 * PARTICULAR PURPOSE, AND NON-INFRINGMENT. TDP LTD, THE AUTHORS OF THE SOFTWARE, 014 * AND THE OWNERS OF COPYRIGHT IN THE SOFTWARE ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, 015 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING 016 * FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 017 * THE SOFTWARE. 018 */ 019package cz.tdp.kshield.example; 020 021import cz.tdp.kshield.client.KShieldClient; 022import cz.tdp.kshield.client.KShieldClientException; 023import cz.tdp.kshield.client.UserInfo; 024 025//SONAR-IGNORE-FILE 026 027/** 028 * Low level usage of KShieldClient.<br/> 029 * It is recommended to use AuthenticationService instead of KShieldClient, but in certain use cases is possible to use KShieldClient directly<br/> 030 * KShieldClient doesn't depend on Servlet container. 031 * <br/> 032 * @see cz.tdp.kshield.integration.SimpleAuthenticationServiceImpl 033 */ 034public class KShieldClientDemo 035{ 036 public static void main(String[] args) { 037 // URL of KeyShield SSO server 038 String serverURL = "http://192.168.0.42:8485"; 039 040 // IP address of user 041 String ipAddress = "192.168.100.42"; 042 043 // get user for given IP address 044 try { 045 final UserInfo user = new KShieldClient(serverURL).getUserByIP(ipAddress); 046 047 if(user != null) { 048 System.out.print("authenticated user: " + user.getUsername()); 049 } 050 else { 051 System.out.print("No user authenticated at: "+ipAddress); 052 } 053 } 054 catch (KShieldClientException e) { 055 System.out.print("Authentication failed: " + e.getMessage()); 056 } 057 } 058}