You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@accumulo.apache.org by Benjamin Parrish <be...@gmail.com> on 2013/09/23 15:24:36 UTC

Setting authorizations in code

I am trying to set authorizations in code, but the scanner is always returning the previous fetch of data using the previous authorizations.  I am setting the Authorizations on the Connector, and then I get a new Scanner after setting the Authorizations.
	
	public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
		List<byte[]> authorizationList = new ArrayList<byte[]>();
		
		for (SecurityGroup auth : authorizations) {
			String groupString = Security.getName(auth);
			
			byte[] groupBytes = groupString.getBytes();
			
			authorizationList.add(groupBytes);
		}
		
		Authorizations auths = new Authorizations(authorizationList);
		
		try {
			connector.securityOperations().changeUserAuthorizations(_loggedInUser, auths);
			
			return auths;
		} catch (AccumuloException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AccumuloSecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
	public Scanner getScanner() {
        	try {
        		Authorizations auths = this.getAuthorizations();
		    
			return connector.createScanner(TABLE, auths);
		} catch (TableNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        	return null;
	}
	
	@Override
	public Collection<Plate> filter(SecurityGroup[] authorizations, String regEx) {
		_db.setAuthorizations(authorizations);
		
		Scanner scanner = _db.getScanner();

		String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
        
		scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
        
		IteratorSetting iter = new IteratorSetting(1, "regexfilter", RegExFilter.class);
        
        	iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
        
        	scanner.addScanIterator(iter);
		
		Iterator<Entry<Key, Value>> it = scanner.iterator();
		
		Map<Text, Plate> map = new HashMap<Text, Plate>();
	    
	    	while (it.hasNext()) {
		    	Entry<Key,Value> entry = it.next();
		    
		    	Text rowId = entry.getKey().getRow();
		    
		    	if (map.containsKey(rowId)) {
		    		continue;
		    	}
		    
	    		Plate plate = new Plate(Plate.getMap(rowId, scanner));
		    
		    	map.put(rowId, plate);
	    	}
		
		return map.values();
	}

Re: Setting authorizations in code

Posted by Josh Elser <jo...@gmail.com>.
I imagine that it might be useful to add a "wait" option to more (if
not all) of the client API where applicable (securityOperations being
one of them). We already have the resources with fate to handle these
transactions, so it would be nice to present that capability to users.

Benjamin, want to add a sleep for a second or two to your code to
verify that this is what you're seeing?



On Mon, Sep 23, 2013 at 12:06 PM, Eric Newton <er...@gmail.com> wrote:
> Authorizations, like all settings, take a moment to propagate to all
> servers.
>
> -Eric
>
>
>
> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
> <be...@gmail.com> wrote:
>>
>> I am trying to set authorizations in code, but the scanner is always
>> returning the previous fetch of data using the previous authorizations.  I
>> am setting the Authorizations on the Connector, and then I get a new Scanner
>> after setting the Authorizations.
>>
>>
>> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
>> List<byte[]> authorizationList = new ArrayList<byte[]>();
>>
>>
>> for (SecurityGroup auth : authorizations) {
>> String groupString = Security.getName(auth);
>>
>>
>> byte[] groupBytes = groupString.getBytes();
>>
>>
>> authorizationList.add(groupBytes);
>> }
>>
>>
>> Authorizations auths = new Authorizations(authorizationList);
>>
>>
>> try {
>> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
>> auths);
>>
>>
>> return auths;
>> } catch (AccumuloException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> } catch (AccumuloSecurityException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>>
>> return null;
>> }
>>
>>
>> public Scanner getScanner() {
>>         try {
>>         Authorizations auths = this.getAuthorizations();
>>
>>
>>
>> return connector.createScanner(TABLE, auths);
>> } catch (TableNotFoundException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>>
>>
>>         return null;
>> }
>>
>>
>> @Override
>> public Collection<Plate> filter(SecurityGroup[] authorizations, String
>> regEx) {
>> _db.setAuthorizations(authorizations);
>>
>>
>> Scanner scanner = _db.getScanner();
>>
>> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>>
>>
>>
>> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>>
>>
>>
>> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
>> RegExFilter.class);
>>
>>
>>
>>         iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>>
>>
>>
>>         scanner.addScanIterator(iter);
>>
>>
>> Iterator<Entry<Key, Value>> it = scanner.iterator();
>>
>>
>> Map<Text, Plate> map = new HashMap<Text, Plate>();
>>
>>
>>
>>     while (it.hasNext()) {
>>     Entry<Key,Value> entry = it.next();
>>
>>
>>
>>     Text rowId = entry.getKey().getRow();
>>
>>
>>
>>     if (map.containsKey(rowId)) {
>>     continue;
>>     }
>>
>>
>>
>>     Plate plate = new Plate(Plate.getMap(rowId, scanner));
>>
>>
>>
>>     map.put(rowId, plate);
>>     }
>>
>>
>> return map.values();
>> }
>
>

Re: Setting authorizations in code

Posted by Benjamin Parrish <be...@gmail.com>.
No, GORM (Grails Object Relational Mapping)

On Sep 23, 2013, at 9:18 PM, David Medinets <da...@gmail.com> wrote:

> When you say "GORM", are you talking about Apache GORA? If so, see https://github.com/medined/gora-with-accumulo for a few examples. Nothing very elaborate, I'm afraid.
> 
> 
> On Mon, Sep 23, 2013 at 3:34 PM, Benjamin Parrish <be...@gmail.com> wrote:
> yeah, I think I found the error when trying to add a Range to the Scanner object when doing 'Plate plate = new Plate(Plate.getMap(rowId, scanner));'  I modified the Scanner in the getMap() method, but the data wasn't persisting correctly.
> 
> Side question.  Has anyone started a helper library or GORM for Accumulo?
> 
> On Sep 23, 2013, at 2:46 PM, Michael Wall <mj...@gmail.com> wrote:
> 
> > Without seeing all your code, I notice that both setAuthorizations and
> > getScanner return null.  Are you sure whatever _db is in the filter
> > method is getting setup as you expect?
> >
> > On Mon, Sep 23, 2013 at 12:28 PM, Benjamin Parrish
> > <be...@gmail.com> wrote:
> >> This is on a stand-alone instance.  Stepping through the code I can see that
> >> it is getting the correct Authorizations from getAuthorizations() method
> >> that I have, and it propagates to the Scanner object, but the Scanner object
> >> is not pulling in the data associated with that column visibility.  I can
> >> run a setauths on the shell and see all the data with the same
> >> Authorization.
> >>
> >> On Sep 23, 2013, at 12:06 PM, Eric Newton <er...@gmail.com> wrote:
> >>
> >> Authorizations, like all settings, take a moment to propagate to all
> >> servers.
> >>
> >> -Eric
> >>
> >>
> >>
> >> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
> >> <be...@gmail.com> wrote:
> >>>
> >>> I am trying to set authorizations in code, but the scanner is always
> >>> returning the previous fetch of data using the previous authorizations.  I
> >>> am setting the Authorizations on the Connector, and then I get a new Scanner
> >>> after setting the Authorizations.
> >>>
> >>> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
> >>> List<byte[]> authorizationList = new ArrayList<byte[]>();
> >>>
> >>> for (SecurityGroup auth : authorizations) {
> >>> String groupString = Security.getName(auth);
> >>>
> >>> byte[] groupBytes = groupString.getBytes();
> >>>
> >>> authorizationList.add(groupBytes);
> >>> }
> >>>
> >>> Authorizations auths = new Authorizations(authorizationList);
> >>>
> >>> try {
> >>> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
> >>> auths);
> >>>
> >>> return auths;
> >>> } catch (AccumuloException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> } catch (AccumuloSecurityException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> }
> >>>
> >>> return null;
> >>> }
> >>>
> >>> public Scanner getScanner() {
> >>>        try {
> >>>        Authorizations auths = this.getAuthorizations();
> >>>
> >>> return connector.createScanner(TABLE, auths);
> >>> } catch (TableNotFoundException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> }
> >>>
> >>>        return null;
> >>> }
> >>>
> >>> @Override
> >>> public Collection<Plate> filter(SecurityGroup[] authorizations, String
> >>> regEx) {
> >>> _db.setAuthorizations(authorizations);
> >>>
> >>> Scanner scanner = _db.getScanner();
> >>>
> >>> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
> >>>
> >>> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
> >>>
> >>> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
> >>> RegExFilter.class);
> >>>
> >>>        iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
> >>>
> >>>        scanner.addScanIterator(iter);
> >>>
> >>> Iterator<Entry<Key, Value>> it = scanner.iterator();
> >>>
> >>> Map<Text, Plate> map = new HashMap<Text, Plate>();
> >>>
> >>>    while (it.hasNext()) {
> >>>    Entry<Key,Value> entry = it.next();
> >>>
> >>>    Text rowId = entry.getKey().getRow();
> >>>
> >>>    if (map.containsKey(rowId)) {
> >>>    continue;
> >>>    }
> >>>
> >>>    Plate plate = new Plate(Plate.getMap(rowId, scanner));
> >>>
> >>>    map.put(rowId, plate);
> >>>    }
> >>>
> >>> return map.values();
> >>> }
> >>
> >>
> >>
> 
> 


