Skip to content

Commit 6a8f831

Browse files
committed
CLOUDSTACK-7361: Fix SAML2UserAuthenticator to not let every login credential
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent a1d0925 commit 6a8f831

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

plugins/user-authenticators/saml2/src/org/apache/cloudstack/SAML2UserAuthenticator.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,44 @@
1616

1717
import com.cloud.server.auth.DefaultUserAuthenticator;
1818
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;
1923
import com.cloud.utils.Pair;
2024
import org.apache.log4j.Logger;
2125

2226
import javax.ejb.Local;
27+
import javax.inject.Inject;
2328
import java.util.Map;
2429

2530
@Local(value = {UserAuthenticator.class})
2631
public class SAML2UserAuthenticator extends DefaultUserAuthenticator {
2732
public static final Logger s_logger = Logger.getLogger(SAML2UserAuthenticator.class);
2833

34+
@Inject
35+
private UserAccountDao _userAccountDao;
36+
@Inject
37+
private UserDao _userDao;
38+
2939
@Override
3040
public Pair<Boolean, ActionOnFailedAuthentication> authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters) {
3141
if (s_logger.isDebugEnabled()) {
3242
s_logger.debug("Trying SAML2 auth for user: " + username);
3343
}
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);
3857
}
3958

4059
@Override

0 commit comments

Comments
 (0)