Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 9ca1ee7

Browse files
committed
Sync to revision 85917 from svn upstream.
1 parent 02da220 commit 9ca1ee7

File tree

10 files changed

+378
-12
lines changed

10 files changed

+378
-12
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE hibernate-mapping PUBLIC
3+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4+
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
5+
6+
<hibernate-mapping package="com.topcoder.web.common.model">
7+
8+
<class name="UserSSOLogin" table="common_oltp:user_sso_login" >
9+
<composite-id name="id" class="UserSSOLogin$Identifier">
10+
<key-property name="userId" column="user_id" />
11+
<key-property name="providerId" column="provider_id" />
12+
</composite-id>
13+
14+
<property name="ssoUserName" column="sso_user_name" access="field"/>
15+
<property name="ssoEmail" column="email" access="field"/>
16+
<property name="ssoUserId" column="sso_user_id" access="field"/>
17+
</class>
18+
</hibernate-mapping>

resources/reg/hibernate.cfg.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@
154154
<mapping class="com.topcoder.web.common.model.educ.ProfessorStatus"/>
155155

156156
<mapping resource="com/topcoder/web/common/model/UserSocialLogin.hbm.xml"/>
157+
158+
<!-- 2017.04.24 [SEG-42] Block adding additional social logins to account -->
159+
<mapping resource="com/topcoder/web/common/model/UserSSOLogin.hbm.xml"/>
160+
157161
<mapping resource="com/topcoder/web/common/model/UserApiSpin.hbm.xml"/>
158162

159163
<mapping resource="com/topcoder/web/common/model/DocuSignEnvelope.hbm.xml"/>

