• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/trunk/components/common/src/ome/system/Login.java

Revision 1167, 5.0 kB (checked in by jmoore, 2 years ago)

[svn:keywords] Id,Date,Revision,URL for *.java and Id for *.xml

  • Property svn:keywords set to
    Date
    Revision
    Id
    URL
Line 
1/*
2 * ome.system.Login
3 *
4 *   Copyright 2006 University of Dundee. All rights reserved.
5 *   Use is subject to license terms supplied in LICENSE.txt
6 */
7
8package ome.system;
9
10// Java imports
11import java.util.Properties;
12
13// Third-party libraries
14
15// Application-internal dependencies
16import ome.conditions.ApiUsageException;
17
18/**
19 * Provides simplified handling of login properties when creating a
20 * {@link ome.system.ServiceFactory}. For more complicated uses,
21 * {@link java.util.Properties} can also be used. In which case, the constant
22 * {@link java.lang.String strings} provided in this class can be used as the
23 * keys to the {@link java.util.Properties properties instance} passed to
24 * {@link ome.system.ServiceFactory#ServiceFactory(Properties)}.
25 *
26 * @author Josh Moore &nbsp;&nbsp;&nbsp;&nbsp; <a
27 *         href="mailto:josh.moore@gmx.de">josh.moore@gmx.de</a>
28 * @version 1.0
29 * @see ome.system.ServiceFactory <small> (<b>Internal version:</b> $Rev$
30 *      $Date$) </small>
31 * @since 1.0
32 */
33public class Login {
34
35    /**
36     * Java property name for use in configuration of client login.
37     */
38    public final static String OMERO_USER = "omero.user";
39
40    /**
41     * Java property name for use in configuration of client login.
42     */
43    public final static String OMERO_GROUP = "omero.group";
44
45    /**
46     * Java property name for use in configuration of client login.
47     */
48    public final static String OMERO_PASS = "omero.pass";
49
50    /**
51     * Java property name for use in configuration of client login.
52     */
53    public final static String OMERO_EVENT = "omero.event";
54
55    /**
56     * {@link CopyOfLogin} constant which has username and password values set
57     * to null and other values set to their default. This will permit logging
58     * in as an anonymous user.
59     */
60    public final static Login GUEST = new Login() {
61        @Override
62        public Properties asProperties() {
63            Properties p = super.asProperties();
64            p.setProperty(OMERO_USER, null);
65            p.setProperty(OMERO_PASS, null);
66            p.setProperty(OMERO_GROUP, null);
67            p.setProperty(OMERO_EVENT, null);
68            return p;
69        }
70    };
71
72    private String _user, _group, _pass, _event;
73
74    // Need at least user and password
75    private Login() {
76    }
77
78    /**
79     * standard constructor which leaves OMERO_GROUP and OMERO_EVENT null.
80     *
81     * @param user
82     *            {@link ome.model.meta.Experimenter#getOmeName()}. Not null.
83     * @param password
84     *            Cleartext password. Not null.
85     */
86    public Login(String user, String password) {
87        if (user == null || password == null) {
88            throw new ApiUsageException("User and password arguments "
89                    + "to Login constructor cannot be null");
90        }
91        _user = user;
92        _pass = password;
93    }
94
95    /**
96     * extended constructor. As with {@link #Login(String, String)}, user and
97     * password may not be null.
98     *
99     * @param user
100     *            {@link ome.model.meta.Experimenter#getOmeName()}. Not null.
101     * @param password
102     *            Cleartext password. Not null.
103     * @param group
104     *            Group name. May be null.
105     * @param event
106     *            Enumeration value of the EventType. May be null.
107     */
108    public Login(String user, String password, String group, String event) {
109        this(user, password);
110        _group = group;
111        _event = event;
112    }
113
114    // ~ Views
115    // =========================================================================
116
117    /**
118     * produces a copy of the internal fields as a {@link java.util.Properties}
119     * instance. Only those keys are present for which a field is non-null.
120     *
121     * @return Properties. Not null.
122     */
123    public Properties asProperties() {
124        Properties p = new Properties();
125        p.setProperty(OMERO_USER, _user);
126        p.setProperty(OMERO_PASS, _pass);
127        if (_group != null) {
128            p.setProperty(OMERO_GROUP, _group);
129        }
130        if (_event != null) {
131            p.setProperty(OMERO_EVENT, _event);
132        }
133        return p;
134    }
135
136    /**
137     * simple getter for the user name passed into the constructor
138     *
139     * @return {@link ome.model.meta.Experimenter#getOmeName() user name}. Not
140     *         null unless Login == {@link Login#GUEST}.
141     */
142    public String getName() {
143        return _user;
144    }
145
146    /**
147     * simple getter for the password passed into the constructor
148     *
149     * @return password. Not null unless Login == {@link Login#GUEST}
150     */
151    public String getPassword() {
152        return _pass;
153    }
154
155    /**
156     * simple getter for the group name passed into the constructor
157     *
158     * @return {@link ome.model.meta.ExperimenterGroup#getName() group name}.
159     *         May be null.
160     */
161    public String getGroup() {
162        return _group;
163    }
164
165    /**
166     * simple getter for the event type passed into the constructor
167     *
168     * @return {@link ome.model.enums.EventType event type}. May be null.
169     */
170    public String getEvent() {
171        return _event;
172    }
173
174}
Note: See TracBrowser for help on using the browser.

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/