Project

General

Profile

« Previous | Next » 

Revision 0d0522eb

Added by Andreas Kohlbecker over 6 years ago

intoducing CdmAuthorityParsingException to avoid invalid use of non api sun.security.provider.PolicyParser.ParsingException

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/CdmAuthority.java
21 21

  
22 22
import eu.etaxonomy.cdm.model.common.CdmBase;
23 23
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
24
import sun.security.provider.PolicyParser.ParsingException;
25 24

  
26 25
/**
27 26
 * A <code>CdmAuthority</code> consists basically of two parts which are separated
......
125 124
        }
126 125
    }
127 126

  
128
    private CdmAuthority (String authority) throws ParsingException{
127
    private CdmAuthority (String authority) throws CdmAuthorityParsingException{
129 128

  
130 129
        String[] tokens = parse(authority);
131 130
        // className must never be null
......
133 132
        try {
134 133
            permissionClass = CdmPermissionClass.valueOf(tokens[0]);
135 134
        } catch (IllegalArgumentException e) {
136
            throw new ParsingException(authority);
135
            throw new CdmAuthorityParsingException(authority);
137 136
        }
138 137
        property = tokens[1];
139 138

  
......
142 141
                operation = Operation.fromString(tokens[2]);
143 142
            } catch (IllegalArgumentException e) {
144 143
                logger.warn("cannot parse Operation " + tokens[2]);
145
                throw new ParsingException(authority);
144
                throw new CdmAuthorityParsingException(authority);
146 145
            }
147 146
        }
148 147
        if(tokens[3] != null){
......
190 189
     * </ol>
191 190
     * @param authority
192 191
     * @return an array of tokens
193
     * @throws ParsingException
192
     * @throws CdmAuthorityParsingException
194 193
     */
195
    protected String[] parse(String authority) throws ParsingException {
194
    protected String[] parse(String authority) throws CdmAuthorityParsingException {
196 195
        //
197 196
        // regex pattern explained:
198 197
        //  (\\w*)             -> classname
......
217 216
            }
218 217
        } else {
219 218
            logger.debug("no match");
220
            throw new ParsingException("Unsupported authority string: '" + authority + "'");
219
            throw new CdmAuthorityParsingException("Unsupported authority string: '" + authority + "'");
221 220
        }
222 221

  
223 222
        return tokens;
......
267 266
     * instances per <code>GrantedAuthority</code> string in a map.
268 267
     *
269 268
     * @param authority
270
     * @throws ParsingException
269
     * @throws CdmAuthorityParsingException
271 270
     */
272
    public static CdmAuthority fromGrantedAuthority(GrantedAuthority authority) throws ParsingException {
271
    public static CdmAuthority fromGrantedAuthority(GrantedAuthority authority) throws CdmAuthorityParsingException {
273 272
        CdmAuthority cdmAuthority = grantedAuthorityCache.get(authority.getAuthority());
274 273
        if(cdmAuthority == null){
275 274
            cdmAuthority = new CdmAuthority(authority.getAuthority());
......
280 279

  
281 280

  
282 281
    @Override
283
    public GrantedAuthorityImpl asNewGrantedAuthority() throws ParsingException {
282
    public GrantedAuthorityImpl asNewGrantedAuthority() throws CdmAuthorityParsingException {
284 283
        GrantedAuthorityImpl grantedAuthority = GrantedAuthorityImpl.NewInstance(getAuthority());
285 284
        return grantedAuthority;
286 285
    }
287 286

  
288 287

  
289

  
290 288
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/CdmAuthorityParsingException.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.persistence.hibernate.permission;
10

  
11
/**
12
 * @author a.kohlbecker
13
 * @since 18.10.2017
14
 *
15
 */
16
public class CdmAuthorityParsingException extends Exception {
17

  
18
    private static final long serialVersionUID = -1458716979023979164L;
19

  
20
    public CdmAuthorityParsingException(String authority){
21
        super(authority);
22
    }
23

  
24
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/IGrantedAuthorityConverter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.persistence.hibernate.permission;
10 10

  
11
import sun.security.provider.PolicyParser.ParsingException;
12 11
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
13 12

  
14 13
/**
......
20 19

  
21 20
    /**
22 21
     * @return
23
     * @throws ParsingException
22
     * @throws CdmAuthorityParsingException
24 23
     */
25
    public abstract GrantedAuthorityImpl asNewGrantedAuthority() throws ParsingException;
24
    public abstract GrantedAuthorityImpl asNewGrantedAuthority() throws CdmAuthorityParsingException;
26 25

  
27 26
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/voter/CdmPermissionVoter.java
21 21
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
22 22
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
23 23
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
24
import sun.security.provider.PolicyParser.ParsingException;
24
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthorityParsingException;
25 25

  
26 26
/**
27 27
 * The <code>CdmPermissionVoter</code> provides access control votes for {@link CdmBase} objects.
......
102 102
                CdmAuthority auth;
103 103
                try {
104 104
                    auth = CdmAuthority.fromGrantedAuthority(authority);
105
                } catch (ParsingException e) {
106
                    logger.debug("skipping " + authority.getAuthority() + " due to ParsingException");
105
                } catch (CdmAuthorityParsingException e) {
106
                    logger.debug("skipping " + authority.getAuthority() + " due to CdmAuthorityParsingException");
107 107
                    continue;
108 108
                }
109 109

  
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/hibenate/permission/CdmAuthorityTest.java
21 21
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
22 22
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
23 23
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
24
import sun.security.provider.PolicyParser.ParsingException;
24
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthorityParsingException;
25 25

  
26 26
/**
27 27
 * @author c.mathew
......
43 43

  
44 44
	/**
45 45
	 * Test method for {@link eu.etaxonomy.cdm.persistence.hibernate.permission#getAuthority()}.
46
	 * @throws ParsingException
46
	 * @throws CdmAuthorityParsingException
47 47
	 */
48 48
	@Test
49
	public final void testGetAuthority() throws ParsingException {
49
	public final void testGetAuthority() throws CdmAuthorityParsingException {
50 50
		// create CdmAuthority object manually
51 51
		CdmPermissionClass tnClass = CdmPermissionClass.TAXONBASE;
52 52
		String property = "Taxon";
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/SecurityTest.java
62 62
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
63 63
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
64 64
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
65
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthorityParsingException;
65 66
import eu.etaxonomy.cdm.persistence.query.MatchMode;
66
import sun.security.provider.PolicyParser.ParsingException;
67 67

  
68 68

  
69 69
@DataSet
......
363 363
    }
364 364

  
365 365
    @Test
366
    public final void testUpdateReferenceAllow() throws ParsingException {
366
    public final void testUpdateReferenceAllow() throws CdmAuthorityParsingException {
367 367

  
368 368

  
369 369
        authentication = authenticationManager.authenticate(tokenForUserManager);

Also available in: Unified diff