MIFOSX-258: return roles of authenticated user in response of authentication api.
This commit is contained in:
+16
-11
@@ -989,8 +989,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><a href="#authentication">AUTHENTICATION</a></td>
|
<td><a href="#authentication">AUTHENTICATION</a></td>
|
||||||
<td>authentication</td>
|
<td>authentication</td>
|
||||||
<td><a href="#authenticate_request">Verify
|
<td><a href="#authenticate_request">Verify Authentication</a></td>
|
||||||
Authentication</a></td>
|
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
@@ -9423,8 +9422,7 @@ GET https://DomainName/api/v1/reports/{reportName}
|
|||||||
<div class="method-section">
|
<div class="method-section">
|
||||||
<div class="method-description">
|
<div class="method-description">
|
||||||
<h4>Verify authentication</h4>
|
<h4>Verify authentication</h4>
|
||||||
<p>Authenticates the credentials provided and returns the set
|
<p>Authenticates the credentials provided and returns the set roles and permissions allowed.</p>
|
||||||
of permissions allowed.</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="method-example">
|
<div class="method-example">
|
||||||
<code class="method-declaration">
|
<code class="method-declaration">
|
||||||
@@ -9437,13 +9435,20 @@ No Request Body
|
|||||||
</code>
|
</code>
|
||||||
<code class="method-response">
|
<code class="method-response">
|
||||||
{
|
{
|
||||||
"username": "mifos",
|
"username": "mifos",
|
||||||
"userId": 1,
|
"userId": 1,
|
||||||
"base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
|
"base64EncodedAuthenticationKey": "bWlmb3M6cGFzc3dvcmQ=",
|
||||||
"authenticated": true,
|
"authenticated": true,
|
||||||
"permissions": [
|
"roles": [
|
||||||
"ALL_FUNCTIONS"
|
{
|
||||||
]
|
"id": 1,
|
||||||
|
"name": "Super user",
|
||||||
|
"description": "This role provides all application permissions."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permissions": [
|
||||||
|
"ALL_FUNCTIONS"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
<code class="method-request">
|
<code class="method-request">
|
||||||
|
|||||||
+8
-2
@@ -17,7 +17,9 @@ import javax.ws.rs.core.MediaType;
|
|||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
|
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
|
||||||
|
import org.mifosplatform.useradministration.data.RoleData;
|
||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
@@ -36,13 +38,15 @@ public class AuthenticationApiResource {
|
|||||||
|
|
||||||
private final DaoAuthenticationProvider customAuthenticationProvider;
|
private final DaoAuthenticationProvider customAuthenticationProvider;
|
||||||
private final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService;
|
private final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService;
|
||||||
|
private final RoleReadPlatformService roleReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public AuthenticationApiResource(
|
public AuthenticationApiResource(
|
||||||
@Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider,
|
@Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider,
|
||||||
final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService) {
|
final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService, final RoleReadPlatformService roleReadPlatformService) {
|
||||||
this.customAuthenticationProvider = customAuthenticationProvider;
|
this.customAuthenticationProvider = customAuthenticationProvider;
|
||||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||||
|
this.roleReadPlatformService = roleReadPlatformService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@@ -64,7 +68,9 @@ public class AuthenticationApiResource {
|
|||||||
AppUser principal = (AppUser) authenticationCheck.getPrincipal();
|
AppUser principal = (AppUser) authenticationCheck.getPrincipal();
|
||||||
byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
|
byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
|
||||||
|
|
||||||
authenticatedUserData = new AuthenticatedUserData(username, permissions, principal.getId(), new String(
|
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAll();
|
||||||
|
|
||||||
|
authenticatedUserData = new AuthenticatedUserData(username, roles, permissions, principal.getId(), new String(
|
||||||
base64EncodedAuthenticationKey));
|
base64EncodedAuthenticationKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -7,6 +7,8 @@ package org.mifosplatform.infrastructure.security.data;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.mifosplatform.useradministration.data.RoleData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable data object for authentication.
|
* Immutable data object for authentication.
|
||||||
*/
|
*/
|
||||||
@@ -21,6 +23,8 @@ public class AuthenticatedUserData {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final boolean authenticated;
|
private final boolean authenticated;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
private final Collection<RoleData> roles;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private final Collection<String> permissions;
|
private final Collection<String> permissions;
|
||||||
|
|
||||||
public AuthenticatedUserData(final String username, final Collection<String> permissions) {
|
public AuthenticatedUserData(final String username, final Collection<String> permissions) {
|
||||||
@@ -28,15 +32,17 @@ public class AuthenticatedUserData {
|
|||||||
this.userId = null;
|
this.userId = null;
|
||||||
this.base64EncodedAuthenticationKey = null;
|
this.base64EncodedAuthenticationKey = null;
|
||||||
this.authenticated = false;
|
this.authenticated = false;
|
||||||
|
this.roles = null;
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthenticatedUserData(final String username, final Collection<String> permissions, final Long userId,
|
public AuthenticatedUserData(final String username, final Collection<RoleData> roles, final Collection<String> permissions,
|
||||||
final String base64EncodedAuthenticationKey) {
|
final Long userId, final String base64EncodedAuthenticationKey) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
|
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
|
||||||
this.authenticated = true;
|
this.authenticated = true;
|
||||||
|
this.roles = roles;
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -104,7 +104,7 @@ public class RolesApiResource {
|
|||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||||
|
|
||||||
final Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
final Collection<RoleData> roles = this.roleReadPlatformService.retrieveAll();
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
return this.toApiJsonSerializer.serialize(settings, roles, RESPONSE_DATA_PARAMETERS);
|
return this.toApiJsonSerializer.serialize(settings, roles, RESPONSE_DATA_PARAMETERS);
|
||||||
@@ -135,7 +135,7 @@ public class RolesApiResource {
|
|||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
RoleData role = this.roleReadPlatformService.retrieveOne(roleId);
|
||||||
if (settings.isCommandIdPassed()) {
|
if (settings.isCommandIdPassed()) {
|
||||||
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(settings.getCommandId());
|
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(settings.getCommandId());
|
||||||
final RoleCommand changesOnly = this.fromApiJsonDeserializer.commandFromApiJson(entry.json());
|
final RoleCommand changesOnly = this.fromApiJsonDeserializer.commandFromApiJson(entry.json());
|
||||||
@@ -172,7 +172,7 @@ public class RolesApiResource {
|
|||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
final RoleData role = this.roleReadPlatformService.retrieveOne(roleId);
|
||||||
final Collection<PermissionData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
final Collection<PermissionData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||||
Collection<PermissionData> currentChanges = null;
|
Collection<PermissionData> currentChanges = null;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -76,7 +76,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
|||||||
public AppUserData retrieveNewUserDetails() {
|
public AppUserData retrieveNewUserDetails() {
|
||||||
|
|
||||||
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||||
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
|
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAll();
|
||||||
|
|
||||||
return AppUserData.template(offices, availableRoles);
|
return AppUserData.template(offices, availableRoles);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
|||||||
final AppUser user = this.appUserRepository.findOne(userId);
|
final AppUser user = this.appUserRepository.findOne(userId);
|
||||||
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
|
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
|
||||||
|
|
||||||
Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
|
Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAll();
|
||||||
|
|
||||||
Collection<RoleData> selectedUserRoles = new ArrayList<RoleData>();
|
Collection<RoleData> selectedUserRoles = new ArrayList<RoleData>();
|
||||||
Set<Role> userRoles = user.getRoles();
|
Set<Role> userRoles = user.getRoles();
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@ import org.mifosplatform.useradministration.data.RoleData;
|
|||||||
|
|
||||||
public interface RoleReadPlatformService {
|
public interface RoleReadPlatformService {
|
||||||
|
|
||||||
Collection<RoleData> retrieveAllRoles();
|
Collection<RoleData> retrieveAll();
|
||||||
|
|
||||||
RoleData retrieveRole(Long roleId);
|
RoleData retrieveOne(Long roleId);
|
||||||
}
|
}
|
||||||
+15
-21
@@ -11,12 +11,10 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
|
||||||
import org.mifosplatform.useradministration.data.RoleData;
|
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.mifosplatform.useradministration.exception.RoleNotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -25,35 +23,31 @@ import org.springframework.stereotype.Service;
|
|||||||
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final PlatformSecurityContext context;
|
private final RoleMapper roleRowMapper;
|
||||||
private final RoleRepository roleRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RoleReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
public RoleReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource) {
|
||||||
final RoleRepository roleRepository) {
|
|
||||||
this.context = context;
|
|
||||||
this.roleRepository = roleRepository;
|
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
this.roleRowMapper = new RoleMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<RoleData> retrieveAllRoles() {
|
public Collection<RoleData> retrieveAll() {
|
||||||
context.authenticatedUser();
|
final String sql = "select " + roleRowMapper.schema() + " order by r.id";
|
||||||
|
|
||||||
final RoleMapper mapper = new RoleMapper();
|
return this.jdbcTemplate.query(sql, this.roleRowMapper);
|
||||||
final String sql = "select " + mapper.schema() + " order by r.id";
|
|
||||||
|
|
||||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoleData retrieveRole(final Long id) {
|
public RoleData retrieveOne(final Long id) {
|
||||||
context.authenticatedUser();
|
|
||||||
|
|
||||||
final Role role = this.roleRepository.findOne(id);
|
try {
|
||||||
if (role == null) { throw new RoleNotFoundException(id); }
|
final String sql = "select " + roleRowMapper.schema() + " where r.id=?";
|
||||||
|
|
||||||
return role.toData();
|
return this.jdbcTemplate.queryForObject(sql, this.roleRowMapper, new Object[] { id });
|
||||||
|
} catch (EmptyResultDataAccessException e) {
|
||||||
|
throw new RoleNotFoundException(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final class RoleMapper implements RowMapper<RoleData> {
|
protected static final class RoleMapper implements RowMapper<RoleData> {
|
||||||
|
|||||||
Reference in New Issue
Block a user