Re: Setting authorizations in code

Posted by David Medinets <da...@gmail.com>.
When you say "GORM", are you talking about Apache GORA? If so, see
https://github.com/medined/gora-with-accumulo for a few examples. Nothing
very elaborate, I'm afraid.


On Mon, Sep 23, 2013 at 3:34 PM, Benjamin Parrish <
benjamin.d.parrish@gmail.com> wrote:

> yeah, I think I found the error when trying to add a Range to the Scanner
> object when doing 'Plate plate = new Plate(Plate.getMap(rowId, scanner));'
>  I modified the Scanner in the getMap() method, but the data wasn't
> persisting correctly.
>
> Side question.  Has anyone started a helper library or GORM for Accumulo?
>
> On Sep 23, 2013, at 2:46 PM, Michael Wall <mj...@gmail.com> wrote:
>
> > Without seeing all your code, I notice that both setAuthorizations and
> > getScanner return null.  Are you sure whatever _db is in the filter
> > method is getting setup as you expect?
> >
> > On Mon, Sep 23, 2013 at 12:28 PM, Benjamin Parrish
> > <be...@gmail.com> wrote:
> >> This is on a stand-alone instance.  Stepping through the code I can see
> that
> >> it is getting the correct Authorizations from getAuthorizations() method
> >> that I have, and it propagates to the Scanner object, but the Scanner
> object
> >> is not pulling in the data associated with that column visibility.  I
> can
> >> run a setauths on the shell and see all the data with the same
> >> Authorization.
> >>
> >> On Sep 23, 2013, at 12:06 PM, Eric Newton <er...@gmail.com>
> wrote:
> >>
> >> Authorizations, like all settings, take a moment to propagate to all
> >> servers.
> >>
> >> -Eric
> >>
> >>
> >>
> >> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
> >> <be...@gmail.com> wrote:
> >>>
> >>> I am trying to set authorizations in code, but the scanner is always
> >>> returning the previous fetch of data using the previous
> authorizations.  I
> >>> am setting the Authorizations on the Connector, and then I get a new
> Scanner
> >>> after setting the Authorizations.
> >>>
> >>> public Authorizations setAuthorizations(SecurityGroup[]
> authorizations) {
> >>> List<byte[]> authorizationList = new ArrayList<byte[]>();
> >>>
> >>> for (SecurityGroup auth : authorizations) {
> >>> String groupString = Security.getName(auth);
> >>>
> >>> byte[] groupBytes = groupString.getBytes();
> >>>
> >>> authorizationList.add(groupBytes);
> >>> }
> >>>
> >>> Authorizations auths = new Authorizations(authorizationList);
> >>>
> >>> try {
> >>> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
> >>> auths);
> >>>
> >>> return auths;
> >>> } catch (AccumuloException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> } catch (AccumuloSecurityException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> }
> >>>
> >>> return null;
> >>> }
> >>>
> >>> public Scanner getScanner() {
> >>>        try {
> >>>        Authorizations auths = this.getAuthorizations();
> >>>
> >>> return connector.createScanner(TABLE, auths);
> >>> } catch (TableNotFoundException e) {
> >>> // TODO Auto-generated catch block
> >>> e.printStackTrace();
> >>> }
> >>>
> >>>        return null;
> >>> }
> >>>
> >>> @Override
> >>> public Collection<Plate> filter(SecurityGroup[] authorizations, String
> >>> regEx) {
> >>> _db.setAuthorizations(authorizations);
> >>>
> >>> Scanner scanner = _db.getScanner();
> >>>
> >>> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
> >>>
> >>> scanner.fetchColumn(Plate.COLUMN_FAMILY, new
> Text(Plate.PLATE_QUALIFIER));
> >>>
> >>> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
> >>> RegExFilter.class);
> >>>
> >>>        iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
> >>>
> >>>        scanner.addScanIterator(iter);
> >>>
> >>> Iterator<Entry<Key, Value>> it = scanner.iterator();
> >>>
> >>> Map<Text, Plate> map = new HashMap<Text, Plate>();
> >>>
> >>>    while (it.hasNext()) {
> >>>    Entry<Key,Value> entry = it.next();
> >>>
> >>>    Text rowId = entry.getKey().getRow();
> >>>
> >>>    if (map.containsKey(rowId)) {
> >>>    continue;
> >>>    }
> >>>
> >>>    Plate plate = new Plate(Plate.getMap(rowId, scanner));
> >>>
> >>>    map.put(rowId, plate);
> >>>    }
> >>>
> >>> return map.values();
> >>> }
> >>
> >>
> >>
>
>

