44import com .fasterxml .jackson .databind .JsonNode ;
55import com .fasterxml .jackson .databind .ObjectMapper ;
66import cz .metacentrum .perun .core .api .Attribute ;
7+ import cz .metacentrum .perun .core .api .AttributesManager ;
78import cz .metacentrum .perun .core .api .User ;
9+ import cz .metacentrum .perun .core .api .exceptions .AttributeNotExistsException ;
810import cz .metacentrum .perun .core .api .exceptions .WrongAttributeAssignmentException ;
911import cz .metacentrum .perun .core .api .exceptions .WrongAttributeValueException ;
1012import cz .metacentrum .perun .core .api .exceptions .WrongReferenceAttributeValueException ;
1113import cz .metacentrum .perun .core .impl .PerunSessionImpl ;
1214import cz .metacentrum .perun .core .implApi .modules .attributes .UserAttributesModuleAbstract ;
1315import cz .metacentrum .perun .core .implApi .modules .attributes .UserAttributesModuleImplApi ;
16+
17+ import java .util .Collections ;
1418import java .util .HashSet ;
1519import java .util .Iterator ;
1620import java .util .Map ;
@@ -142,11 +146,21 @@ public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, At
142146 throw new WrongAttributeAssignmentException ("Attribute " + attribute + "is incorrectly assigned." );
143147 }
144148
145- Attribute mfaCategories = perunSession .getPerunBl ().getAttributesManagerBl ().getEntitylessAttributes (perunSession , "mfaCategories" ).get (0 );
146- String mfaSettingsValue = mfaCategories .valueAsString ();
149+
150+ Attribute mfaCategory = null ;
151+ try {
152+ Map <String , Attribute > mfaCategories = perunSession .getPerunBl ().getAttributesManagerBl ().getEntitylessAttributesWithKeys (perunSession , AttributesManager .NS_ENTITYLESS_ATTR_DEF + ":mfaCategories" , Collections .singletonList ("categories" ));
153+ mfaCategory = mfaCategories .get ("categories" );
154+ } catch (AttributeNotExistsException e ) {
155+ throw new WrongReferenceAttributeValueException ("Attribute mfa categories does not exist." );
156+ }
157+
158+ if (mfaCategory == null ) throw new WrongReferenceAttributeValueException ("Attribute mfa categories does not have value for key categories." );
159+
160+ String mfaCategoryValue = mfaCategory .valueAsString ();
147161 try {
148162 final ObjectMapper mapper = new ObjectMapper ();
149- JsonNode mfaCategoriesNode = mapper .readTree (mfaSettingsValue ). get ( "categories" );
163+ JsonNode mfaCategoriesNode = mapper .readTree (mfaCategoryValue );
150164
151165 // Iterate through categories and check that all included categories exist
152166 for (Iterator <Map .Entry <String , JsonNode >> catIt = mfaCategoriesNode .fields (); catIt .hasNext (); ) {
@@ -171,7 +185,7 @@ public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, At
171185 throw new WrongReferenceAttributeValueException ("Rps " + excludeRps + " do not exist inside included categories in mfaCategories attribute." );
172186 }
173187 } catch (JsonProcessingException e ) {
174- throw new WrongAttributeAssignmentException ("Attribute " + mfaCategories + "is incorrectly assigned." );
188+ throw new WrongAttributeAssignmentException ("Attribute " + mfaCategory + "is incorrectly assigned." );
175189 }
176190 }
177191
0 commit comments