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.integration.cas; 020 021import org.jasig.cas.authentication.principal.Credentials; 022import org.jasig.cas.authentication.principal.Principal; 023 024public class KShieldCredentials implements Credentials 025{ 026 private static final long serialVersionUID = 1L; 027 028 private Principal principal; 029 private final String ipAddr; 030 031 public KShieldCredentials(String ipAddr) { 032 this.ipAddr = ipAddr; 033 } 034 035 public Principal getPrincipal() { 036 return principal; 037 } 038 039 public void setPrincipal(Principal principal) { 040 this.principal = principal; 041 } 042 043 public String getIpAddr() { 044 return ipAddr; 045 } 046 047 @Override 048 public int hashCode() { 049 return ipAddr.hashCode(); 050 } 051 052 @Override 053 public boolean equals(Object o) { 054 if (o instanceof KShieldCredentials) { 055 return ((KShieldCredentials)o).getIpAddr().equals(ipAddr); 056 } 057 return false; 058 } 059 060 @Override 061 public String toString() { 062 return this.principal !=null ? this.principal.getId() : "unauthenticated ("+ipAddr+")"; 063 } 064}