Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/springConfigXml/AccountManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<zstack:extension interface="org.zstack.header.apimediator.ApiMessageInterceptor"/>
<zstack:extension interface="org.zstack.header.rest.RestAuthenticationBackend"/>
<zstack:extension interface="org.zstack.header.managementnode.PrepareDbInitialValueExtensionPoint" order="9999"/>
<zstack:extension interface="org.zstack.identity.BeforeLoginInAccountPoint" />
</zstack:plugin>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
import static org.zstack.header.identity.AccountConstant.ACCOUNT_REST_AUTHENTICATION_TYPE;

public class AccountManagerImpl extends AbstractService implements AccountManager, SoftDeleteEntityExtensionPoint,
HardDeleteEntityExtensionPoint, ApiMessageInterceptor, RestAuthenticationBackend, PrepareDbInitialValueExtensionPoint {
HardDeleteEntityExtensionPoint, ApiMessageInterceptor, RestAuthenticationBackend, PrepareDbInitialValueExtensionPoint,
BeforeLoginInAccountPoint {
private static final CLogger logger = Utils.getLogger(AccountManagerImpl.class);

@Autowired
Expand Down Expand Up @@ -527,6 +528,10 @@ private void handle(APILogInByUserMsg msg) {
private void handle(APILogInByAccountMsg msg) {
APILogInReply reply = new APILogInReply();

pluginRgty.getExtensionList(BeforeLoginInAccountPoint.class).forEach(point->{
point.beforeLogin(msg);
});

LogInMsg logInMsg = new LogInMsg();
logInMsg.setVerifyCode(msg.getVerifyCode());
logInMsg.setCaptchaUuid(msg.getCaptchaUuid());
Expand Down Expand Up @@ -1790,4 +1795,20 @@ public SessionInventory doAuth(RestAuthenticationParams params) {
session.setUuid(params.authKey);
return session;
}

@Override
public void beforeLogin(APISessionMessage sessionMessage) {
String name = sessionMessage.getUsername();
AccountType thirdPartyType = AccountType.ThirdParty;

AccountVO account = Q.New(AccountVO.class).eq(AccountVO_.name, name).find();

if (account == null) {
return;
}

if (account.getType() == thirdPartyType) {
throw new CloudRuntimeException(String.format("Account [name=%s] [type=%s] cannot local login", name, thirdPartyType));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.zstack.identity;

import org.zstack.header.identity.APISessionMessage;

public interface BeforeLoginInAccountPoint {
void beforeLogin(APISessionMessage sessionMessage);
}