diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 56a85fb6c..9697fd7bb 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -989,8 +989,7 @@
Authenticates the credentials provided and returns the set - of permissions allowed.
+Authenticates the credentials provided and returns the set roles and permissions allowed.
@@ -9437,13 +9435,20 @@ No Request Body
{
- "username": "mifos",
- "userId": 1,
- "base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
- "authenticated": true,
- "permissions": [
- "ALL_FUNCTIONS"
- ]
+ "username": "mifos",
+ "userId": 1,
+ "base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
+ "authenticated": true,
+ "roles": [
+ {
+ "id": 1,
+ "name": "Super user",
+ "description": "This role provides all application permissions."
+ }
+ ],
+ "permissions": [
+ "ALL_FUNCTIONS"
+ ]
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/api/AuthenticationApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/api/AuthenticationApiResource.java
index 10e619e0c..5629810cd 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/api/AuthenticationApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/api/AuthenticationApiResource.java
@@ -17,7 +17,9 @@ import javax.ws.rs.core.MediaType;
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
+import org.mifosplatform.useradministration.data.RoleData;
import org.mifosplatform.useradministration.domain.AppUser;
+import org.mifosplatform.useradministration.service.RoleReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
@@ -36,13 +38,15 @@ public class AuthenticationApiResource {
private final DaoAuthenticationProvider customAuthenticationProvider;
private final ToApiJsonSerializer apiJsonSerializerService;
+ private final RoleReadPlatformService roleReadPlatformService;
@Autowired
public AuthenticationApiResource(
@Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider,
- final ToApiJsonSerializer apiJsonSerializerService) {
+ final ToApiJsonSerializer apiJsonSerializerService, final RoleReadPlatformService roleReadPlatformService) {
this.customAuthenticationProvider = customAuthenticationProvider;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.roleReadPlatformService = roleReadPlatformService;
}
@POST
@@ -64,7 +68,9 @@ public class AuthenticationApiResource {
AppUser principal = (AppUser) authenticationCheck.getPrincipal();
byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
- authenticatedUserData = new AuthenticatedUserData(username, permissions, principal.getId(), new String(
+ Collection roles = this.roleReadPlatformService.retrieveAll();
+
+ authenticatedUserData = new AuthenticatedUserData(username, roles, permissions, principal.getId(), new String(
base64EncodedAuthenticationKey));
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/data/AuthenticatedUserData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/data/AuthenticatedUserData.java
index 6e3adf470..d60f0b883 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/data/AuthenticatedUserData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/data/AuthenticatedUserData.java
@@ -7,6 +7,8 @@ package org.mifosplatform.infrastructure.security.data;
import java.util.Collection;
+import org.mifosplatform.useradministration.data.RoleData;
+
/**
* Immutable data object for authentication.
*/
@@ -21,6 +23,8 @@ public class AuthenticatedUserData {
@SuppressWarnings("unused")
private final boolean authenticated;
@SuppressWarnings("unused")
+ private final Collection roles;
+ @SuppressWarnings("unused")
private final Collection permissions;
public AuthenticatedUserData(final String username, final Collection permissions) {
@@ -28,15 +32,17 @@ public class AuthenticatedUserData {
this.userId = null;
this.base64EncodedAuthenticationKey = null;
this.authenticated = false;
+ this.roles = null;
this.permissions = permissions;
}
- public AuthenticatedUserData(final String username, final Collection permissions, final Long userId,
- final String base64EncodedAuthenticationKey) {
+ public AuthenticatedUserData(final String username, final Collection roles, final Collection permissions,
+ final Long userId, final String base64EncodedAuthenticationKey) {
this.username = username;
this.userId = userId;
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
this.authenticated = true;
+ this.roles = roles;
this.permissions = permissions;
}
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java
index 94dcdd865..1e0ffaf14 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java
@@ -104,7 +104,7 @@ public class RolesApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
- final Collection roles = this.roleReadPlatformService.retrieveAllRoles();
+ final Collection roles = this.roleReadPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, roles, RESPONSE_DATA_PARAMETERS);
@@ -135,7 +135,7 @@ public class RolesApiResource {
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
+ RoleData role = this.roleReadPlatformService.retrieveOne(roleId);
if (settings.isCommandIdPassed()) {
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(settings.getCommandId());
final RoleCommand changesOnly = this.fromApiJsonDeserializer.commandFromApiJson(entry.json());
@@ -172,7 +172,7 @@ public class RolesApiResource {
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
- final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
+ final RoleData role = this.roleReadPlatformService.retrieveOne(roleId);
final Collection permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
Collection currentChanges = null;
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java
index 402558bef..8e1576af5 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java
@@ -76,7 +76,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
public AppUserData retrieveNewUserDetails() {
final Collection offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
- final Collection availableRoles = this.roleReadPlatformService.retrieveAllRoles();
+ final Collection availableRoles = this.roleReadPlatformService.retrieveAll();
return AppUserData.template(offices, availableRoles);
}
@@ -89,7 +89,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
final AppUser user = this.appUserRepository.findOne(userId);
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
- Collection availableRoles = this.roleReadPlatformService.retrieveAllRoles();
+ Collection availableRoles = this.roleReadPlatformService.retrieveAll();
Collection selectedUserRoles = new ArrayList();
Set userRoles = user.getRoles();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformService.java
index 80fb1423e..ebcbb5f59 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformService.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformService.java
@@ -11,7 +11,7 @@ import org.mifosplatform.useradministration.data.RoleData;
public interface RoleReadPlatformService {
- Collection retrieveAllRoles();
+ Collection retrieveAll();
- RoleData retrieveRole(Long roleId);
+ RoleData retrieveOne(Long roleId);
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java
index b717bfeaf..24718b90c 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java
@@ -11,12 +11,10 @@ import java.util.Collection;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
-import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.data.RoleData;
-import org.mifosplatform.useradministration.domain.Role;
-import org.mifosplatform.useradministration.domain.RoleRepository;
import org.mifosplatform.useradministration.exception.RoleNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@@ -25,35 +23,31 @@ import org.springframework.stereotype.Service;
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
private final JdbcTemplate jdbcTemplate;
- private final PlatformSecurityContext context;
- private final RoleRepository roleRepository;
+ private final RoleMapper roleRowMapper;
@Autowired
- public RoleReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
- final RoleRepository roleRepository) {
- this.context = context;
- this.roleRepository = roleRepository;
+ public RoleReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
+ this.roleRowMapper = new RoleMapper();
}
@Override
- public Collection retrieveAllRoles() {
- context.authenticatedUser();
+ public Collection retrieveAll() {
+ final String sql = "select " + roleRowMapper.schema() + " order by r.id";
- final RoleMapper mapper = new RoleMapper();
- final String sql = "select " + mapper.schema() + " order by r.id";
-
- return this.jdbcTemplate.query(sql, mapper, new Object[] {});
+ return this.jdbcTemplate.query(sql, this.roleRowMapper);
}
@Override
- public RoleData retrieveRole(final Long id) {
- context.authenticatedUser();
+ public RoleData retrieveOne(final Long id) {
- final Role role = this.roleRepository.findOne(id);
- if (role == null) { throw new RoleNotFoundException(id); }
-
- return role.toData();
+ try {
+ final String sql = "select " + roleRowMapper.schema() + " where r.id=?";
+
+ return this.jdbcTemplate.queryForObject(sql, this.roleRowMapper, new Object[] { id });
+ } catch (EmptyResultDataAccessException e) {
+ throw new RoleNotFoundException(id);
+ }
}
protected static final class RoleMapper implements RowMapper {