001/* 002 * JGrapes Event Driven Framework 003 * Copyright (C) 2024 Michael N. Lipp 004 * 005 * This program is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Affero General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License along 016 * with this program; if not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jgrapes.webconsole.base.events; 020 021import java.util.ArrayList; 022import java.util.List; 023import javax.security.auth.Subject; 024import org.jgrapes.core.Event; 025 026/** 027 * The Class UserAuthenticated. 028 */ 029public class UserAuthenticated extends Event<Void> { 030 031 private final Event<?> forLogin; 032 private final Subject subject; 033 private final List<String> authenticators; 034 035 /** 036 * Instantiates successful user authentication. 037 * 038 * @param forLogin the for login 039 */ 040 public UserAuthenticated(Event<?> forLogin, Subject subject) { 041 this.forLogin = forLogin; 042 this.subject = subject; 043 authenticators = new ArrayList<>(); 044 } 045 046 /** 047 * Gets the event that initiated the login process. 048 * 049 * @return the for login 050 */ 051 public Event<?> forLogin() { 052 return forLogin; 053 } 054 055 /** 056 * Gets the subject. 057 * 058 * @return the subject 059 */ 060 public Subject subject() { 061 return subject; 062 } 063 064 /** 065 * Add the name of a component that has authenticated the user 066 * or added roles. 067 * 068 * @param by the by 069 * @return the user authenticated 070 */ 071 @SuppressWarnings({ "PMD.ShortMethodName", "PMD.ShortVariable" }) 072 public UserAuthenticated by(String by) { 073 authenticators.add(by); 074 return this; 075 } 076 077 /** 078 * Return the names of the components that have authenticated the user 079 * or added roles. 080 * 081 * @return the list 082 */ 083 @SuppressWarnings("PMD.ShortMethodName") 084 public List<String> by() { 085 return authenticators; 086 } 087}