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

Commit 7be6dfc

Browse files
authored
Merge pull request #353 from appirio-tech/jwttoken_update_v2
Jwttoken update with tcjwt removal
2 parents a60e838 + 569c620 commit 7be6dfc

23 files changed

+230
-342
lines changed

build.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@
573573
</fileset>
574574
</copy>
575575

576-
<copy file="${commons-codec-1.9.jar}" todir="${jboss.home}/server/${server.name}/lib" overwrite="true"/>
576+
<copy file="${commons-codec-1.9.jar}" tofile="${jboss.home}/server/${server.name}/lib/commons-codec.jar" overwrite="true"/>
577577
<copy todir="${jboss.home}/server/${server.name}/lib" flatten="true" overwrite="true">
578578
<fileset dir="${ext_libdir}">
579579
<include name="aws-java-sdk/aws-java-sdk-1.0.004.jar" />

conf/ApplicationServer.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ SSO_COOKIE_KEY = @ApplicationServer.SSO_COOKIE_KEY@
4444
SSO_HASH_SECRET = @ApplicationServer.SSO_HASH_SECRET@
4545
SSO_DOMAIN = @ApplicationServer.SSO_DOMAIN@
4646

47-
JWT_COOKIE_KEY = @ApplicationServer.JWT_COOKIE_KEY@
4847
JWT_V3_COOKIE_KEY = @ApplicationServer.JWT_V3_COOKIE_KEY@
48+
JWT_COOKIE_KEY = @ApplicationServer.JWT_COOKIE_KEY@

conf/Direct.properties

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LDAP_AUTH0_CONNECTION_NAME = @LDAP_AUTH0_CONNECTION_NAME@
1818
REDIRECT_URL_AUTH0 = /reg2/callback.action
1919
REG_SERVER_NAME= @REG_SERVER_NAME@
2020
JWT_VALID_ISSUERS=@JWT_VALID_ISSUERS@
21+
JWT_V3_SECRET = @JWT_V3_SECRET@
2122

2223
#Parameter whether we use login processor or not
2324
USE_LOGIN_PROCESSOR = @useLoginProcessor@

conf/web/WEB-INF/applicationContext.xml

+1-8
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
<property name="loginPageName" value="anonymous"/>
213213
<property name="userSessionIdentityKey" value="user"/>
214214
<property name="redirectBackUrlIdentityKey" value="redirectBackUrl"/>
215+
<property name="authorizationURL" value="@authorizationUrl@"/>
215216
</bean>
216217

217218
<!-- LoggingInterceptor -->
@@ -340,7 +341,6 @@
340341
<property name="contestFeeService" ref="contestFeeService"/>
341342
<property name="contestFeePercentageService" ref="contestFeePercentageService"/>
342343
<property name="userGroupsApiEndpoint" value="@userGroupsApiEndpoint@"/>
343-
<property name="jwtTokenUpdater" ref="jwtTokenUpdater" />
344344
</bean>
345345

346346
<bean id="projectAction" class="com.topcoder.direct.services.view.action.contest.launch.ProjectAction"
@@ -1504,13 +1504,11 @@
15041504
class="com.topcoder.direct.services.view.action.my.MyCreatedChallengesAction" scope="prototype">
15051505
<property name="serviceURL" value="@directChallengeServicesApiUrl@"/>
15061506
<property name="userService" ref="userService"/>
1507-
<property name="jwtTokenUpdater" ref="jwtTokenUpdater"/>
15081507
</bean>
15091508

15101509
<bean id="myChallengesAction"
15111510
class="com.topcoder.direct.services.view.action.my.MyChallengesAction" scope="prototype">
15121511
<property name="serviceURL" value="@directChallengeServicesApiUrl@"/>
1513-
<property name="jwtTokenUpdater" ref="jwtTokenUpdater"/>
15141512
</bean>
15151513

