1 18 19 20 package org.apache.struts.mock; 21 22 23 import java.security.Principal ; 24 25 26 42 43 public class MockPrincipal implements Principal { 44 45 46 public MockPrincipal() { 47 super(); 48 this.name = ""; 49 this.roles = new String [0]; 50 } 51 52 53 public MockPrincipal(String name) { 54 super(); 55 this.name = name; 56 this.roles = new String [0]; 57 } 58 59 60 public MockPrincipal(String name, String roles[]) { 61 super(); 62 this.name = name; 63 this.roles = roles; 64 } 65 66 67 protected String name = null; 68 69 70 protected String roles[] = null; 71 72 73 public String getName() { 74 return (this.name); 75 } 76 77 78 public boolean isUserInRole(String role) { 79 for (int i = 0; i < roles.length; i++) { 80 if (role.equals(roles[i])) { 81 return (true); 82 } 83 } 84 return (false); 85 } 86 87 88 public boolean equals(Object o) { 89 if (o == null) { 90 return (false); 91 } 92 if (!(o instanceof Principal )) { 93 return (false); 94 } 95 Principal p = (Principal ) o; 96 if (name == null) { 97 return (p.getName() == null); 98 } else { 99 return (name.equals(p.getName())); 100 } 101 } 102 103 104 public int hashCode() { 105 if (name == null) { 106 return ("".hashCode()); 107 } else { 108 return (name.hashCode()); 109 } 110 } 111 112 113 } 114 | Popular Tags |