use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class ServerContainerInitializeListener method createSecurityContext.
protected SecurityContext createSecurityContext(final HandshakeRequest req) {
//todo: get somehow from request
final boolean isSecure = false;
final String authType = "BASIC";
final Subject subject = EnvironmentContext.getCurrent().getSubject();
final Principal principal = new SimplePrincipal(subject.getUserName());
return new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return principal;
}
@Override
public boolean isUserInRole(String role) {
return false;
}
@Override
public boolean isSecure() {
return isSecure;
}
@Override
public String getAuthenticationScheme() {
return authType;
}
};
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class OAuthAuthenticationService method invalidate.
@DELETE
@Path("token")
public void invalidate(@Required @QueryParam("oauth_provider") String oauthProvider) throws BadRequestException, NotFoundException, ServerException, ForbiddenException {
OAuthAuthenticator oauth = getAuthenticator(oauthProvider);
final Subject subject = EnvironmentContext.getCurrent().getSubject();
try {
if (!oauth.invalidateToken(subject.getUserId())) {
throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
}
} catch (IOException e) {
throw new ServerException(e.getMessage());
}
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class FactoryEditValidatorImplTest method setCurrentUser.
private void setCurrentUser(String userId) {
Subject subject = mock(Subject.class);
when(subject.getUserId()).thenReturn(userId);
EnvironmentContext.getCurrent().setSubject(subject);
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class EnvironmentContextTest method shouldReturnAnonymousSubjectWhenThereIsNoSubject.
@Test
public void shouldReturnAnonymousSubjectWhenThereIsNoSubject() {
//given
EnvironmentContext expected = EnvironmentContext.getCurrent();
expected.setSubject(null);
//when
Subject actualSubject = EnvironmentContext.getCurrent().getSubject();
//then
assertEquals(actualSubject.getUserName(), Subject.ANONYMOUS.getUserName());
assertEquals(actualSubject.getUserId(), Subject.ANONYMOUS.getUserId());
assertEquals(actualSubject.getToken(), Subject.ANONYMOUS.getToken());
assertEquals(actualSubject.isTemporary(), Subject.ANONYMOUS.isTemporary());
assertEquals(actualSubject.isAnonymous(), Subject.ANONYMOUS.isAnonymous());
}
use of org.eclipse.che.commons.subject.Subject in project che by eclipse.
the class EnvironmentContextTest method shouldBeAbleToSetEnvContextInSameThread.
@Test
public void shouldBeAbleToSetEnvContextInSameThread() {
//given
EnvironmentContext expected = EnvironmentContext.getCurrent();
expected.setSubject(new SubjectImpl("user", "id", "token", false));
EnvironmentContext actual = EnvironmentContext.getCurrent();
Subject actualSubject = actual.getSubject();
assertEquals(actualSubject.getUserName(), "user");
assertEquals(actualSubject.getUserId(), "id");
assertEquals(actualSubject.getToken(), "token");
assertFalse(actualSubject.isTemporary());
}
Aggregations