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

Commit 74710db

Browse files
Merge pull request #16 from appirio-tech/dev
Merge to Master-ifx from dev-ifx
2 parents b8cd3f4 + e3baa9a commit 74710db

File tree

15 files changed

+945
-491
lines changed

15 files changed

+945
-491
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

buildtokenproperties.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ M2MAUTHCONFIG_AUTHDOMAIN=$(eval "echo \$${ENV}_M2MAUTHCONFIG_AUTHDOMAIN")
2929
M2MAUTHCONFIG_TOKENEXPIRETIME=$(eval "echo \$${ENV}_M2MAUTHCONFIG_TOKENEXPIRETIME")
3030
M2MAUTHCONFIG_USERID=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERID")
3131
M2MAUTHCONFIG_AUTHPROXYSERVERURL=$(eval "echo \$${ENV}_M2MAUTHCONFIG_AUTHPROXYSERVERURL")
32+
M2MAUTHCONFIG_USERPROFILES_CREATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_CREATE")
33+
M2MAUTHCONFIG_USERPROFILES_UPDATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_UPDATE")
34+
M2MAUTHCONFIG_USERPROFILES_READ=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_READ")
35+
M2MAUTHCONFIG_USERPROFILES_DELETE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_DELETE")
3236

3337
DOMAIN=$(eval "echo \$${ENV}_DOMAIN")
3438
SMTP=$(eval "echo \$${ENV}_SMTP")
@@ -97,5 +101,9 @@ perl -pi -e "s/\{\{M2MAUTHCONFIG_TOKENEXPIRETIME\}\}/$M2MAUTHCONFIG_TOKENEXPIRET
97101
perl -pi -e "s/\{\{M2MAUTHCONFIG_USERID\}\}/$M2MAUTHCONFIG_USERID/g" $CONFFILENAME
98102
#perl -pi -e "s/\{\{M2MAUTHCONFIG_AUTHPROXYSERVERURL\}\}/$M2MAUTHCONFIG_AUTHPROXYSERVERURL/g" $CONFFILENAME
99103
perl -pi -e "s|\{\{M2MAUTHCONFIG_AUTHPROXYSERVERURL\}\}|$M2MAUTHCONFIG_AUTHPROXYSERVERURL|g" $CONFFILENAME
104+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_CREATE\}\}|$M2MAUTHCONFIG_USERPROFILES_CREATE|g" $CONFFILENAME
105+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_UPDATE\}\}|$M2MAUTHCONFIG_USERPROFILES_UPDATE|g" $CONFFILENAME
106+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_READ\}\}|$M2MAUTHCONFIG_USERPROFILES_READ|g" $CONFFILENAME
107+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROFILES_DELETE|g" $CONFFILENAME
100108
perl -pi -e "s/\{\{AUTH0_NEW_DOMAIN\}\}/$AUTH0_NEW_DOMAIN/g" $CONFFILENAME
101-
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME
109+
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/IdentityApplication.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void run(IdentityConfiguration configuration, Environment environment) th
230230
configuration.getEventBusServiceClientConfig(), configuration.getM2mAuthConfiguration());
231231
// Resources::users
232232
CacheService cacheService = configuration.getCache().createCacheService();
233-
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient);
233+
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles());
234234
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
235235
userResource.setDomain(configuration.getAuthDomain());
236236
// this secret _used_ to be different from the one used in AuthorizationResource.
@@ -250,8 +250,6 @@ public void run(IdentityConfiguration configuration, Environment environment) th
250250
GroupResource groupResource = new GroupResource(groupDao, groupInformixDao);
251251
environment.jersey().register(groupResource);
252252
environment.jersey().register(groupDao);
253-
// TODO: temporary fix.
254-
userResource.setGroupDAO(groupDao);
255253

256254
// Resources::authorizations
257255
AuthDataStore authDataStore = configuration.getAuthStore().createAuthDataStore();

src/main/java/com/appirio/tech/core/service/identity/M2mAuthConfiguration.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.appirio.tech.core.service.identity;
22

3+
import com.appirio.tech.core.service.identity.util.m2mscope.UserProfilesFactory;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import javax.validation.constraints.NotNull;
56

