[4173] | 1 | /* |
---|
| 2 | * Copyright (C) 2013 DASISH |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or |
---|
| 5 | * modify it under the terms of the GNU General Public License |
---|
| 6 | * as published by the Free Software Foundation; either version 2 |
---|
| 7 | * of the License, or (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 17 | */ |
---|
| 18 | package eu.dasish.annotation.backend.rest; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * |
---|
| 22 | * @author olhsha |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | import java.security.Principal; |
---|
| 26 | //import java.util.List; |
---|
| 27 | // |
---|
| 28 | //import org.apache.commons.codec.digest.DigestUtils; |
---|
| 29 | // |
---|
| 30 | //import de.mpg.aai.shhaa.model.AuthAttribute; |
---|
| 31 | //import de.mpg.aai.shhaa.model.AuthAttributes; |
---|
| 32 | //import de.mpg.aai.shhaa.model.AuthPrincipal; |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Wrapper class to hold the userPrincipal and a displayName |
---|
| 36 | * |
---|
| 37 | */ |
---|
| 38 | public class UserCredentials { |
---|
| 39 | |
---|
| 40 | private final Principal userPrincipal; |
---|
| 41 | |
---|
| 42 | public UserCredentials(Principal userPrincipal) { |
---|
| 43 | this.userPrincipal = userPrincipal; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public Principal getPrincipal() { |
---|
| 47 | return userPrincipal; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public String getPrincipalName() { |
---|
| 51 | return userPrincipal.getName(); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | // public String getPrincipalNameMD5Hex() { |
---|
| 55 | // return getPrincipalNameMD5Hex(userPrincipal.getName()); |
---|
| 56 | // } |
---|
| 57 | // |
---|
| 58 | // public static String getPrincipalNameMD5Hex(String name){ |
---|
| 59 | // return DigestUtils.md5Hex(name); |
---|
| 60 | // } |
---|
| 61 | |
---|
| 62 | public String getDisplayName() { |
---|
| 63 | String result = null; |
---|
| 64 | // if (userPrincipal instanceof AuthPrincipal) { |
---|
| 65 | // List<String> displayNamesAttributes = Configuration.getInstance().getDisplayNameShibbolethKeys(); |
---|
| 66 | // AuthPrincipal authPrincipal = (AuthPrincipal) userPrincipal; |
---|
| 67 | // for (String key : displayNamesAttributes) { |
---|
| 68 | // result = getValue(authPrincipal, key); |
---|
| 69 | // if (result != null) { |
---|
| 70 | // break; |
---|
| 71 | // } |
---|
| 72 | // } |
---|
| 73 | // } |
---|
| 74 | if (result == null) { |
---|
| 75 | result = getPrincipalName(); |
---|
| 76 | } |
---|
| 77 | return result; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | // private String getValue(AuthPrincipal authPrincipal, String key) { |
---|
| 81 | // String result = null; |
---|
| 82 | // AuthAttributes attributes = authPrincipal.getAttribues(); |
---|
| 83 | // if (attributes != null) { |
---|
| 84 | // AuthAttribute<String> authAttribute = (AuthAttribute<String>) attributes.get(key); |
---|
| 85 | // if (authAttribute != null) { |
---|
| 86 | // result = authAttribute.getValue(); |
---|
| 87 | // } |
---|
| 88 | // } |
---|
| 89 | // return result; |
---|
| 90 | // } |
---|
| 91 | |
---|
| 92 | @Override |
---|
| 93 | public String toString() { |
---|
| 94 | return getPrincipal().toString(); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|