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.
372e0da96e757a977154063f980d3f4e1abd41cf09Nick Pelly * @hide
389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */
393998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejunpublic final class PasswordAuthentication {
409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
413998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun    private byte[] mUserName;
429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
433998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun    private final byte[] mPassword;
449439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
4605ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun     * Creates a new <code>PasswordAuthentication</code> with the user name and
4705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun     * password provided.
489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @param userName the user name to include; this may be <code>null</code>
499439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @param password the password to include in the response
503998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun     * @throws NullPointerException if <code>password</code> is
5105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun     *         <code>null</code>
529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
533998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun    public PasswordAuthentication(final byte[] userName, final byte[] password) {
549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        if (userName != null) {
553998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun            mUserName = new byte[userName.length];
563998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun            System.arraycopy(userName, 0, mUserName, 0, userName.length);
579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly        }
589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
593998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun        mPassword = new byte[password.length];
603998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun        System.arraycopy(password, 0, mPassword, 0, password.length);
619439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
629439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
6405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun     * Retrieves the user name that was specified in the constructor. The user
6505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun     * name may be <code>null</code>.
669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @return the user name
679439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    public byte[] getUserName() {
693998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun        return mUserName;
709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly
729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    /**
739439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * Retrieves the password.
749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     * @return the password
759439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly     */
769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    public byte[] getPassword() {
773998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun        return mPassword;
789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly    }
799439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly}
80