PasswordAuthentication.java revision 9439a7fe517b858bc5e5c654b459315e4722feb2
19439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly/*
29439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Copyright (c) 2008-2009, Motorola, Inc.
39439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
49439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * All rights reserved.
59439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
69439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Redistribution and use in source and binary forms, with or without
79439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * modification, are permitted provided that the following conditions are met:
89439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
99439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Redistributions of source code must retain the above copyright notice,
109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * this list of conditions and the following disclaimer.
119439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Redistributions in binary form must reproduce the above copyright notice,
139439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * this list of conditions and the following disclaimer in the documentation
149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * and/or other materials provided with the distribution.
159439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Neither the name of the Motorola, Inc. nor the names of its contributors
179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * may be used to endorse or promote products derived from this software
189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * without specific prior written permission.
199439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
209439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
219439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
249439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * POSSIBILITY OF SUCH DAMAGE.
319439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */
329439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
339439a7fe517b858bc5e5c654b459315e4722feb2Nick Pellypackage javax.obex;
349439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly/**
369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * This class holds user name and password combinations.
379439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly *
389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @version 0.3 November 28, 2008
399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */
409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pellypublic class PasswordAuthentication {
419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    private byte[] userName;
439439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
449439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    private byte[] password;
459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
469439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * Creates a new <code>PasswordAuthentication</code> with the user name
489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * and password provided.
499439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     *
509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @param userName the user name to include; this may be <code>null</code>
519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     *
529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @param password the password to include in the response
539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     *
549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @exception NullPointerException if <code>password</code> is
559439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * <code>null</code>
569439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    public PasswordAuthentication(byte[] userName, byte[] password) {
589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        if (userName != null) {
599439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly            this.userName = new byte[userName.length];
609439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly            System.arraycopy(userName, 0, this.userName, 0, userName.length);
619439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        }
629439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        this.password = new byte[password.length];
649439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        System.arraycopy(password, 0, this.password, 0, password.length);
659439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
679439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * Retrieves the user name that was specified in the constructor.
699439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * The user name may be <code>null</code>.
709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     *
719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @return the user name
729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
739439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    public byte[] getUserName() {
749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        return this.userName;
759439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
779439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * Retrieves the password.
799439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     *
809439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @return the password
819439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    public byte[] getPassword() {
839439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        return this.password;
849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
859439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly}
86