use of java.security.Principal in project jersey by jersey.
the class InMemoryConnector method apply.
/**
* {@inheritDoc}
* <p/>
* Transforms client-side request to server-side and invokes it on provided application ({@link ApplicationHandler}
* instance).
*
* @param clientRequest client side request to be invoked.
*/
@Override
public ClientResponse apply(final ClientRequest clientRequest) {
PropertiesDelegate propertiesDelegate = new MapPropertiesDelegate();
final ContainerRequest containerRequest = new ContainerRequest(baseUri, clientRequest.getUri(), clientRequest.getMethod(), null, propertiesDelegate);
containerRequest.getHeaders().putAll(clientRequest.getStringHeaders());
final ByteArrayOutputStream clientOutput = new ByteArrayOutputStream();
if (clientRequest.getEntity() != null) {
clientRequest.setStreamProvider(new OutboundMessageContext.StreamProvider() {
@Override
public OutputStream getOutputStream(int contentLength) throws IOException {
final MultivaluedMap<String, Object> clientHeaders = clientRequest.getHeaders();
if (contentLength != -1 && !clientHeaders.containsKey(HttpHeaders.CONTENT_LENGTH)) {
containerRequest.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength));
}
return clientOutput;
}
});
clientRequest.enableBuffering();
try {
clientRequest.writeEntity();
} catch (IOException e) {
final String msg = "Error while writing entity to the output stream.";
LOGGER.log(Level.SEVERE, msg, e);
throw new ProcessingException(msg, e);
}
}
containerRequest.setEntityStream(new ByteArrayInputStream(clientOutput.toByteArray()));
boolean followRedirects = ClientProperties.getValue(clientRequest.getConfiguration().getProperties(), ClientProperties.FOLLOW_REDIRECTS, true);
final InMemoryResponseWriter inMemoryResponseWriter = new InMemoryResponseWriter();
containerRequest.setWriter(inMemoryResponseWriter);
containerRequest.setSecurityContext(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public boolean isUserInRole(String role) {
return false;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
appHandler.handle(containerRequest);
return tryFollowRedirects(followRedirects, createClientResponse(clientRequest, inMemoryResponseWriter), new ClientRequest(clientRequest));
}
use of java.security.Principal in project pinpoint by naver.
the class JbossUtility method fetchRemoteAddress.
/**
* Fetch remote address.
*
* @param connection the connection
* @return the string
*/
public static String fetchRemoteAddress(final Connection connection) {
if (connection == null) {
return "";
}
final List<String> remoteAddressInfos = new ArrayList<String>();
for (final Principal principal : connection.getPrincipals()) {
if (principal instanceof org.jboss.remoting3.security.InetAddressPrincipal) {
final InetAddress inetAddress = ((org.jboss.remoting3.security.InetAddressPrincipal) principal).getInetAddress();
initializeRemoteAddressInfo(remoteAddressInfos, inetAddress);
break;
}
}
return remoteAddressInfos.toString();
}
use of java.security.Principal in project neo4j by neo4j.
the class AuthorizedRequestWrapper method getSecurityContextFromHttpContext.
public static SecurityContext getSecurityContextFromHttpContext(HttpContext httpContext) {
HttpRequestContext requestContext = httpContext.getRequest();
Principal principal = requestContext.getUserPrincipal();
return getSecurityContextFromUserPrincipal(principal);
}
use of java.security.Principal in project neo4j by neo4j.
the class UserService method getUser.
@GET
@Path("/{username}")
public Response getUser(@PathParam("username") String username, @Context HttpServletRequest req) {
Principal principal = req.getUserPrincipal();
if (principal == null || !principal.getName().equals(username)) {
return output.notFound();
}
SecurityContext securityContext = getSecurityContextFromUserPrincipal(principal);
UserManager userManager = userManagerSupplier.getUserManager(securityContext);
try {
User user = userManager.getUser(username);
return output.ok(new AuthorizationRepresentation(user));
} catch (InvalidArgumentsException e) {
return output.notFound();
}
}
use of java.security.Principal in project orientdb by orientechnologies.
the class OKerberosCredentialInterceptor method getFirstPrincipal.
private String getFirstPrincipal(Subject subject) {
if (subject != null) {
final Object[] principals = subject.getPrincipals().toArray();
final Principal p = (Principal) principals[0];
return p.getName();
}
return null;
}
Aggregations