src/main/com/topcoder/web/common/dao/DAOFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ public interface DAOFactory {
234234
*/
235235
UserSocialLoginDAO getUserSocialLoginDAO();
236236

237+
/**
238+
* Gets the instance of {@link UserSSOLoginDAO}.
239+
*
240+
* @return the dao.
241+
*/
242+
UserSSOLoginDAO getUserSSOLoginDAO();
243+
237244
/**
238245
* Gets the instance of {@link UserApiSpinDAO}.
239246
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2017 TopCoder Inc., All Rights Reserved.
3+
*/
4+
package com.topcoder.web.common.dao;
5+
6+
import com.topcoder.web.common.model.UserSSOLogin;
7+
8+
import java.util.List;
9+
10+
/**
11+
* <p>
12+
* An interface for the UserSSOLogin DAO.
13+
* </p>
14+
*
15+
* <p>
16+
* <strong>Thread safety:</strong> This class is thread-safe.
17+
* </p>
18+
*
19+
* @author kht.tc
20+
* @version 1.0
21+
*/
22+
public interface UserSSOLoginDAO extends GenericDAO<UserSSOLogin, UserSSOLogin.Identifier> {
23+
/**
24+
* Find UserSSOLogin by user id.
25+
*
26+
* @param userId the user id
27+
* @return retrieved list
28+
*/
29+
List<UserSSOLogin> findByUserId(long userId);
30+
UserSSOLogin findByProviderIdAndSSOUserId(long providerId, String ssoUserId);
31+
}

src/main/com/topcoder/web/common/dao/hibernate/DAOFactoryHibernate.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ public UserSocialLoginDAO getUserSocialLoginDAO() {
379379
return new UserSocialLoginDAOHibernate();
380380
}
381381

382+
/**
383+
* Gets the instance of {@link UserSSOLoginDAO}.
384+
*
385+
* @return the dao.
386+
*/
387+
public UserSSOLoginDAO getUserSSOLoginDAO() {
388+
return new UserSSOLoginDAOHibernate();
389+
}
390+
382391
/**
383392
* Gets the instance of {@link UserApiSpinDAO}.
384393
*
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2017 TopCoder Inc., All Rights Reserved.
3+
*/
4+
package com.topcoder.web.common.dao.hibernate;
5+
6+
import com.topcoder.web.common.dao.UserSSOLoginDAO;
7+
import com.topcoder.web.common.model.UserSSOLogin;
8+
import org.hibernate.Criteria;
9+
import org.hibernate.Query;
10+
import org.hibernate.criterion.Restrictions;
11+
12+
import java.util.List;
13+
14+
/**
15+
* <p>
16+
* An implementation for the UserSSOLogin DAO.
17+
* </p>
18+
*
19+
* <p>
20+
* <strong>Thread safety:</strong> This class is thread-safe.
21+
* </p>
22+
*
23+
* @author kht.tc
24+
* @version 1.0
25+
*/
26+
public class UserSSOLoginDAOHibernate extends GenericBase<UserSSOLogin, UserSSOLogin.Identifier>
27+
implements UserSSOLoginDAO {
28+
29+
/**
30+
* Find UserSSOLogin by user id.
31+
*
32+
* @param userId the user id
33+
* @return retrieved list
34+
*/
35+
public List<UserSSOLogin> findByUserId(long userId) {
36+
Query q = getSession().createQuery("from UserSSOLogin " +
37+
" where id.userId = " + userId ).setCacheable(false);
38+
39+
return q.list();
40+
}
41+
42+
public UserSSOLogin findByProviderIdAndSSOUserId(long providerId, String ssoUserId) {
43+
Criteria c = getSession().createCriteria(UserSSOLogin.class)
44+
.add(Restrictions.eq("ssoUserId", ssoUserId))
45+
.add(Restrictions.eq("id.providerId", providerId));
46+
List ret = c.list();
47+
return ret.isEmpty() ? null : (UserSSOLogin) ret.get(0);
48+
49+
}
50+
}

src/main/com/topcoder/web/common/dao/querytool/DAOFactoryQueryTool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ public UserSocialLoginDAO getUserSocialLoginDAO() {
366366
throw new RuntimeException("Not supported");
367367
}
368368

369+
/**
370+
* Gets the instance of {@link UserSSOLoginDAO}.
371+
*
372+
* @return nothing, will throw exception.
373+
*/
374+
public UserSSOLoginDAO getUserSSOLoginDAO() {
375+
throw new RuntimeException("Not supported");
376+
}
377+
369378
/**
370379
* Gets the instance of {@link UserApiSpinDAO}.
371380
*
@@ -405,4 +414,5 @@ public EmailRequestDAO getEmailRequestDAO() {
405414
public DocuSignEnvelopeDAO getDocuSignEnvelopeDAO() {
406415
throw new RuntimeException("Not supported");
407416
}
417+
408418
}
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*
2+
* Copyright (C) 2017 TopCoder Inc., All Rights Reserved.
3+
*/
4+
package com.topcoder.web.common.model;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* <p>
10+
* This class represents a User SSO Login entity.
11+
* </p>
12+
*
13+
* <p>
14+
* <strong>Thread safety:</strong> This class is thread-safe.
15+
* </p>
16+
*
17+
* @author kht.tc
18+
* @version 1.0
19+
*/
20+
public class UserSSOLogin extends Base {
21+
22+
/**
23+
* The id.
24+
*/
25+
private Identifier id;
26+
27+
/**
28+
* The sso user name.
29+
*/
30+
private String ssoUserName;
31+
32+
/**
33+
* THe sso email.
34+
*/
35+
private String ssoEmail;
36+
37+
38+
private String ssoUserId;
39+
40+
/**
41+
* Get the id.
42+
*
43+
* @return the id.
44+
*/
45+
public Identifier getId() {
46+
return id;
47+
}
48+
49+
/**
50+
* Set the id.
51+
*
52+
* @param id the id.
53+
*/
54+
public void setId(Identifier id) {
55+
this.id = id;
56+
}
57+
58+
/**
59+
* Get sso user name.
60+
*
61+
* @return the name.
62+
*/
63+
public String getSsoUserName() {
64+
return ssoUserName;
65+
}
66+
67+
/**
68+
* Set the sso user name.
69+
*
70+
* @param ssoUserName the name.
71+
*/
72+
public void setSsoUserName(String ssoUserName) {
73+
this.ssoUserName = ssoUserName;
74+
}
75+
76+
/**
77+
* Get the sso email.
78+
*
79+
* @return the email.
80+
*/
81+
public String getSsoEmail() {
82+
return ssoEmail;
83+
}
84+
85+
/**
86+
* Set the sso email.
87+
*
88+
* @param ssoEmail the email.
89+
*/
90+
public void setSsoEmail(String ssoEmail) {
91+
this.ssoEmail = ssoEmail;
92+
}
93+
94+
95+
public String getSsoUserId() {
96+
return ssoUserId;
97+
}
98+
99+
public void setSsoUserId(String ssoUserId) {
100+
this.ssoUserId = ssoUserId;
101+
}
102+
103+
/**
104+
* Get the hash code.
105+
*
106+
* @return the hash code.
107+
*/
108+
public int hashCode() {
109+
return id.hashCode();
110+
}
111+
112+
/**
113+
* Check whether equals to other object.
114+
*
115+
* @param obj the object to check.
116+
* @return whether equals.
117+
*/
118+
public boolean equals(Object obj) {
119+
if (this == obj) {
120+
return true;
121+
}
122+
if (obj == null) {
123+
return false;
124+
}
125+
if (getClass() != obj.getClass()) {
126+
return false;
127+
}
128+
return id.equals(((UserSSOLogin) obj).getId());
129+
}
130+
131+
/**
132+
* The class used to represent the id of user social login.
133+
*/
134+
public static class Identifier implements Serializable {
135+
/**
136+
* The user id.
137+
*/
138+
private long userId;
139+
140+
/**
141+
* The sso provider id.
142+
*/
143+
private long providerId;
144+
145+
/**
146+
* Identifier.
147+
*
148+
* @param userId the user id.
149+
* @param providerId the sso provider id.
150+
*/
151+
public Identifier(long userId, long providerId) {
152+
this.userId = userId;
153+
this.providerId = providerId;
154+
}
155+
156+
/**
157+
* The default ctor.
158+
*/
159+
public Identifier() {
160+
}
161+
162+
/**
163+
* Get user id.
164+
*
165+
* @return the user id.
166+
*/
167+
public long getUserId() {
168+
return userId;
169+
}
170+
171+
/**
172+
* Set user id.
173+
*
174+
* @param userId the user id.
175+
*/
176+
public void setUserId(long userId) {
177+
this.userId = userId;
178+
}
179+
180+
/**
181+
* Get sso provider id.
182+
*
183+
* @return the provider id.
184+
*/
185+
public long getProviderId() {
186+
return providerId;
187+
}
188+
189+
/**
190+
* Set provider id.
191+
*
192+
* @param providerId the provider id.
193+
*/
194+
public void setProviderId(long providerId) {
195+
this.providerId = providerId;
196+
}
197+
198+
/**
199+
* Check whether id equals to other object.
200+
*
201+
* @param o the object to check.
202+
* @return whether equals.
203+
*/
204+
public boolean equals(Object o) {
205+
if (o == null) {
206+
return false;
207+
}
208+
try {
209+
Identifier id = (Identifier) o;
210+
return id.getUserId() == userId
211+
&& id.getProviderId() == providerId;
212+
} catch (ClassCastException e) {
213+
return false;
214+
}
215+
216+
}
217+
218+
/**
219+
* Get the hash code.
220+
*
221+
* @return the hash code.
222+
*/
223+
public int hashCode() {
224+
final int PRIME = 31;
225+
return (int) (userId * PRIME + providerId);
226+
}
227+
}
228+
}

0 commit comments

Comments
 (0)