15161514
<bean id="xmlPhaseTemplatePersistence"
@@ -1555,10 +1553,5 @@
15551553
<bean id="getGroupMemberAction" class="com.topcoder.direct.services.view.action.contest.launch.GetGroupMemberAction"
15561554
scope="prototype" parent="baseDirectStrutsAction">
15571555
<property name="groupApiEndpoint" value="@groupMemberApiUrl@"/>
1558-
<property name="jwtTokenUpdater" ref="jwtTokenUpdater"/>
1559-
</bean>
1560-
<bean id="jwtTokenUpdater" class="com.topcoder.direct.services.view.util.JwtTokenUpdater" scope="prototype">
1561-
<property name="ssoLoginUrl" value="@ssoLoginUrl@"/>
1562-
<property name="authorizationURL" value="@authorizationUrl@"/>
15631556
</bean>
15641557
</beans>

conf/web/WEB-INF/struts.xml

-2
Original file line numberDiff line numberDiff line change
@@ -1548,15 +1548,13 @@
15481548
<package name="my" namespace="/my" extends="base">
15491549
<action name="createdChallenges" class="myCreatedChallengesAction">
15501550
<result name="success">/WEB-INF/my/myCreatedChallenges.jsp</result>
1551-
<result name="forward" type="redirect">${ssoLoginUrl}</result>
15521551
</action>
15531552
<action name="getCreatedChallenges" method="getMyCreatedChallenges" class="myCreatedChallengesAction">
15541553
<result name="success" type="json"/>
15551554
<result name="error" type="json"/>
15561555
</action>
15571556
<action name="challenges" class="myChallengesAction">
15581557
<result name="success">/WEB-INF/my/myChallenges.jsp</result>
1559-
<result name="forward" type="redirect">${ssoLoginUrl}</result>
15601558
</action>
15611559
<action name="getMyChallenges" method="getMyChallenges" class="myChallengesAction">
15621560
<result name="success" type="json"/>

src/java/main/com/topcoder/direct/services/configs/ServerConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ServerConfiguration extends ApplicationServer {
5555
*
5656
* @since 1.1
5757
*/
58-
public static String JWT_COOOKIE_KEY = bundle.getProperty("JWT_COOKIE_KEY", "tcjwt");
59-
6058
public static String JWT_V3_COOKIE_KEY = bundle.getProperty("JWT_V3_COOKIE_KEY", "v3jwt");
59+
60+
public static String JWT_COOKIE_KEY = bundle.getProperty("JWT_COOKIE_KEY", "tcjwt");
6161
}

src/java/main/com/topcoder/direct/services/view/action/ServiceBackendDataTablesAction.java

+4-15
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*/
44
package com.topcoder.direct.services.view.action;
55

