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