use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class MockProvider method createMockAuthentication.
public static Authentication createMockAuthentication() {
Authentication mockAuthentication = mock(Authentication.class);
when(mockAuthentication.getUserId()).thenReturn(EXAMPLE_USER_ID);
return mockAuthentication;
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testIsUserAuthorizedResourceIdFalse.
@Test
public void testIsUserAuthorizedResourceIdFalse() {
List<String> exampleGroups = new ArrayList<String>();
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, exampleGroups);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
AuthorizationUtil authorizationUtil = new AuthorizationUtil(MockProvider.EXAMPLE_RESOURCE_TYPE_NAME, MockProvider.EXAMPLE_RESOURCE_TYPE_ID, MockProvider.EXAMPLE_PERMISSION_NAME);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, exampleGroups, authorizationUtil, authorizationUtil, MockProvider.EXAMPLE_RESOURCE_ID)).thenReturn(false);
given().queryParam("permissionName", MockProvider.EXAMPLE_PERMISSION_NAME).queryParam("resourceName", MockProvider.EXAMPLE_RESOURCE_TYPE_NAME).queryParam("resourceType", MockProvider.EXAMPLE_RESOURCE_TYPE_ID).queryParam("resourceId", MockProvider.EXAMPLE_RESOURCE_ID).then().expect().statusCode(Status.OK.getStatusCode()).contentType(MediaType.APPLICATION_JSON).body("permissionName", equalTo(MockProvider.EXAMPLE_PERMISSION_NAME)).body("resourceName", equalTo(MockProvider.EXAMPLE_RESOURCE_TYPE_NAME)).body("resourceId", equalTo(MockProvider.EXAMPLE_RESOURCE_ID)).body("authorized", equalTo(false)).when().get(AUTH_CHECK_PATH);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, exampleGroups, authorizationUtil, authorizationUtil, MockProvider.EXAMPLE_RESOURCE_ID);
verify(identityServiceMock, times(1)).getCurrentAuthentication();
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testIsUserAuthorizedTrue.
@Test
public void testIsUserAuthorizedTrue() {
List<String> exampleGroups = new ArrayList<String>();
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, exampleGroups);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
AuthorizationUtil authorizationUtil = new AuthorizationUtil(MockProvider.EXAMPLE_RESOURCE_TYPE_NAME, MockProvider.EXAMPLE_RESOURCE_TYPE_ID, MockProvider.EXAMPLE_PERMISSION_NAME);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, exampleGroups, authorizationUtil, authorizationUtil)).thenReturn(true);
given().queryParam("permissionName", MockProvider.EXAMPLE_PERMISSION_NAME).queryParam("resourceName", MockProvider.EXAMPLE_RESOURCE_TYPE_NAME).queryParam("resourceType", MockProvider.EXAMPLE_RESOURCE_TYPE_ID).then().expect().statusCode(Status.OK.getStatusCode()).contentType(MediaType.APPLICATION_JSON).body("permissionName", equalTo(MockProvider.EXAMPLE_PERMISSION_NAME)).body("resourceName", equalTo(MockProvider.EXAMPLE_RESOURCE_TYPE_NAME)).body("resourceId", equalTo(null)).body("authorized", equalTo(true)).when().get(AUTH_CHECK_PATH);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, exampleGroups, authorizationUtil, authorizationUtil);
verify(identityServiceMock, times(1)).getCurrentAuthentication();
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class ApplicationContextPathUtil method getApplicationPathForDeployment.
public static String getApplicationPathForDeployment(ProcessEngine engine, String deploymentId) {
// get the name of the process application that made the deployment
String processApplicationName = null;
IdentityService identityService = engine.getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
try {
identityService.clearAuthentication();
processApplicationName = engine.getManagementService().getProcessApplicationForDeployment(deploymentId);
} finally {
identityService.setAuthentication(currentAuthentication);
}
if (processApplicationName == null) {
// no a process application deployment
return null;
} else {
ProcessApplicationService processApplicationService = BpmPlatform.getProcessApplicationService();
ProcessApplicationInfo processApplicationInfo = processApplicationService.getProcessApplicationInfo(processApplicationName);
return processApplicationInfo.getProperties().get(ProcessApplicationInfo.PROP_SERVLET_CONTEXT_PATH);
}
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class UserResourceImpl method updateCredentials.
public void updateCredentials(UserCredentialsDto account) {
ensureNotReadOnly();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
if (currentAuthentication != null && currentAuthentication.getUserId() != null) {
if (!identityService.checkPassword(currentAuthentication.getUserId(), account.getAuthenticatedUserPassword())) {
throw new InvalidRequestException(Status.BAD_REQUEST, "The given authenticated user password is not valid.");
}
}
User dbUser = findUserObject();
if (dbUser == null) {
throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist");
}
dbUser.setPassword(account.getPassword());
identityService.saveUser(dbUser);
}
Aggregations