1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.security.authn.util;
17
18 import java.io.InputStream;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Properties;
22
23 import org.apache.log4j.Logger;
24
25 public class AuthenticationMapper {
26 Logger LOG = Logger.getLogger( AuthenticationMapper.class );
27
28 private String loginURL;
29 private String logoutURL;
30
31 private List<String> urlPatterns;
32
33 public AuthenticationMapper( final String configFilePath )
34 {
35 urlPatterns = new ArrayList<String>();
36 try {
37 readProperties( configFilePath );
38 } catch (Exception e) {
39 LOG.error( "Unable to load configuration file: "+configFilePath+"\n"+e.getLocalizedMessage() );
40 }
41 }
42
43 public boolean requiresAuthentication( final String url )
44 {
45 boolean requiresAuthN = false;
46 for( String pattern : getUrlPatterns() )
47 {
48 if( url.startsWith(pattern) )
49 {
50 requiresAuthN = true;
51 }
52 }
53 return requiresAuthN;
54 }
55
56 public String getLoginURL() {
57 return loginURL;
58 }
59
60 public void setLoginURL(String loginURL) {
61 this.loginURL = loginURL;
62 }
63
64 public String getLogoutURL() {
65 return logoutURL;
66 }
67
68 public void setLogoutURL(String logoutURL) {
69 this.logoutURL = logoutURL;
70 }
71
72 public List<String> getUrlPatterns() {
73 return urlPatterns;
74 }
75
76 public void setUrlPatterns(List<String> urlPatterns) {
77 this.urlPatterns = urlPatterns;
78 }
79
80 public void readProperties(final String configFilePath) throws Exception {
81 Properties properties = new Properties();
82 InputStream is = this.getClass().getResourceAsStream( configFilePath );
83 properties.loadFromXML(is);
84
85 for( Object s : properties.keySet() )
86 {
87 LOG.debug( "Loading property "+(String)s+" = "+properties.getProperty( (String)s ) );
88 if( ((String)s).startsWith( AuthenticationConstants.AUTH_PATH_PREFIX ) )
89 {
90 this.urlPatterns.add( properties.getProperty( (String)s ) );
91 }
92 else if( "loginURL".equalsIgnoreCase( (String)s ) )
93 {
94 this.setLoginURL( properties.getProperty((String) s) );
95 }
96 else if( "logoutURL".equalsIgnoreCase( (String)s ) )
97 {
98 this.setLogoutURL( properties.getProperty((String) s) );
99 }
100 }
101 }
102 }