001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.core.security;
034:
035: import com.flexive.shared.security.UserTicket;
036:
037: import java.security.Principal;
038:
039: /**
040: * Flexive security principal.
041: *
042: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
043: */
044: public class FxPrincipal implements Principal, java.io.Serializable {
045:
046: private static final long serialVersionUID = 6997956811428518235L;
047: private UserTicket ticket = null;
048:
049: /**
050: * Constructs a new FlexivePrincipal.
051: *
052: * @param ticket the user ticket
053: */
054: public FxPrincipal(UserTicket ticket) {
055: this .ticket = ticket;
056: }
057:
058: /**
059: * Returns the user name for this FlexivePrincipal.
060: * The name can also be retrieved using getUserTicket.getName(), this function
061: * serves as a shorcut.
062: *
063: * @return the user name for this FlexivePrincipal
064: */
065: public String getName() {
066: return this .ticket.getUserName();
067: }
068:
069: /**
070: * Returns the unique user id for this FlexivePrincipal.
071: * The id can also be retrieved using getUserTicket.getId(), this function
072: * serves as a shorcut.
073: *
074: * @return the unique user id for this FlexivePrincipal
075: */
076: public long getId() {
077: return this .ticket.getUserId();
078: }
079:
080: /**
081: * Returns the UserTicket for this FlexivePrincipal.
082: *
083: * @return the UserTicket for this FlexivePrincipal
084: */
085: public UserTicket getUserTicket() {
086: return this .ticket;
087: }
088:
089: /**
090: * Returns a string representation of the FlexivePrincipal.
091: *
092: * @return a string representation of the FlexivePrincipal.
093: */
094: @Override
095: public String toString() {
096: if (this .ticket == null) {
097: return FxPrincipal.class + "@[userId:null;ticket:null]";
098: } else {
099: return this.ticket.toString();
100: }
101: }
102:
103: }
|