*/
public final void actionPerformed( WikiEvent event )
{
if ( event instanceof WikiSecurityEvent )
{
WikiSecurityEvent e = (WikiSecurityEvent)event;
if ( e.getTarget() != null )
{
switch (e.getType() )
{
case WikiSecurityEvent.GROUP_ADD:
{
Group group = (Group)e.getTarget();
if ( isInGroup( group ) )
{
m_subject.getPrincipals().add( group.getPrincipal() );
}
break;
}
case WikiSecurityEvent.GROUP_REMOVE:
{
Group group = (Group)e.getTarget();
if ( m_subject.getPrincipals().contains( group.getPrincipal() ) )
{
m_subject.getPrincipals().remove( group.getPrincipal() );
}
break;
}
case WikiSecurityEvent.GROUP_CLEAR_GROUPS:
{
m_subject.getPrincipals().removeAll( m_subject.getPrincipals( GroupPrincipal.class ) );
break;
}
case WikiSecurityEvent.LOGIN_INITIATED:
{
// Do nothing
}
case WikiSecurityEvent.PRINCIPAL_ADD:
{
WikiSession target = (WikiSession)e.getTarget();
if ( this.equals( target ) && m_status == AUTHENTICATED )
{
Set<Principal> principals = m_subject.getPrincipals();
principals.add( (Principal)e.getPrincipal());
}
break;
}
case WikiSecurityEvent.LOGIN_ANONYMOUS:
{
WikiSession target = (WikiSession)e.getTarget();
if ( this.equals( target ) )
{
m_status = ANONYMOUS;
// Set the login/user principals and login status
Set<Principal> principals = m_subject.getPrincipals();
m_loginPrincipal = (Principal)e.getPrincipal();
m_userPrincipal = m_loginPrincipal;
// Add the login principal to the Subject, and set the built-in roles
principals.clear();
principals.add( m_loginPrincipal );
principals.add( Role.ALL );
principals.add( Role.ANONYMOUS );
}
break;
}
case WikiSecurityEvent.LOGIN_ASSERTED:
{
WikiSession target = (WikiSession)e.getTarget();
if ( this.equals( target ) )
{
m_status = ASSERTED;
// Set the login/user principals and login status
Set<Principal> principals = m_subject.getPrincipals();
m_loginPrincipal = (Principal)e.getPrincipal();
m_userPrincipal = m_loginPrincipal;
// Add the login principal to the Subject, and set the built-in roles
principals.clear();
principals.add( m_loginPrincipal );
principals.add( Role.ALL );
principals.add( Role.ASSERTED );
}
break;
}
case WikiSecurityEvent.LOGIN_AUTHENTICATED:
{
WikiSession target = (WikiSession)e.getTarget();
if ( this.equals( target ) )
{
m_status = AUTHENTICATED;
// Set the login/user principals and login status
Set<Principal> principals = m_subject.getPrincipals();
m_loginPrincipal = (Principal)e.getPrincipal();
m_userPrincipal = m_loginPrincipal;
// Add the login principal to the Subject, and set the built-in roles
principals.clear();
principals.add( m_loginPrincipal );
principals.add( Role.ALL );
principals.add( Role.AUTHENTICATED );
// Add the user and group principals
injectUserProfilePrincipals(); // Add principals for the user profile
injectGroupPrincipals(); // Inject group principals
}
break;
}
case WikiSecurityEvent.PROFILE_SAVE:
{
WikiSession source = (WikiSession)e.getSource();
if ( this.equals( source ) )
{
injectUserProfilePrincipals(); // Add principals for the user profile
injectGroupPrincipals(); // Inject group principals
}
break;
}
case WikiSecurityEvent.PROFILE_NAME_CHANGED:
{
// Refresh user principals based on new user profile
WikiSession source = (WikiSession)e.getSource();
if ( this.equals( source ) && m_status == AUTHENTICATED )
{
// To prepare for refresh, set the new full name as the primary principal
UserProfile[] profiles = (UserProfile[])e.getTarget();
UserProfile newProfile = profiles[1];
if ( newProfile.getFullname() == null )
{
throw new IllegalStateException( "User profile FullName cannot be null." );
}