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.springframework.context.annotation.Scope; 024import org.springframework.stereotype.Service; 025 026 027/** 028 * TokenBasedAuthenticationDataSource 029 * 030 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 031 * 032 */ 033@Service( "authenticationDataSource#token" ) 034@Scope( "prototype" ) 035public class TokenBasedAuthenticationDataSource 036 implements AuthenticationDataSource 037{ 038 private String token; 039 040 private String principal; 041 042 private boolean enforcePasswordChange = true; 043 044 public TokenBasedAuthenticationDataSource( String principal ) 045 { 046 this.principal = principal; 047 } 048 049 public TokenBasedAuthenticationDataSource() 050 { 051 } 052 053 public String getUsername() 054 { 055 return principal; 056 } 057 058 public String getToken() 059 { 060 return token; 061 } 062 063 public void setPrincipal( String principal ) 064 { 065 this.principal = principal; 066 } 067 068 public void setToken( String token ) 069 { 070 this.token = token; 071 } 072 073 public String toString() 074 { 075 StringBuilder sb = new StringBuilder(); 076 sb.append( "TokenBasedAuthenticationDataSource[" ); 077 sb.append( "principal=" ).append( principal ); 078 sb.append( ",token=" ).append( token ); 079 sb.append( ']' ); 080 return sb.toString(); 081 } 082 083 public void setEnforcePasswordChange( boolean enforcePasswordChange ) 084 { 085 this.enforcePasswordChange = enforcePasswordChange; 086 } 087 088 public boolean isEnforcePasswordChange() 089 { 090 return enforcePasswordChange; 091 } 092}