Re: Setting authorizations in code

Posted by Benjamin Parrish <be...@gmail.com>.
yeah, I think I found the error when trying to add a Range to the Scanner object when doing 'Plate plate = new Plate(Plate.getMap(rowId, scanner));'  I modified the Scanner in the getMap() method, but the data wasn't persisting correctly.

Side question.  Has anyone started a helper library or GORM for Accumulo?

On Sep 23, 2013, at 2:46 PM, Michael Wall <mj...@gmail.com> wrote:

> Without seeing all your code, I notice that both setAuthorizations and
> getScanner return null.  Are you sure whatever _db is in the filter
> method is getting setup as you expect?
> 
> On Mon, Sep 23, 2013 at 12:28 PM, Benjamin Parrish
> <be...@gmail.com> wrote:
>> This is on a stand-alone instance.  Stepping through the code I can see that
>> it is getting the correct Authorizations from getAuthorizations() method
>> that I have, and it propagates to the Scanner object, but the Scanner object
>> is not pulling in the data associated with that column visibility.  I can
>> run a setauths on the shell and see all the data with the same
>> Authorization.
>> 
>> On Sep 23, 2013, at 12:06 PM, Eric Newton <er...@gmail.com> wrote:
>> 
>> Authorizations, like all settings, take a moment to propagate to all
>> servers.
>> 
>> -Eric
>> 
>> 
>> 
>> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
>> <be...@gmail.com> wrote:
>>> 
>>> I am trying to set authorizations in code, but the scanner is always
>>> returning the previous fetch of data using the previous authorizations.  I
>>> am setting the Authorizations on the Connector, and then I get a new Scanner
>>> after setting the Authorizations.
>>> 
>>> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
>>> List<byte[]> authorizationList = new ArrayList<byte[]>();
>>> 
>>> for (SecurityGroup auth : authorizations) {
>>> String groupString = Security.getName(auth);
>>> 
>>> byte[] groupBytes = groupString.getBytes();
>>> 
>>> authorizationList.add(groupBytes);
>>> }
>>> 
>>> Authorizations auths = new Authorizations(authorizationList);
>>> 
>>> try {
>>> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
>>> auths);
>>> 
>>> return auths;
>>> } catch (AccumuloException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> } catch (AccumuloSecurityException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> 
>>> return null;
>>> }
>>> 
>>> public Scanner getScanner() {
>>>        try {
>>>        Authorizations auths = this.getAuthorizations();
>>> 
>>> return connector.createScanner(TABLE, auths);
>>> } catch (TableNotFoundException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> 
>>>        return null;
>>> }
>>> 
>>> @Override
>>> public Collection<Plate> filter(SecurityGroup[] authorizations, String
>>> regEx) {
>>> _db.setAuthorizations(authorizations);
>>> 
>>> Scanner scanner = _db.getScanner();
>>> 
>>> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>>> 
>>> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>>> 
>>> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
>>> RegExFilter.class);
>>> 
>>>        iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>>> 
>>>        scanner.addScanIterator(iter);
>>> 
>>> Iterator<Entry<Key, Value>> it = scanner.iterator();
>>> 
>>> Map<Text, Plate> map = new HashMap<Text, Plate>();
>>> 
>>>    while (it.hasNext()) {
>>>    Entry<Key,Value> entry = it.next();
>>> 
>>>    Text rowId = entry.getKey().getRow();
>>> 
>>>    if (map.containsKey(rowId)) {
>>>    continue;
>>>    }
>>> 
>>>    Plate plate = new Plate(Plate.getMap(rowId, scanner));
>>> 
>>>    map.put(rowId, plate);
>>>    }
>>> 
>>> return map.values();
>>> }
>> 
>> 
>> 