6+
import com.topcoder.direct.services.configs.ServerConfiguration;
67
import com.topcoder.direct.services.view.dto.contest.ContestStatus;
78
import com.topcoder.direct.services.view.dto.project.ProjectBriefDTO;
89
import com.topcoder.direct.services.view.util.DataProvider;
910
import com.topcoder.direct.services.view.util.DirectUtils;
10-
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
1111
import com.topcoder.security.TCSubject;
1212
import org.apache.http.HttpEntity;
1313
import org.apache.http.HttpHeaders;
@@ -17,6 +17,7 @@
1717
import org.apache.http.client.utils.URIBuilder;
1818
import org.apache.http.impl.client.DefaultHttpClient;
1919
import org.apache.log4j.Logger;
20+
import org.apache.struts2.ServletActionContext;
2021
import org.codehaus.jackson.JsonNode;
2122
import org.codehaus.jackson.map.DeserializationConfig;
2223
import org.codehaus.jackson.map.ObjectMapper;
@@ -215,11 +216,6 @@ public abstract class ServiceBackendDataTablesAction extends AbstractAction {
215216
*/
216217
protected static final ObjectMapper objectMapper;
217218

218-
/**
219-
* JwtTokenUpdater
220-
*/
221-
private JwtTokenUpdater jwtTokenUpdater;
222-
223219
/**
224220
* <p>A static <code>Map</code> mapping the existing contest statuses to their textual presentations.</p>
225221
*
@@ -323,7 +319,8 @@ protected JsonNode getJsonResultFromAPI(URI apiEndPoint) throws Exception {
323319
// specify the get request
324320
HttpGet getRequest = new HttpGet(apiEndPoint);
325321

326-
String token = jwtTokenUpdater.getV3Token();
322+
String token = DirectUtils.getCookieFromRequest(ServletActionContext.getRequest(),
323+
ServerConfiguration.JWT_V3_COOKIE_KEY).getValue();
327324

328325
getRequest.setHeader(HttpHeaders.AUTHORIZATION,
329326
"Bearer " + token);
@@ -702,12 +699,4 @@ public String getEndDateTo() {
702699
public void setEndDateTo(String endDateTo) {
703700
this.endDateTo = endDateTo;
704701
}
705-
706-
public JwtTokenUpdater getJwtTokenUpdater() {
707-
return jwtTokenUpdater;
708-
}
709-
710-
public void setJwtTokenUpdater(JwtTokenUpdater jwtTokenUpdater) {
711-
this.jwtTokenUpdater = jwtTokenUpdater;
712-
}
713702
}

src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.topcoder.direct.services.view.util.AuthorizationProvider;
2121
import com.topcoder.direct.services.view.util.DataProvider;
2222
import com.topcoder.direct.services.view.util.DirectUtils;
23-
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
2423
import com.topcoder.direct.services.view.util.challenge.CostCalculationService;
2524
import com.topcoder.management.project.ProjectGroup;
2625
import com.topcoder.security.TCSubject;
@@ -129,7 +128,6 @@ public class CommonAction extends BaseContestFeeAction {
129128
*/
130129
private String userGroupsApiEndpoint;
131130

132-
private JwtTokenUpdater jwtTokenUpdater;
133131

134132
/**
135133
* <p>
@@ -561,7 +559,7 @@ public void setCategoryId(long categoryId) {
561559
public String getGroups() {
562560
try {
563561
TCSubject tcSubject = DirectUtils.getTCSubjectFromSession();
564-
Set<ProjectGroup> projectGroups = DirectUtils.getGroups(tcSubject, jwtTokenUpdater, userGroupsApiEndpoint);
562+
Set<ProjectGroup> projectGroups = DirectUtils.getGroups(tcSubject, userGroupsApiEndpoint);
565563
setResult(projectGroups);
566564
} catch (Throwable e) {
567565
if (getModel() != null) {
@@ -578,12 +576,4 @@ public String getUserGroupsApiEndpoint() {
578576
public void setUserGroupsApiEndpoint(String userGroupsApiEndpoint) {
579577
this.userGroupsApiEndpoint = userGroupsApiEndpoint;
580578
}
581-
582-
public JwtTokenUpdater getJwtTokenUpdater() {
583-
return jwtTokenUpdater;
584-
}
585-
586-
public void setJwtTokenUpdater(JwtTokenUpdater jwtTokenUpdater) {
587-
this.jwtTokenUpdater = jwtTokenUpdater;
588-
}
589579
}

src/java/main/com/topcoder/direct/services/view/action/contest/launch/GetGroupMemberAction.java

+8-24
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import com.topcoder.direct.services.configs.ServerConfiguration;
77
import com.topcoder.direct.services.view.dto.contest.GroupMember;
88
import com.topcoder.direct.services.view.dto.my.RestResult;
9-
import com.topcoder.direct.services.view.exception.JwtAuthenticationException;
109
import com.topcoder.direct.services.view.util.DirectUtils;
11-
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
1210
import com.topcoder.direct.services.view.util.SortedCacheAddress;
1311
import com.topcoder.web.common.cache.CacheClient;
1412
import com.topcoder.web.common.cache.CacheClientFactory;
@@ -27,9 +25,13 @@
2725
import org.codehaus.jackson.map.DeserializationConfig;
2826
import org.codehaus.jackson.map.ObjectMapper;
2927

30-
import javax.servlet.http.Cookie;
3128
import java.net.URI;
32-
import java.util.*;
29+
import java.util.HashSet;
30+
import java.util.LinkedList;
31+
import java.util.List;
32+
import java.util.ListIterator;
33+
import java.util.Map;
34+
import java.util.Set;
3335

3436
/**
3537
* This action handle group member search for given list of groups and substringof user's handle
@@ -62,11 +64,6 @@ class GetGroupMemberAction extends ContestAction {
6264
*/
6365
private String handle;
6466

65-
/**
66-
* JwtTokenUpdater
67-
*/
68-
private JwtTokenUpdater jwtTokenUpdater;
69-
7067
/**
7168
* Json object mapper
7269
*/
@@ -188,13 +185,8 @@ private RestResult<GroupMember> getGroupMemberByGid(Long gid) throws Exception {
188185
try{
189186
URI groupApiEndpointUri = new URI(String.format(groupApiEndpoint, gid));
190187
HttpGet request = new HttpGet(groupApiEndpointUri);
191-
String jwtToken;
192-
try{
193-
jwtToken = jwtTokenUpdater.getV3Token();
194-
} catch (Exception e) {
195-
logger.error("Can't get jwt token");
196-
throw e;
197-
}
188+
String jwtToken = DirectUtils.getCookieFromRequest(ServletActionContext.getRequest(),
189+
ServerConfiguration.JWT_V3_COOKIE_KEY).getValue();
198190

199191
request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + jwtToken);
200192
request.addHeader(HttpHeaders.ACCEPT, "application/json");
@@ -239,12 +231,4 @@ public String getHandle() {
239231
public void setHandle(String handle) {
240232
this.handle = handle;
241233
}
242-
243-
public JwtTokenUpdater getJwtTokenUpdater() {
244-
return jwtTokenUpdater;
245-
}
246-
247-
public void setJwtTokenUpdater(JwtTokenUpdater jwtTokenUpdater) {
248-
this.jwtTokenUpdater = jwtTokenUpdater;
249-
}
250234
}

src/java/main/com/topcoder/direct/services/view/action/my/MyChallengesAction.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
*/
44
package com.topcoder.direct.services.view.action.my;
55

6-
import com.topcoder.direct.services.configs.ServerConfiguration;
76
import com.topcoder.direct.services.view.action.ServiceBackendDataTablesAction;
87
import com.topcoder.direct.services.view.dto.my.Challenge;
98
import com.topcoder.direct.services.view.dto.my.RestResult;
10-
import com.topcoder.direct.services.view.util.DirectUtils;
119
import org.codehaus.jackson.JsonNode;
1210

13-
import org.apache.struts2.ServletActionContext;
14-
1511
import java.text.DateFormat;
1612
import java.text.NumberFormat;
1713
import java.text.SimpleDateFormat;
18-
import java.util.*;
14+
import java.util.ArrayList;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Locale;
18+
import java.util.Map;
19+
import java.util.TimeZone;
1920

2021
/**
2122
* <p>
@@ -49,10 +50,6 @@ public class MyChallengesAction extends ServiceBackendDataTablesAction {
4950
*/
5051
@Override
5152
public String execute() throws Exception {
52-
if (DirectUtils.getCookieFromRequest(ServletActionContext.getRequest(),
53-
ServerConfiguration.JWT_COOOKIE_KEY) == null)
54-
return "forward";
55-
5653
// populate filter data
5754
this.setupFilterPanel();
5855

src/java/main/com/topcoder/direct/services/view/action/my/MyCreatedChallengesAction.java

-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
*/
44
package com.topcoder.direct.services.view.action.my;
5-
6-
import com.topcoder.direct.services.configs.ServerConfiguration;
75
import com.topcoder.direct.services.view.action.ServiceBackendDataTablesAction;
86
import com.topcoder.direct.services.view.dto.my.Challenge;
97
import com.topcoder.direct.services.view.dto.my.RestResult;
108
import com.topcoder.direct.services.view.util.DirectUtils;
119
import com.topcoder.service.user.UserService;
12-
import org.apache.struts2.ServletActionContext;
1310
import org.codehaus.jackson.JsonNode;
1411

1512
import java.text.DateFormat;
@@ -60,10 +57,6 @@ public class MyCreatedChallengesAction extends ServiceBackendDataTablesAction {
6057
*/
6158
@Override
6259
public String execute() throws Exception {
63-
if (DirectUtils.getCookieFromRequest(ServletActionContext.getRequest(),
64-
ServerConfiguration.JWT_COOOKIE_KEY) == null)
65-
return "forward";
66-
6760
// populate filter data
6861
this.setupFilterPanel();
6962

src/java/main/com/topcoder/direct/services/view/exception/JwtAuthenticationException.java

-13
This file was deleted.

0 commit comments

Comments
 (0)