Skip to content

Commit a090b84

Browse files
committed
OPSMN-7000: Allowed super admins to disallow logins from users of a specific auth domain.
1 parent d17134c commit a090b84

File tree

12 files changed

+66
-5
lines changed

12 files changed

+66
-5
lines changed

WEB-INF/resources/com/krishagni/catissueplus/core/repository/hbm/AuthDomain.hbm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
<many-to-one name="authProvider" column="PROVIDER_ID" cascade="all"/>
1919

20+
<property name="allowLogins" column="ALLOW_LOGINS" not-null="true" />
21+
2022
<query name="getDomainByName">
2123
select
2224
d

WEB-INF/resources/db/12.1/schema.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@
2525
</column>
2626
</addColumn>
2727
</changeSet>
28-
</databaseChangeLog>
28+
29+
<changeSet author="vpawar" id="Auth domain property to specify whether logins are allowed from a specified domain">
30+
<addColumn tableName="OS_AUTH_DOMAINS">
31+
<column name="ALLOW_LOGINS" type="${boolean.type}" defaultValueBoolean="true">
32+
<constraints nullable="false" />
33+
</column>
34+
</addColumn>
35+
</changeSet>
36+
</databaseChangeLog>

WEB-INF/resources/errors/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ auth_imp_token_exp=Impersonated user token has expired.
14681468

14691469
auth_otp_expired=User login OTP has expired.
14701470

1471+
auth_domain_login_disabled=Login using the authentication domain {0} is disabled.
14711472

14721473
####################
14731474
# DE forms Module

WEB-INF/src/com/krishagni/catissueplus/core/administrative/services/impl/UserServiceImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ public UserDetails loadUserByUsername(String username)
203203
int slashIdx = username.indexOf('/');
204204
String loginName = slashIdx != -1 ? username.substring(0, slashIdx) : username;
205205
String domain = slashIdx != -1 ? username.substring(slashIdx + 1) : DEFAULT_AUTH_DOMAIN;
206-
return daoFactory.getUserDao().getUser(loginName, domain);
206+
User user = daoFactory.getUserDao().getUser(loginName, domain);
207+
if (user != null && user.getAuthDomain() != null && !user.getAuthDomain().isAllowLogins()) {
208+
throw OpenSpecimenException.userError(AuthErrorCode.DOMAIN_LOGIN_DISABLED, user.getAuthDomain().getName());
209+
}
210+
211+
return user;
207212
}
208213

209214
@Override
@@ -223,6 +228,9 @@ public Object loadUserBySAML(SAMLCredential credential)
223228
// We should perhaps use SAML local entity ID
224229
//
225230
AuthDomain domain = daoFactory.getAuthDao().getAuthDomainByType("saml");
231+
if (domain != null && !domain.isAllowLogins()) {
232+
throw OpenSpecimenException.userError(AuthErrorCode.DOMAIN_LOGIN_DISABLED, domain.getName());
233+
}
226234

227235
Map<String, String> props = domain.getAuthProvider().getProps();
228236
String loginNameAttr = props.get("loginNameAttr");

