|
16 | 16 |
|
17 | 17 | import com.cloud.server.auth.DefaultUserAuthenticator; |
18 | 18 | import com.cloud.server.auth.UserAuthenticator; |
| 19 | +import com.cloud.user.User; |
| 20 | +import com.cloud.user.UserAccount; |
| 21 | +import com.cloud.user.dao.UserAccountDao; |
| 22 | +import com.cloud.user.dao.UserDao; |
19 | 23 | import com.cloud.utils.Pair; |
20 | 24 | import org.apache.log4j.Logger; |
21 | 25 |
|
22 | 26 | import javax.ejb.Local; |
| 27 | +import javax.inject.Inject; |
23 | 28 | import java.util.Map; |
24 | 29 |
|
25 | 30 | @Local(value = {UserAuthenticator.class}) |
26 | 31 | public class SAML2UserAuthenticator extends DefaultUserAuthenticator { |
27 | 32 | public static final Logger s_logger = Logger.getLogger(SAML2UserAuthenticator.class); |
28 | 33 |
|
| 34 | + @Inject |
| 35 | + private UserAccountDao _userAccountDao; |
| 36 | + @Inject |
| 37 | + private UserDao _userDao; |
| 38 | + |
29 | 39 | @Override |
30 | 40 | public Pair<Boolean, ActionOnFailedAuthentication> authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters) { |
31 | 41 | if (s_logger.isDebugEnabled()) { |
32 | 42 | s_logger.debug("Trying SAML2 auth for user: " + username); |
33 | 43 | } |
34 | | - |
35 | | - // TODO: implement core logic, HTTP GET redirections etc. |
36 | | - |
37 | | - return new Pair<Boolean, ActionOnFailedAuthentication>(true, null); |
| 44 | + final UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId); |
| 45 | + if (userAccount == null) { |
| 46 | + s_logger.debug("Unable to find user with " + username + " in domain " + domainId); |
| 47 | + return new Pair<Boolean, ActionOnFailedAuthentication>(false, null); |
| 48 | + } else { |
| 49 | + User user = _userDao.getUser(userAccount.getId()); |
| 50 | + // TODO: check SAMLRequest, signature etc. from requestParameters |
| 51 | + if (user != null && user.getUuid().startsWith("saml")) { |
| 52 | + return new Pair<Boolean, ActionOnFailedAuthentication>(true, null); |
| 53 | + } |
| 54 | + } |
| 55 | + // Deny all by default |
| 56 | + return new Pair<Boolean, ActionOnFailedAuthentication>(false, ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT); |
38 | 57 | } |
39 | 58 |
|
40 | 59 | @Override |
|
0 commit comments