001package org.apache.archiva.redback.system; 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.AuthenticationResult; 023import org.apache.archiva.redback.users.User; 024import org.springframework.stereotype.Service; 025 026import java.io.Serializable; 027 028/** 029 * @author Jason van Zyl 030 */ 031@Service( "securitySession" ) 032public class DefaultSecuritySession 033 implements SecuritySession, Serializable 034{ 035 private AuthenticationResult authenticationResult; 036 037 private User user; 038 039 // TODO: ambiguity between this authenticated and authentication result's authenticated is dangerous 040 private boolean authenticated; 041 042 public DefaultSecuritySession() 043 { 044 this.authenticationResult = new AuthenticationResult(); 045 this.user = null; 046 this.authenticated = false; 047 } 048 049 public DefaultSecuritySession( AuthenticationResult authResult ) 050 { 051 this.authenticationResult = authResult; 052 this.user = null; 053 this.authenticated = false; 054 } 055 056 public DefaultSecuritySession( AuthenticationResult authenticationResult, User user ) 057 { 058 this.authenticationResult = authenticationResult; 059 this.user = user; 060 this.authenticated = true; 061 } 062 063 public AuthenticationResult getAuthenticationResult() 064 { 065 return authenticationResult; 066 } 067 068 public User getUser() 069 { 070 return user; 071 } 072 073 public boolean isAuthenticated() 074 { 075 return ( ( user != null ) && authenticated ); 076 } 077 078 @Override 079 public String toString() 080 { 081 return "DefaultSecuritySession{" + 082 "authenticationResult=" + authenticationResult + 083 ", user=" + user + 084 ", authenticated=" + authenticated + 085 '}'; 086 } 087}