Search in sources :

Example 6 with RequestContext

use of org.openkilda.auth.model.RequestContext in project open-kilda by telstra.

the class SwitchControllerTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    mockMvc = MockMvcBuilders.standaloneSetup(switchController).build();
    RequestContext requestContext = new RequestContext();
    requestContext.setUserId(TestIslMock.USER_ID);
    when(serverContext.getRequestContext()).thenReturn(requestContext);
}
Also used : RequestContext(org.openkilda.auth.model.RequestContext) Before(org.junit.Before)

Example 7 with RequestContext

use of org.openkilda.auth.model.RequestContext in project open-kilda by telstra.

the class UserService method getLoggedInUserInfo.

/**
 * Gets the logged in user info.
 *
 * @return the logged in user info
 * @throws AccessDeniedException the access denied exception
 */
public UserInfo getLoggedInUserInfo() throws AccessDeniedException {
    RequestContext requestContext = serverContext.getRequestContext();
    if (requestContext.getUserId() == null) {
        throw new AccessDeniedException(messageUtils.getUnauthorizedMessage());
    }
    UserInfo userInfo = new UserInfo();
    userInfo.setUserId(requestContext.getUserId());
    userInfo.setUsername(requestContext.getUserName());
    userInfo.setIs2FaEnabled(requestContext.getIs2FaEnabled());
    userInfo.setStatus(requestContext.getStatus());
    userInfo.setName(requestContext.getFullName());
    userInfo.setPermissions(requestContext.getPermissions());
    return userInfo;
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) UserInfo(org.usermanagement.model.UserInfo) RequestContext(org.openkilda.auth.model.RequestContext)

Aggregations

RequestContext (org.openkilda.auth.model.RequestContext)7 UserInfo (org.usermanagement.model.UserInfo)2 IOException (java.io.IOException)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 HttpSession (javax.servlet.http.HttpSession)1 HttpResponse (org.apache.http.HttpResponse)1 HttpClient (org.apache.http.client.HttpClient)1 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPatch (org.apache.http.client.methods.HttpPatch)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Before (org.junit.Before)1 Permissions (org.openkilda.auth.model.Permissions)1 BaseEntity (org.openkilda.entity.BaseEntity)1 ExternalSystemException (org.openkilda.exception.ExternalSystemException)1 RestCallFailedException (org.openkilda.exception.RestCallFailedException)1