Re: Setting authorizations in code

Posted by Michael Wall <mj...@gmail.com>.
Without seeing all your code, I notice that both setAuthorizations and
getScanner return null.  Are you sure whatever _db is in the filter
method is getting setup as you expect?

On Mon, Sep 23, 2013 at 12:28 PM, Benjamin Parrish
<be...@gmail.com> wrote:
> This is on a stand-alone instance.  Stepping through the code I can see that
> it is getting the correct Authorizations from getAuthorizations() method
> that I have, and it propagates to the Scanner object, but the Scanner object
> is not pulling in the data associated with that column visibility.  I can
> run a setauths on the shell and see all the data with the same
> Authorization.
>
> On Sep 23, 2013, at 12:06 PM, Eric Newton <er...@gmail.com> wrote:
>
> Authorizations, like all settings, take a moment to propagate to all
> servers.
>
> -Eric
>
>
>
> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
> <be...@gmail.com> wrote:
>>
>> I am trying to set authorizations in code, but the scanner is always
>> returning the previous fetch of data using the previous authorizations.  I
>> am setting the Authorizations on the Connector, and then I get a new Scanner
>> after setting the Authorizations.
>>
>> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
>> List<byte[]> authorizationList = new ArrayList<byte[]>();
>>
>> for (SecurityGroup auth : authorizations) {
>> String groupString = Security.getName(auth);
>>
>> byte[] groupBytes = groupString.getBytes();
>>
>> authorizationList.add(groupBytes);
>> }
>>
>> Authorizations auths = new Authorizations(authorizationList);
>>
>> try {
>> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
>> auths);
>>
>> return auths;
>> } catch (AccumuloException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> } catch (AccumuloSecurityException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>> return null;
>> }
>>
>> public Scanner getScanner() {
>>         try {
>>         Authorizations auths = this.getAuthorizations();
>>
>> return connector.createScanner(TABLE, auths);
>> } catch (TableNotFoundException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>>         return null;
>> }
>>
>> @Override
>> public Collection<Plate> filter(SecurityGroup[] authorizations, String
>> regEx) {
>> _db.setAuthorizations(authorizations);
>>
>> Scanner scanner = _db.getScanner();
>>
>> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>>
>> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>>
>> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
>> RegExFilter.class);
>>
>>         iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>>
>>         scanner.addScanIterator(iter);
>>
>> Iterator<Entry<Key, Value>> it = scanner.iterator();
>>
>> Map<Text, Plate> map = new HashMap<Text, Plate>();
>>
>>     while (it.hasNext()) {
>>     Entry<Key,Value> entry = it.next();
>>
>>     Text rowId = entry.getKey().getRow();
>>
>>     if (map.containsKey(rowId)) {
>>     continue;
>>     }
>>
>>     Plate plate = new Plate(Plate.getMap(rowId, scanner));
>>
>>     map.put(rowId, plate);
>>     }
>>
>> return map.values();
>> }
>
>
>

