001 /* Copyright 2006-2007 the original author or authors. 002 * 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. 014 */ 015 package org.codehaus.groovy.grails.plugins.springsecurity; 016 017 import org.springframework.security.GrantedAuthority; 018 import org.springframework.security.userdetails.User; 019 020 /** 021 * Extends Spring Security's User class to set Grails Domain Class at login, 022 * to load auth class from context. 023 * 024 * @author T.Yamamoto 025 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> 026 */ 027 public class GrailsUserImpl extends User implements GrailsUser { 028 029 private static final long serialVersionUID = 6089520028447407158L; 030 031 private final Object domainClass; 032 033 /** 034 * Constructor. 035 * @param username the username presented to the 036 * <code>DaoAuthenticationProvider</code> 037 * @param password the password that should be presented to the 038 * <code>DaoAuthenticationProvider</code> 039 * @param enabled set to <code>true</code> if the user is enabled 040 * @param accountNonExpired set to <code>true</code> if the account has not 041 * expired 042 * @param credentialsNonExpired set to <code>true</code> if the credentials 043 * have not expired 044 * @param accountNonLocked set to <code>true</code> if the account is not 045 * locked 046 * @param authorities the authorities that should be granted to the caller 047 * if they presented the correct username and password and the user 048 * is enabled 049 * @param user the user domain instance 050 * 051 * @throws IllegalArgumentException if a <code>null</code> value was passed 052 * either as a parameter or as an element in the 053 * <code>GrantedAuthority[]</code> array 054 */ 055 public GrailsUserImpl( 056 final String username, final String password, final boolean enabled, 057 final boolean accountNonExpired, final boolean credentialsNonExpired, 058 final boolean accountNonLocked, final GrantedAuthority[] authorities, 059 final Object user) throws IllegalArgumentException { 060 super(username, password, enabled, accountNonExpired, 061 credentialsNonExpired, accountNonLocked, authorities); 062 domainClass = user; 063 } 064 065 /** 066 * {@inheritDoc} 067 * @see org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser#getDomainClass() 068 */ 069 public Object getDomainClass() { 070 return domainClass; 071 } 072 }