001package org.apache.archiva.redback.integration.model;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.redback.users.User;
023import org.apache.archiva.redback.users.UserManager;
024import org.apache.archiva.redback.users.UserManagerException;
025import org.apache.commons.lang3.StringUtils;
026
027import java.io.Serializable;
028
029/**
030 * UserCredentials
031 *
032 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
033 */
034public abstract class UserCredentials
035    implements Serializable
036{
037    // Potentially Editable Field.
038    private String username;
039
040    // Editable Fields.
041    private String password;
042
043    private String confirmPassword;
044
045    private String fullName;
046
047    private String email;
048
049    // Display Only Fields.
050    private String timestampAccountCreation;
051
052    private String timestampLastLogin;
053
054    private String timestampLastPasswordChange;
055
056    public User createUser( UserManager um )
057        throws UserManagerException
058    {
059        User user = um.createUser( username, fullName, email );
060
061        user.setPassword( password );
062
063        return user;
064    }
065
066    public String toString()
067    {
068        StringBuilder sb = new StringBuilder();
069
070        sb.append( "UserCredentials[" );
071        sb.append( "username=" ).append( username );
072        sb.append( ",fullName=" ).append( fullName );
073        sb.append( ",email=" ).append( email );
074        sb.append( ",password=" );
075        if ( StringUtils.isNotEmpty( password ) )
076        {
077            sb.append( "<***>" );
078        }
079        else
080        {
081            sb.append( "<empty>" );
082        }
083        sb.append( ",confirmPassword=" );
084        if ( StringUtils.isNotEmpty( confirmPassword ) )
085        {
086            sb.append( "<***>" );
087        }
088        else
089        {
090            sb.append( "<empty>" );
091        }
092
093        return sb.append( "]" ).toString();
094    }
095
096    public String getConfirmPassword()
097    {
098        return confirmPassword;
099    }
100
101    public void setConfirmPassword( String confirmPassword )
102    {
103        this.confirmPassword = confirmPassword;
104    }
105
106    public String getEmail()
107    {
108        return email;
109    }
110
111    public void setEmail( String email )
112    {
113        this.email = email;
114    }
115
116    public String getFullName()
117    {
118        return fullName;
119    }
120
121    public void setFullName( String fullName )
122    {
123        this.fullName = fullName;
124    }
125
126    public String getPassword()
127    {
128        return password;
129    }
130
131    public void setPassword( String password )
132    {
133        this.password = password;
134    }
135
136    public String getUsername()
137    {
138        return username;
139    }
140
141    public void setUsername( String username )
142    {
143        this.username = username;
144    }
145
146    public abstract boolean isEdit();
147
148    public String getTimestampAccountCreation()
149    {
150        return timestampAccountCreation;
151    }
152
153    public String getTimestampLastLogin()
154    {
155        return timestampLastLogin;
156    }
157
158    public String getTimestampLastPasswordChange()
159    {
160        return timestampLastPasswordChange;
161    }
162
163    public void setTimestampAccountCreation( String timestampAccountCreation )
164    {
165        this.timestampAccountCreation = timestampAccountCreation;
166    }
167
168    public void setTimestampLastLogin( String timestampLastLogin )
169    {
170        this.timestampLastLogin = timestampLastLogin;
171    }
172
173    public void setTimestampLastPasswordChange( String timestampLastPasswordChange )
174    {
175        this.timestampLastPasswordChange = timestampLastPasswordChange;
176    }
177}