Search in sources :

Example 1 with AuthorizationManager

use of com.agiletec.aps.system.services.authorization.AuthorizationManager in project entando-core by entando.

the class AbstractControllerTest method mockOAuthInterceptor.

protected String mockOAuthInterceptor(UserDetails user) throws Exception, ApsSystemException {
    String accessToken = OAuth2TestUtils.getValidAccessToken();
    when(apiOAuth2TokenManager.getApiOAuth2Token(Mockito.anyString())).thenReturn(OAuth2TestUtils.getOAuth2Token(user.getUsername(), accessToken));
    when(authenticationProviderManager.getUser(user.getUsername())).thenReturn(user);
    when(authorizationManager.isAuthOnPermission(any(UserDetails.class), anyString())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            UserDetails user = (UserDetails) invocation.getArguments()[0];
            String permissionName = (String) invocation.getArguments()[1];
            return new AuthorizationManager().isAuthOnPermission(user, permissionName);
        }
    });
    return accessToken;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) AuthorizationManager(com.agiletec.aps.system.services.authorization.AuthorizationManager)

Example 2 with AuthorizationManager

use of com.agiletec.aps.system.services.authorization.AuthorizationManager in project entando-core by entando.

the class AbstractControllerIntegrationTest method mockOAuthInterceptor.

protected String mockOAuthInterceptor(UserDetails user) throws Exception, ApsSystemException {
    String accessToken = OAuth2TestUtils.getValidAccessToken();
    when(apiOAuth2TokenManager.getApiOAuth2Token(Mockito.anyString())).thenReturn(OAuth2TestUtils.getOAuth2Token(user.getUsername(), accessToken));
    when(authenticationProviderManager.getUser(user.getUsername())).thenReturn(user);
    when(authorizationManager.isAuthOnPermission(any(UserDetails.class), anyString())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            UserDetails user = (UserDetails) invocation.getArguments()[0];
            String permissionName = (String) invocation.getArguments()[1];
            return new AuthorizationManager().isAuthOnPermission(user, permissionName);
        }
    });
    return accessToken;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) AuthorizationManager(com.agiletec.aps.system.services.authorization.AuthorizationManager)

Aggregations

AuthorizationManager (com.agiletec.aps.system.services.authorization.AuthorizationManager)2 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2