source: branches/TaskRewrite/src/plugins/acegi-0.5.1/src/java/org/codehaus/groovy/grails/plugins/springsecurity/facebook/FacebookAuthenticationToken.java @ 58

Last change on this file since 58 was 58, checked in by gav, 15 years ago

Configure BootStrap? with latest concepts.
Install and setup Acegi plugin with custom views.
Test Fixture plugin in a test app but couldn't get it to work with Acegi encodePassword() so gave up.

File size: 3.3 KB
Line 
1/* Copyright 2006-2009 the original author or authors.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *      http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15package org.codehaus.groovy.grails.plugins.springsecurity.facebook;
16
17import org.springframework.security.GrantedAuthority;
18import org.springframework.security.providers.AbstractAuthenticationToken;
19
20/**
21 * Authentication token with Facebook-specific extra information.
22 *
23 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
24 */
25public class FacebookAuthenticationToken extends AbstractAuthenticationToken {
26
27        private static final long serialVersionUID = 1022970403466610153L;
28
29        private Status _status;
30        private long _userId;
31        private String _sessionKey;
32        private String _errorMessage;
33
34        /**
35         * Token type.
36         */
37        public static enum Status {
38                /** successful authentication. */
39                success,
40                /** failed authentication. */
41                failure,
42                /** authentication error. */
43                error
44        }
45
46        /**
47         * Created by the OpenIDAuthenticationProvider on successful authentication.
48         * @param authorities  roles
49         * @param userId
50         * @param sessionKey
51         */
52        public FacebookAuthenticationToken(final GrantedAuthority[] authorities,
53                        final long userId, final String sessionKey) {
54                super(authorities);
55                _status = Status.success;
56                _userId = userId;
57                _sessionKey = sessionKey;
58                setAuthenticated(true);
59        }
60
61        /**
62         * Created by {@link FacebookAuthenticationProcessingFilter} from Facebook login info,
63         * but before loading roles.
64         * @param userId  the UID
65         * @param sessionKey  the session key
66         */
67        public FacebookAuthenticationToken(final long userId, final String sessionKey) {
68                super(new GrantedAuthority[0]);
69                _status = Status.success;
70                _userId = userId;
71                _sessionKey = sessionKey;
72                setAuthenticated(false);
73        }
74
75        /**
76         * Create a failure token.
77         * @param status  a non-success token
78         * @param errorMessage  the error message
79         */
80        public FacebookAuthenticationToken(final Status status, final String errorMessage) {
81                super(new GrantedAuthority[0]);
82                _status = status;
83                _errorMessage = errorMessage;
84                setAuthenticated(false);
85        }
86
87        /**
88         * {@inheritDoc}
89         * @see org.springframework.security.providers.AbstractAuthenticationToken#getCredentials()
90         */
91        public Object getCredentials() {
92                // we don't have access to password
93                return null;
94        }
95
96        /**
97         * {@inheritDoc}
98         * @see org.springframework.security.providers.AbstractAuthenticationToken#getPrincipal()
99         */
100        public Object getPrincipal() {
101                return _userId;
102        }
103
104        /**
105         * The Facebook UID.
106         * @return  the uid
107         */
108        public long getUserId() {
109                return _userId;
110        }
111
112        /**
113         * The status.
114         * @return  the status
115         */
116        public Status getStatus() {
117                return _status;
118        }
119
120        /**
121         * The login session key.
122         * @return  the key
123         */
124        public String getSessionKey() {
125                return _sessionKey;
126        }
127
128        /**
129         * Get the error message (if status is <code>error</code>).
130         * @return  the message
131         */
132        public String getErrorMessage() {
133                return _errorMessage;
134        }
135}
Note: See TracBrowser for help on using the repository browser.