use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class WorkspaceManagerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
workspaceManager = new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, false, false, snapshotDao, sharedPool);
when(accountManager.getByName(NAMESPACE)).thenReturn(new AccountImpl("accountId", NAMESPACE, "test"));
when(accountManager.getByName(NAMESPACE_2)).thenReturn(new AccountImpl("accountId2", NAMESPACE_2, "test"));
when(workspaceDao.create(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
when(workspaceDao.update(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
EnvironmentContext.setCurrent(new EnvironmentContext() {
@Override
public Subject getSubject() {
return new SubjectImpl(NAMESPACE, USER_ID, "token", false);
}
});
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class EnvironmentInitializationFilter method doFilter.
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
Subject subject = new SubjectImpl("che", "che", "dummy_token", false);
HttpSession session = httpRequest.getSession();
session.setAttribute("codenvy_user", subject);
final EnvironmentContext environmentContext = EnvironmentContext.getCurrent();
try {
environmentContext.setSubject(subject);
filterChain.doFilter(addUserInRequest(httpRequest, subject), response);
} finally {
EnvironmentContext.reset();
}
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class OAuthAuthenticationService method token.
/**
* Gets OAuth token for user.
*
* @param oauthProvider
* OAuth provider name
* @return OAuthToken
* @throws ServerException
*/
@GET
@Path("token")
@Produces(MediaType.APPLICATION_JSON)
public OAuthToken token(@Required @QueryParam("oauth_provider") String oauthProvider) throws ServerException, BadRequestException, NotFoundException, ForbiddenException {
OAuthAuthenticator provider = getAuthenticator(oauthProvider);
final Subject subject = EnvironmentContext.getCurrent().getSubject();
try {
OAuthToken token = provider.getToken(subject.getUserId());
if (token == null) {
token = provider.getToken(subject.getUserName());
}
if (token != null) {
return token;
}
throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
} catch (IOException e) {
throw new ServerException(e.getLocalizedMessage(), e);
}
}
Aggregations