Re: Setting authorizations in code

Posted by Benjamin Parrish <be...@gmail.com>.
This is on a stand-alone instance.  Stepping through the code I can see that it is getting the correct Authorizations from getAuthorizations() method that I have, and it propagates to the Scanner object, but the Scanner object is not pulling in the data associated with that column visibility.  I can run a setauths on the shell and see all the data with the same Authorization.

On Sep 23, 2013, at 12:06 PM, Eric Newton <er...@gmail.com> wrote:

> Authorizations, like all settings, take a moment to propagate to all servers.
> 
> -Eric
> 
> 
> 
> On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish <be...@gmail.com> wrote:
> I am trying to set authorizations in code, but the scanner is always returning the previous fetch of data using the previous authorizations.  I am setting the Authorizations on the Connector, and then I get a new Scanner after setting the Authorizations.
> 	
> 	public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
> 		List<byte[]> authorizationList = new ArrayList<byte[]>();
> 		
> 		for (SecurityGroup auth : authorizations) {
> 			String groupString = Security.getName(auth);
> 			
> 			byte[] groupBytes = groupString.getBytes();
> 			
> 			authorizationList.add(groupBytes);
> 		}
> 		
> 		Authorizations auths = new Authorizations(authorizationList);
> 		
> 		try {
> 			connector.securityOperations().changeUserAuthorizations(_loggedInUser, auths);
> 			
> 			return auths;
> 		} catch (AccumuloException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		} catch (AccumuloSecurityException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 		
> 		return null;
> 	}
> 	
> 	public Scanner getScanner() {
>         	try {
>         		Authorizations auths = this.getAuthorizations();
> 		    
> 			return connector.createScanner(TABLE, auths);
> 		} catch (TableNotFoundException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
>         
>         	return null;
> 	}
> 	
> 	@Override
> 	public Collection<Plate> filter(SecurityGroup[] authorizations, String regEx) {
> 		_db.setAuthorizations(authorizations);
> 		
> 		Scanner scanner = _db.getScanner();
> 
> 		String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>         
> 		scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>         
> 		IteratorSetting iter = new IteratorSetting(1, "regexfilter", RegExFilter.class);
>         
>         	iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>         
>         	scanner.addScanIterator(iter);
> 		
> 		Iterator<Entry<Key, Value>> it = scanner.iterator();
> 		
> 		Map<Text, Plate> map = new HashMap<Text, Plate>();
> 	    
> 	    	while (it.hasNext()) {
> 		    	Entry<Key,Value> entry = it.next();
> 		    
> 		    	Text rowId = entry.getKey().getRow();
> 		    
> 		    	if (map.containsKey(rowId)) {
> 		    		continue;
> 		    	}
> 		    
> 	    		Plate plate = new Plate(Plate.getMap(rowId, scanner));
> 		    
> 		    	map.put(rowId, plate);
> 	    	}
> 		
> 		return map.values();
> 	}
> 


Re: Setting authorizations in code

Posted by Eric Newton <er...@gmail.com>.
Authorizations, like all settings, take a moment to propagate to all
servers.

-Eric



On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish <
benjamin.d.parrish@gmail.com> wrote:

> I am trying to set authorizations in code, but the scanner is always
> returning the previous fetch of data using the previous authorizations.  I
> am setting the Authorizations on the Connector, and then I get a new
> Scanner after setting the Authorizations.
>
>
> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
> List<byte[]> authorizationList = new ArrayList<byte[]>();
>
>
> for (SecurityGroup auth : authorizations) {
> String groupString = Security.getName(auth);
>
>
> byte[] groupBytes = groupString.getBytes();
>
>
> authorizationList.add(groupBytes);
> }
>
>
> Authorizations auths = new Authorizations(authorizationList);
>
>
> try {
> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
> auths);
>
>
> return auths;
> } catch (AccumuloException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (AccumuloSecurityException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> return null;
> }
>
>
> public Scanner getScanner() {
>         try {
>         Authorizations auths = this.getAuthorizations();
>
>
> return connector.createScanner(TABLE, auths);
> } catch (TableNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
>         return null;
> }
>
>
> @Override
> public Collection<Plate> filter(SecurityGroup[] authorizations, String
> regEx) {
> _db.setAuthorizations(authorizations);
>
>
> Scanner scanner = _db.getScanner();
>
> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>
>
> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>
>
> IteratorSetting iter = new IteratorSetting(1, "regexfilter", RegExFilter.
> class);
>
>
>         iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>
>
>         scanner.addScanIterator(iter);
>
>
> Iterator<Entry<Key, Value>> it = scanner.iterator();
>
>
> Map<Text, Plate> map = new HashMap<Text, Plate>();
>
>
>     while (it.hasNext()) {
>     Entry<Key,Value> entry = it.next();
>
>
>     Text rowId = entry.getKey().getRow();
>
>
>     if (map.containsKey(rowId)) {
>      continue;
>     }
>
>
>     Plate plate = new Plate(Plate.getMap(rowId, scanner));
>
>
>     map.put(rowId, plate);
>     }
>
>
> return map.values();
> }
>

Re: Setting authorizations in code

Posted by Josh Elser <jo...@gmail.com>.
Benjamin,

What's the implementation of the getAuthorizations method called in
the getScanner method? Is the call to setAuthorizations on the _db
object the same setAuthorizations method you provided?

The full context of what you're doing would certainly be helpful.
Also, what version of Accumulo are you using?

On Mon, Sep 23, 2013 at 9:24 AM, Benjamin Parrish
<be...@gmail.com> wrote:
> I am trying to set authorizations in code, but the scanner is always
> returning the previous fetch of data using the previous authorizations.  I
> am setting the Authorizations on the Connector, and then I get a new Scanner
> after setting the Authorizations.
>
>
> public Authorizations setAuthorizations(SecurityGroup[] authorizations) {
> List<byte[]> authorizationList = new ArrayList<byte[]>();
>
>
> for (SecurityGroup auth : authorizations) {
> String groupString = Security.getName(auth);
>
>
> byte[] groupBytes = groupString.getBytes();
>
>
> authorizationList.add(groupBytes);
> }
>
>
> Authorizations auths = new Authorizations(authorizationList);
>
>
> try {
> connector.securityOperations().changeUserAuthorizations(_loggedInUser,
> auths);
>
>
> return auths;
> } catch (AccumuloException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (AccumuloSecurityException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> return null;
> }
>
>
> public Scanner getScanner() {
>         try {
>         Authorizations auths = this.getAuthorizations();
>
>
>
> return connector.createScanner(TABLE, auths);
> } catch (TableNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
>
>         return null;
> }
>
>
> @Override
> public Collection<Plate> filter(SecurityGroup[] authorizations, String
> regEx) {
> _db.setAuthorizations(authorizations);
>
>
> Scanner scanner = _db.getScanner();
>
> String valueRegex = (regEx.equals("")) ? ".*" : regEx + ".*";
>
>
>
> scanner.fetchColumn(Plate.COLUMN_FAMILY, new Text(Plate.PLATE_QUALIFIER));
>
>
>
> IteratorSetting iter = new IteratorSetting(1, "regexfilter",
> RegExFilter.class);
>
>
>
>         iter.addOption(RegExFilter.VALUE_REGEX, valueRegex);
>
>
>
>         scanner.addScanIterator(iter);
>
>
> Iterator<Entry<Key, Value>> it = scanner.iterator();
>
>
> Map<Text, Plate> map = new HashMap<Text, Plate>();
>
>
>
>     while (it.hasNext()) {
>     Entry<Key,Value> entry = it.next();
>
>
>
>     Text rowId = entry.getKey().getRow();
>
>
>
>     if (map.containsKey(rowId)) {
>     continue;
>     }
>
>
>
>     Plate plate = new Plate(Plate.getMap(rowId, scanner));
>
>
>
>     map.put(rowId, plate);
>     }
>
>
> return map.values();
> }