Commit 83927d32 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: use javax.security.Principal class to hold client principal

parent 894ac3b8
......@@ -17,6 +17,7 @@
package org.dcache.chimera.nfs.v4;
import java.security.Principal;
import org.dcache.chimera.nfs.ChimeraNFSException;
import org.dcache.chimera.nfs.ExportFile;
import org.dcache.chimera.nfs.v4.xdr.nfs_resop4;
......@@ -62,6 +63,7 @@ public class CompoundContext {
private int _currentOpPosition = -1;
private stateid4 _currentStateid = null;
private stateid4 _savedStateid = null;
private final Principal _principal;
/**
* Create context of COUMPOUND request.
......@@ -87,6 +89,7 @@ public class CompoundContext {
_stateHandler = stateHandler;
_idMapping = idMapping;
_totalOperationsCount = opCount;
_principal = principalOf(call);
}
public RpcCall getRpcCall() {
......@@ -291,4 +294,36 @@ public class CompoundContext {
}
};
}
public Principal getPrincipal() {
return _principal;
}
private Principal principalOf(final RpcCall call) {
// FIXME: get RPCSEC_GSS principal from rpc header
return new Principal() {
private final String _name = "";
@Override
public String getName() {
return _name;
}
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if ( obj == null || !obj.getClass().isInstance(this)) return false;
return this._name.equals(((Principal)obj).getName());
}
};
}
}
......@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.security.Principal;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
......@@ -89,7 +90,7 @@ public class NFS4Client {
/**
* The RPCSEC_GSS principal sent via the RPC headers.
*/
private final String _principal;
private final Principal _principal;
/**
* Client id generated by the server.
*/
......@@ -152,7 +153,7 @@ public class NFS4Client {
private final long _leaseTime;
public NFS4Client(InetSocketAddress clientAddress, InetSocketAddress localAddress,
byte[] ownerID, verifier4 verifier, String principal, long leaseTime) {
byte[] ownerID, verifier4 verifier, Principal principal, long leaseTime) {
_ownerId = new Opaque(ownerID);
_verifier = verifier;
......@@ -336,7 +337,7 @@ public class NFS4Client {
return _sessions.isEmpty();
}
public String principal() {
public Principal principal() {
return _principal;
}
......
......@@ -18,6 +18,7 @@
package org.dcache.chimera.nfs.v4;
import java.net.InetSocketAddress;
import java.security.Principal;
import org.dcache.chimera.nfs.nfsstat;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.ChimeraNFSException;
......@@ -132,7 +133,7 @@ public class NFSv4StateHandler {
}
public NFS4Client createClient(InetSocketAddress clientAddress, InetSocketAddress localAddress,
byte[] ownerID, verifier4 verifier, String principal) {
byte[] ownerID, verifier4 verifier, Principal principal) {
NFS4Client client = new NFS4Client(clientAddress, localAddress, ownerID, verifier, principal, _leaseTime);
addClient(client);
return client;
......
......@@ -98,8 +98,8 @@ public class OperationCREATE_SESSION extends AbstractNFSv4Operation {
* that is one greater than last successfully used.
*/
if (!client.principal().equals(Integer.toString(context.getUser().getUID())) && !client.isConfirmed()) {
throw new ChimeraNFSException(nfsstat.NFSERR_CLID_INUSE, "client already in use: " + client.principal() + " " + context.getUser().getUID());
if (!client.principal().equals(context.getPrincipal()) && !client.isConfirmed()) {
throw new ChimeraNFSException(nfsstat.NFSERR_CLID_INUSE, "client already in use: " + client.principal() + " " + context.getPrincipal());
}
NFSv41Session session = client.createSession(_args.opcreate_session.csa_sequence.value.value,
......
......@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.URL;
import java.security.CodeSource;
import java.security.Principal;
import java.security.ProtectionDomain;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
......@@ -142,7 +143,7 @@ public class OperationEXCHANGE_ID extends AbstractNFSv4Operation {
}
NFS4Client client = context.getStateHandler().clientByOwner(clientOwner);
final String principal = Integer.toString(context.getUser().getUID());
final Principal principal = context.getPrincipal();
final verifier4 verifier = _args.opexchange_id.eia_clientowner.co_verifier;
final boolean update = (_args.opexchange_id.eia_flags.value & nfs4_prot.EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) != 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment