001package org.apache.archiva.redback.authentication; 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.authentication.AuthenticationDataSource; 023import org.apache.commons.lang3.StringUtils; 024import org.springframework.context.annotation.Scope; 025import org.springframework.stereotype.Service; 026 027/** 028 * PasswordBasedAuthenticationDataSource: the username is considered the principal with this data source 029 * 030 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 031 * 032 * 033 */ 034@Service("authenticationDataSource#password") 035@Scope("prototype") 036public class PasswordBasedAuthenticationDataSource 037 implements AuthenticationDataSource 038{ 039 private String password; 040 041 private String principal; 042 043 public PasswordBasedAuthenticationDataSource() 044 { 045 046 } 047 048 public PasswordBasedAuthenticationDataSource( String principal, String password ) 049 { 050 this.principal = principal; 051 this.password = password; 052 } 053 054 public String getPassword() 055 { 056 return password; 057 } 058 059 public String getUsername() 060 { 061 return principal; 062 } 063 064 public void setPassword( String password ) 065 { 066 this.password = password; 067 } 068 069 public void setPrincipal( String principal ) 070 { 071 this.principal = principal; 072 } 073 074 public String toString() 075 { 076 StringBuilder sb = new StringBuilder(); 077 sb.append( "PasswordBasedAuthenticationDataSource[" ); 078 sb.append( "principal=" ).append( principal ); 079 sb.append( ",password=" ); 080 if ( StringUtils.isNotEmpty( password ) ) 081 { 082 // Intentionally not showing real password 083 sb.append( "***" ); 084 } 085 sb.append( ']' ); 086 return sb.toString(); 087 } 088 089 public boolean isEnforcePasswordChange() 090 { 091 return true; 092 } 093}