WEB-INF/src/com/krishagni/catissueplus/core/auth/domain/AuthDomain.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class AuthDomain {
2525

2626
private AuthProvider authProvider;
2727

28+
29+
private boolean allowLogins = true;
30+
2831
private String activityStatus;
2932

3033
public Long getId() {
@@ -55,6 +58,13 @@ public AuthenticationService getAuthProviderInstance() {
5558
return getAuthProviderInstance(getAuthProvider());
5659
}
5760

61+
public boolean isAllowLogins() {
62+
return allowLogins;
63+
}
64+
65+
public void setAllowLogins(boolean allowLogins) {
66+
this.allowLogins = allowLogins;
67+
}
5868
public String getActivityStatus() {
5969
return activityStatus;
6070
}
@@ -65,6 +75,7 @@ public void setActivityStatus(String activityStatus) {
6575

6676
public void update(AuthDomain domain) {
6777
setName(domain.getName());
78+
setAllowLogins(domain.isAllowLogins());
6879

6980
Map<String, String> newProps = domain.getAuthProvider().getProps();
7081
Map<String, String> oldProps = authProvider.getProps();

WEB-INF/src/com/krishagni/catissueplus/core/auth/domain/AuthErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public enum AuthErrorCode implements ErrorCode {
2323

2424
IMP_TOKEN_EXP,
2525

26-
OTP_EXPIRED;
26+
OTP_EXPIRED,
27+
28+
DOMAIN_LOGIN_DISABLED;
2729

2830
@Override
2931
public String code() {

WEB-INF/src/com/krishagni/catissueplus/core/auth/domain/factory/impl/DomainRegistrationFactoryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import com.krishagni.catissueplus.core.common.errors.ActivityStatusErrorCode;
1414
import com.krishagni.catissueplus.core.common.errors.ErrorType;
1515
import com.krishagni.catissueplus.core.common.errors.OpenSpecimenException;
16+
import com.krishagni.catissueplus.core.common.util.LogUtil;
1617
import com.krishagni.catissueplus.core.common.util.Status;
1718

1819
public class DomainRegistrationFactoryImpl implements DomainRegistrationFactory {
1920

21+
private static final LogUtil logger = LogUtil.getLogger(DomainRegistrationFactoryImpl.class);
22+
2023
@Autowired
2124
private DaoFactory daoFactory;
2225

@@ -30,6 +33,7 @@ public AuthDomain createDomain(AuthDomainDetail input) {
3033

3134
AuthDomain domain = new AuthDomain();
3235
setDomainName(input, domain, ose);
36+
setAllowLogins(input, domain, ose);
3337
setAuthProvider(input, domain, ose);
3438
setActivityStatus(input, domain, ose);
3539

@@ -45,6 +49,10 @@ private void setDomainName(AuthDomainDetail input, AuthDomain domain, OpenSpecim
4549

4650
domain.setName(domainName);
4751
}
52+
53+
private void setAllowLogins(AuthDomainDetail input, AuthDomain domain, OpenSpecimenException ose) {
54+
domain.setAllowLogins(input.isAllowLogins());
55+
}
4856

4957
private void setAuthProvider(AuthDomainDetail detail, AuthDomain authDomain, OpenSpecimenException ose) {
5058
String authType = detail.getAuthType();
@@ -79,6 +87,7 @@ private boolean isValidImplClass(String implClass) {
7987
Class.forName(implClass).getDeclaredConstructor().newInstance();
8088
return true;
8189
} catch (Exception e) {
90+
logger.error("Error validating the authentication provider: " + implClass, e);
8291
return false;
8392
}
8493
}

WEB-INF/src/com/krishagni/catissueplus/core/auth/events/AuthDomainDetail.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static AuthDomainDetail from(AuthDomain authDomain) {
5151
AuthDomainDetail detail = new AuthDomainDetail();
5252
detail.setId(authDomain.getId());
5353
detail.setName(authDomain.getName());
54+
detail.setAllowLogins(authDomain.isAllowLogins());
5455
detail.setAuthType(authDomain.getAuthProvider().getAuthType());
5556
detail.setImplClass(authDomain.getAuthProvider().getImplClass());
5657
detail.setAuthProviderProps(authDomain.getAuthProvider().getProps());

WEB-INF/src/com/krishagni/catissueplus/core/auth/events/AuthDomainSummary.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class AuthDomainSummary {
1212

1313
private String type;
1414

15+
private boolean allowLogins = true;
16+
1517
public Long getId() {
1618
return id;
1719
}
@@ -36,11 +38,20 @@ public void setType(String type) {
3638
this.type = type;
3739
}
3840

41+
public boolean isAllowLogins() {
42+
return allowLogins;
43+
}
44+
45+
public void setAllowLogins(boolean allowLogins) {
46+
this.allowLogins = allowLogins;
47+
}
48+
3949
public static AuthDomainSummary from(AuthDomain domain) {
4050
AuthDomainSummary summary = new AuthDomainSummary();
4151
summary.setId(domain.getId());
4252
summary.setName(domain.getName());
4353
summary.setType(domain.getAuthProvider().getAuthType());
54+
summary.setAllowLogins(domain.isAllowLogins());
4455
return summary;
4556
}
4657

WEB-INF/src/com/krishagni/catissueplus/core/auth/services/impl/OpenSpecimenAuthServiceImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public class OpenSpecimenAuthServiceImpl implements AuthenticationService {
1919

2020
@Autowired
2121
private AuthenticationManager authManager;
22-
22+
23+
public OpenSpecimenAuthServiceImpl() {
24+
25+
}
26+
2327
public OpenSpecimenAuthServiceImpl(Map<String, String> props) {
2428

2529
}

0 commit comments

Comments
 (0)