Search in sources :

Example 6 with Subject

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);
        }
    });
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with Subject

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) HttpSession(javax.servlet.http.HttpSession) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject)

Example 8 with Subject

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);
    }
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Subject(org.eclipse.che.commons.subject.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Subject (org.eclipse.che.commons.subject.Subject)8 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)3 IOException (java.io.IOException)2 Path (javax.ws.rs.Path)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)2 Test (org.testng.annotations.Test)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 AccountImpl (org.eclipse.che.account.spi.AccountImpl)1 OAuthToken (org.eclipse.che.api.auth.shared.dto.OAuthToken)1 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)1 SimplePrincipal (org.everrest.core.tools.SimplePrincipal)1 SimpleSecurityContext (org.everrest.core.tools.SimpleSecurityContext)1