@@ -61,6 +62,17 @@ public class M2mAuthConfiguration {
6162
@JsonProperty
6263
private String authProxyServerUrl;
6364

65+
@JsonProperty
66+
private UserProfilesFactory userProfiles = new UserProfilesFactory();
67+
68+
public UserProfilesFactory getUserProfiles() {
69+
return userProfiles;
70+
}
71+
72+
public void setUserProfiles(UserProfilesFactory userProfiles) {
73+
this.userProfiles = userProfiles;
74+
}
75+
6476
/**
6577
* Get clientId
6678
*
@@ -73,7 +85,7 @@ public String getClientId() {
7385
/**
7486
* Set clientId
7587
*
76-
* @return the clientId to set
88+
* @param clientId the clientId to set
7789
*/
7890
public void setClientId(String clientId) {
7991
this.clientId = clientId;
@@ -91,7 +103,7 @@ public String getClientSecret() {
91103
/**
92104
* Set clientSecret
93105
*
94-
* @return the clientSecret to set
106+
* @param clientSecret the clientSecret to set
95107
*/
96108
public void setClientSecret(String clientSecret) {
97109
this.clientSecret = clientSecret;
@@ -109,7 +121,7 @@ public String getAudience() {
109121
/**
110122
* Set audience
111123
*
112-
* @return the audience to set
124+
* @param audience the audience to set
113125
*/
114126
public void setAudience(String audience) {
115127
this.audience = audience;
@@ -127,7 +139,7 @@ public String getM2mAuthDomain() {
127139
/**
128140
* Set m2mAuthDomain
129141
*
130-
* @return the m2mAuthDomain to set
142+
* @param m2mAuthDomain the m2mAuthDomain to set
131143
*/
132144
public void setM2mAuthDomain(String m2mAuthDomain) {
133145
this.m2mAuthDomain = m2mAuthDomain;
@@ -145,7 +157,7 @@ public Integer getTokenExpireTimeInMinutes() {
145157
/**
146158
* Set tokenExpireTimeInMinutes
147159
*
148-
* @return the tokenExpireTimeInMinutes to set
160+
* @param tokenExpireTimeInMinutes the tokenExpireTimeInMinutes to set
149161
*/
150162
public void setTokenExpireTimeInMinutes(Integer tokenExpireTimeInMinutes) {
151163
this.tokenExpireTimeInMinutes = tokenExpireTimeInMinutes;
@@ -163,7 +175,7 @@ public Long getUserId() {
163175
/**
164176
* Set userId
165177
*
166-
* @return the userId to set
178+
* @param userId the userId to set
167179
*/
168180
public void setUserId(Long userId) {
169181
this.userId = userId;
@@ -181,7 +193,7 @@ public String getAuthProxyServerUrl() {
181193
/**
182194
* Set authProxyServerUrl
183195
*
184-
* @return the authProxyServerUrl to set
196+
* @param authProxyServerUrl the authProxyServerUrl to set
185197
*/
186198
public void setAuthServerProxyUrl(String authProxyServerUrl) {
187199
this.authProxyServerUrl = authProxyServerUrl;

src/main/java/com/appirio/tech/core/service/identity/resource/AuthorizationResource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,13 @@ public ApiResponse createObject(
384384
Map<String, Object> header = Utils.parseJWTHeader(auth.getExternalToken());
385385
if ("RS256".equals(header.get("alg"))) {
386386
isRs256Token = true;
387-
String refreshToken = this.cacheService.get(auth.getExternalToken());
388-
if (refreshToken == null) {
389-
throw new APIRuntimeException(HttpServletResponse.SC_NOT_FOUND, "The refresh token is not found.");
390-
}
387+
388+
String refreshToken = auth.getRefreshToken();
391389
Auth0Credential cred = this.auth0New.refreshToken(refreshToken);
392390
this.cacheService.delete(auth.getExternalToken());
393391
this.cacheService.put(cred.getAccessToken(), refreshToken);
394392
auth.setToken(cred.getAccessToken());
393+
395394
} else {
396395
auth.setToken(createJWTToken(auth.getExternalToken()));
397396
}

src/main/java/com/appirio/tech/core/service/identity/resource/GroupResource.java

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ public class GroupResource implements GetResource<Group>, DDLResource<Group> {
9898
*/
9999
private static final String[] writeScopes = {"write:groups", "all:groups"};
100100

101-
/**
102-
* Represents the admin roles
103-
*/
104-
private static final String[] adminRoles = {"administrator"};
105-
106101
/**
107102
* Represents the DAO For Group
108103
*/
@@ -139,7 +134,7 @@ public ApiResponse createObject(
139134
@Context HttpServletRequest request) {
140135
logger.info("createObject()");
141136

142-
checkAccess(authUser, writeScopes, adminRoles);
137+
Utils.checkAccess(authUser, writeScopes, Utils.AdminRoles);
143138

144139
Group group = validateGroup(postRequest);
145140

@@ -185,7 +180,7 @@ public ApiResponse createSecurityGroup(
185180

186181
logger.info("createSecurityGroup()");
187182

188-
checkAccess(authUser, writeScopes, adminRoles);
183+
Utils.checkAccess(authUser, writeScopes, Utils.AdminRoles);
189184

190185
if (postRequest == null) {
191186
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "Group"));
@@ -392,7 +387,7 @@ public ApiResponse updateObject(
392387
@Context HttpServletRequest request) {
393388
logger.info("updateObject()");
394389

395-
checkAccess(authUser, writeScopes, adminRoles);
390+
Utils.checkAccess(authUser, writeScopes, Utils.AdminRoles);
396391

397392
Group group = validateGroup(putRequest);
398393

@@ -447,7 +442,7 @@ public ApiResponse deleteObject(
447442
@Context HttpServletRequest request) {
448443
logger.info(String.format("deleteObject(%s)", groupId));
449444

450-
checkAccess(authUser, writeScopes, adminRoles);
445+
Utils.checkAccess(authUser, writeScopes, Utils.AdminRoles);
451446

452447
Group group = getExistingGroup(new TCID(groupId));
453448

@@ -511,7 +506,7 @@ public ApiResponse getObject(
511506
logger.info(String.format("getObject(%s)", groupId));
512507
Group group = getExistingGroup(groupId);
513508

514-
validateAdminRoleOrPrivateGroupMembership(authUser, group, readScopes, adminRoles);
509+
validateAdminRoleOrPrivateGroupMembership(authUser, group, readScopes, Utils.AdminRoles);
515510

516511
return ApiResponseFactory.createFieldSelectorResponse(group, selector);
517512
}
@@ -636,7 +631,7 @@ public ApiResponse getMembers(
636631
// Check group exists
637632
Group group = getExistingGroup(groupId);
638633

639-
validateAdminRoleOrPrivateGroupMembership(authUser, group, readScopes, adminRoles);
634+
validateAdminRoleOrPrivateGroupMembership(authUser, group, readScopes, Utils.AdminRoles);
640635

641636
try {
642637
List<GroupMembership> memberships = groupDao.findMembershipsByGroup(Utils.toLongValue(groupId));
@@ -669,10 +664,10 @@ public ApiResponse getObjects(
669664

670665
logger.info(String.format("getObjects(%s, %s)", memberId, membershipType));
671666

672-
checkAccess(authUser, readScopes, null);
667+
Utils.checkAccess(authUser, readScopes, null);
673668

674669
// for admin and machine token
675-
if (authUser.isMachine() || hasAdminRole(authUser)) {
670+
if (authUser.isMachine() || Utils.hasAdminRole(authUser)) {
676671
if (memberId==null && Utils.isEmpty(membershipType)) {
677672
return ApiResponseFactory.createFieldSelectorResponse(groupDao.findAllGroups(), null);
678673
}
@@ -709,7 +704,7 @@ public ApiResponse addMember(
709704

710705
logger.info("addMember()");
711706

712-
checkAccess(authUser, writeScopes, null);
707+
Utils.checkAccess(authUser, writeScopes, null);
713708

714709
validateMembership(postRequest);
715710

@@ -722,7 +717,7 @@ public ApiResponse addMember(
722717
Group group = getExistingGroup(groupId);
723718

724719
// only admins or self registering users are allowed (if the group allows self register)
725-
if(!authUser.isMachine() && !hasAdminRole(authUser) && !(group.getSelfRegister() && membership.getMemberId().toString().equals(authUser.getUserId().getId()))) {
720+
if(!authUser.isMachine() && !Utils.hasAdminRole(authUser) && !(group.getSelfRegister() && membership.getMemberId().toString().equals(authUser.getUserId().getId()))) {
726721
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
727722
}
728723

@@ -759,7 +754,7 @@ public ApiResponse removeMember(
759754

760755
logger.info(String.format("removeMember(%s, %s)", groupId, membershipId));
761756

762-
checkAccess(authUser, writeScopes, null);
757+
Utils.checkAccess(authUser, writeScopes, null);
763758

764759
long id = Utils.toLongValue(membershipId);
765760
GroupMembership membership = groupDao.findMembership(id);
@@ -770,7 +765,7 @@ public ApiResponse removeMember(
770765
}
771766

772767
// only admins or self registering users are allowed (if the group allows self register)
773-
if(!authUser.isMachine() && !hasAdminRole(authUser) && !(group.getSelfRegister() && membership.getMemberId().toString().equals(authUser.getUserId().getId()))) {
768+
if(!authUser.isMachine() && !Utils.hasAdminRole(authUser) && !(group.getSelfRegister() && membership.getMemberId().toString().equals(authUser.getUserId().getId()))) {
774769
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
775770
}
776771

@@ -812,46 +807,4 @@ private void validateAdminRoleOrPrivateGroupMembership(AuthUser authUser, Group
812807
}
813808
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
814809
}
815-
816-
private void checkAccess(AuthUser authUser, String[] allowedScopes, String[] allowedRoles) {
817-
if (authUser == null) {
818-
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "Authentication user"));
819-
}
820-
821-
if (authUser.isMachine()) {
822-
if (allowedScopes == null || allowedScopes.length == 0) {
823-
return;
824-
}
825-
826-
for (String allowedScope : allowedScopes) {
827-
if (authUser.getScope().contains(allowedScope)) {
828-
return;
829-
}
830-
}
831-
} else {
832-
if (allowedRoles == null || allowedRoles.length == 0) {
833-
return;
834-
}
835-
836-
for (String role : allowedRoles) {
837-
if (authUser.getRoles() != null && authUser.getRoles().contains(role)) {
838-
return;
839-
}
840-
}
841-
}
842-
843-
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
844-
}
845-
846-
private boolean hasAdminRole(AuthUser authUser) {
847-
if (authUser.getRoles() != null) {
848-
for (String role : adminRoles) {
849-
if (authUser.getRoles().contains(role)) {
850-
return true;
851-
}
852-
}
853-
}
854-
855-
return false;
856-
}
857810
}

0 commit comments

Comments
 (0)